Search code examples
javascriptopentok

Token Error while using Node Server SDK Opentok


I am currently using OpenTok Node SDK version 2.2.2 (installing via npm) & my client side plugin is version 2.2.5.1 . During session.connect() method call , i get this error :

OT.exception :: title: Authentication error (1004) msg: Invalid token. Make sure you're using the latest OpenTok server SDK .

When i decoded the Token(base64) , this is what i got :

partner_id=23690372&sig=f52e13ac579649a3531a6040e679fb9bcca04007:session_id=1_MX4yMzY5MDM3Mn5-RnJpIEp1biAwNiAxMDoyNjoyMyBQRFQgMjAxNH4xLjQzMDUxMTVFLTZ-fg&create_time=1402075583&nonce=0.7174300465267152&role=publisher&expire_time=1402161983

My session ID matches the one above .

Using methods , opentok.createSession(function(err, session) { } ) and opentok.generateToken(session.sessionId) to generate my session ID and Token on server end .

On client side , this is what i am doing :

session = TB.initSession(TOK_API_KEY,session_id);
session.on("streamCreated", function(event) {
  session.subscribe(event.stream);
});    

var publisher = TB.initPublisher("broadcast_display", null, function(error) {
    if (error) {
      console.log('error initializing publisher', error);
    } else {
      console.log('publisher initialized successfully');
    }
});

session.connect(TOK_API_KEY, token, function(error) {
      if (error) {
        console.log(error);
      } else {
        session.publish(publisher);
      }
});

Not sure what the problem is . Any help ?


Solution

  • Update your NodeJS sdk to latest version (v2.2.3) for OpenTok and generate a new token.