Use the undocumented sessionId
and guestId
properties on the optionsObject parameter of `goinstant.connect':
var url = "https://goinstant.net/ACCOUNT/APPLICATION";
var opts = {sessionId: null, guestId: null};
var conn1, lobby1, conn2, lobby2;
goinstant.connect(url, opts, function(err, connection, lobby) {
conn1 = connection;
lobby1 = lobby;
lobby.key('conn2Key').on('set', function(value, context) {
console.log('-----------------------');
console.log('Saw a set on conn2Key');
console.log('User:', context.userId);
console.log('Value:', value);
console.log('This connection is user:', lobby.self().name.split('/')[2]);
console.log('-----------------------');
});
});
goinstant.connect(url, opts, function(err, connection, lobby) {
conn2 = connection;
lobby2 = lobby;
setTimeout(function() {
lobby.key('conn2Key').set('Hi!');
}, 1000);
});
When set to an empty string or null
, the connection will generate a new guest user and session for the connection.
By default, guest user information within a GoInstant application is shared across tabs, and sessions are reused within tabs (so if you reload, you can properly reconnect). This is why using two instances breaks; the same sessionId
attempts to connect twice.
This feature is undocumented and unsupported, so it may change or break in the future.