Search code examples
video-streamingopentok

In OpenTok, why do I get "token passed is invalid" and "session failed to connect"


I couldn't get the quickstart code to work on my site so I inserted a line of debug code (TB.setLogLevel(TB.DEBUG);) to see where it was tripping up. It failed saying 'The token is invalid'. Here's the debug outputs- I xx'ed out my unique IDs for privacy but they match what I was given. Any idea why it's failing?

OpenTok JavaScript library v2.0.7.1 TB.min.js:52
Release notes: http://www.tokbox.com/opentok/webrtc/do ... notes.html TB.min.js:52
Known issues: http://www.tokbox.com/opentok/webrtc/do ... nownIssues TB.min.js:52
TB.setLogLevel(5) TB.min.js:52
TB.checkSystemRequirements() TB.min.js:52
SessionInfo Response: TB.min.js:52

TB.min.js:52
connectToMessenger TB.min.js:52
WebSocket connected TB.min.js:52
WebSocket message recieved: {"type":1000,"payload":{"connectionId":"7dd66c68-6f5b-401c-a886-e9562f069eb7"}} TB.min.js:52
Sending WebSocket message: {"type":1001,"payload":{"sessionId":"xxxx","apiKey":"xx","token":"xxx","supportsWebRTC":true,"connectionObjects":true,"p2pEnabled":false}} TB.min.js:52
WebSocket message recieved: {"type":1100,"payload":{"reason":"The token passed is invalid.","code":1004}} TB.min.js:52
Received SessionConnectFailed TB.min.js:52
The token passed is invalid. TB.min.js:52
TB.exception :: title: Connect Failed (1006) msg: TB.SessionConnectionFailed :: The session failed to connect. TB.min.js:52
TB.exception :: title: Connect Time-out (1008) msg: Connection to the server timed out fetching the session state. TB.min.js:52


Solution

  • One possible reason for this error is that your token is invalid. This could be because:

    • The token has expired.
    • The token was generated for a different session id than the one you are using.

    For either case, try generating another token for the session and using it in your code.

    Good luck!