The keys . As in the keystore, the Key object is the interface through which you control and control the value in GoInstant. You must use them for CRUD (Create, Read, Update Delete).
:
// We create a new key using our room object var movieName = yourRoom.key('movieName'); // Prepare a handler for our `on` set event function setHandler(value) { console.log('Movie has a new value', value); } // Now when the value of our key is set, our handler will fire movieName.on('set', setHandler); // Ready, `set`, GoInstant :) movieName.set('World War Z', function(err) { if (!err) alert('Movie set successfully!') }
Channels Imagine a full duplex messaging interface. Imagine a multi-client pub / subsystem. Channels do not store data, you cannot receive a message from a channel, it can only be received. You must use it to distribute events between clients using the session.
Channel example:
var mousePosChannel = yourRoom.channel('mousePosChannel'); // When the mouse moves, broadcast the mouse co-ordinates in our channel $(window).on('mousemove', function(event) { mousePosChannel.message({ posX: event.pageX, posY: event.pageY }); }); // Every client in this session can listen for changes to // any users mouse location mousePosChannel.on('message', function(msg) { console.log('A user in this room has moved there mouse too', msg.posX, msg.posY); })
Here you can find official documents:
Key: https://developers.goinstant.net/v1/key/index.html
Channel: https://developers.goinstant.net/v1/channel/index.html
source share