zelloptt / zello-channel-api

WebSocket-based API and SDKs to connect to Zello channels (BETA)
MIT License
88 stars 35 forks source link

[JS] Connecting to more than one channel doesn't work #50

Closed OnkelTem closed 5 years ago

OnkelTem commented 5 years ago

When I try to connect to more than one channel I get this error message:

Uncaught Error: Uncaught, unspecified 'error' event.
    at t.f.emit (zcc.session.js:1)
    at t.value (zcc.session.js:1)
    at t.value (zcc.session.js:1)
    at t.value (zcc.session.js:1)
    at WebSocket.<anonymous> (zcc.session.js:1)

It's actually the same as I was getting yesterday: https://github.com/zelloptt/zello-channel-api/issues/49 but now it seems to be reproducable for any two channels. Sure this error is not the same as in the referenced issue.

I use a development token.

JS library version is 0.4

megamk commented 5 years ago

Hi @OnkelTem Thank you for your report, there's a race condition bug in js sdk not allowing to connect simultaneously. This will be fixed. You can avoid that if you start second session once first one already established. Consider this pattern:

let session1;
let session2;

ZCC.Sdk.init({
  player: true,
  widget: false
}).then(function() {
  session = new ZCC.Session({
    serverUrl: 'wss://zello.io/ws/',
    channel: channel,
    authToken: token,
    username: username,
    password: password
  });
  session.connect().then(() => {
    console.log('Connected 1st session');
    session2 = new ZCC.Session({
      serverUrl: 'wss://zello.io/ws/',
      channel: channel2,
      authToken: token,
      username: username2,
      password: password2
    });
    session2.connect().catch((err) => {
      console.log('Connected 2nd session');
    });
  }).catch((err) => {
    console.trace(err);
  });
}).catch(function(err) {
  console.trace(err);
});

please also note that if you're connecting using username and password (not listenOnly mode) then you can have only one session per username

OnkelTem commented 5 years ago

Thank you Mikhail, I got it. Would be great to have this fixed :)

megamk commented 5 years ago

this is fixed