dhiraj uchil
dhiraj uchil

Reputation: 123

How to find your own connection Id in client Opentok

how can a client find its own connectionId when it connects to a session?

here is my client code I tried listening to streamcreated but it gives back id of all the streams when they connect.

function initializeSession() {
  var session = OT.initSession(apiKey, sessionId);

  session.on('streamCreated', function streamCreated(event) {



    var subscriberOptions = {
      insertMode: 'append',
      width: '100%',
      height: '100%'
    };
    session.subscribe(event.stream, 'subscriber', subscriberOptions, handleError);
  });

  session.on('sessionDisconnected', function sessionDisconnected(event) {
    console.log('You were disconnected from the session.', event.reason);
  });


  var publisherOptions = {
    insertMode: 'append',
    width: '100%',
    height: '100%',
    name: pubname,
    style: { nameDisplayMode: "auto" }
  };
  var publisher = OT.initPublisher('publisher', publisherOptions, handleError);

  session.connect(token, function callback(error) {
    if (error) {
      handleError(error);
    } else {
      session.publish(publisher, handleError);
    }
  });
}

getData();
initializeSession();

Upvotes: 2

Views: 570

Answers (2)

Miguel Sesma
Miguel Sesma

Reputation: 757

Use session.connection.connectionID

Upvotes: -1

Michael Jolley
Michael Jolley

Reputation: 368

OpenTok Developer Advocate here.

Your publisher object defined in var publisher = OT.initPublisher('publisher', publisherOptions, handleError); will have a .stream.connection.connectionId that you can access.

You can learn more about the publisher object and what methods/properties are available to you at https://tokbox.com/developer/sdks/js/reference/Publisher.html.

Upvotes: 1

Related Questions