Sha256: 9abafc4f0cf41b3cdcdd9132f459400d7592016cf1270ea7cea1ad1bcf280181

Contents?: true

Size: 1.6 KB

Versions: 8

Compression:

Stored size: 1.6 KB

Contents

// Initialize an OpenTok Session object
var session = OT.initSession(apiKey, sessionId);

// Initialize a Publisher, and place it into the element with id="publisher"
var publisher = OT.initPublisher('publisher', {
    insertMode: 'append',
    width: '100%',
    height: '100%'
}, function(error) {
  if (error) {
    console.error('Failed to initialise publisher', error);
  }
});

// Attach event handlers
session.on({

  // This function runs when session.connect() asynchronously completes
  sessionConnected: function(event) {
    // Publish the publisher we initialzed earlier (this will trigger 'streamCreated' on other
    // clients)
    session.publish(publisher, function(error) {
      if (error) {
        console.error('Failed to publish', error);
      }
    });
  },

  // This function runs when another client publishes a stream (eg. session.publish())
  streamCreated: function(event) {
    // Create a container for a new Subscriber, assign it an id using the streamId, put it inside
    // the element with id="subscribers"
    var subContainer = document.createElement('div');
    subContainer.id = 'stream-' + event.stream.streamId;
    document.getElementById('subscribers').appendChild(subContainer);

    // Subscribe to the stream that caused this event, put it inside the container we just made
    session.subscribe(event.stream, subContainer, function(error) {
      if (error) {
        console.error('Failed to subscribe', error);
      }
    });
  }

});

// Connect to the Session using a 'token'
session.connect(token, function(error) {
  if (error) {
    console.error('Failed to connect', error);
  }
});

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
opentok-3.1.0 sample/HelloWorld/public/js/helloworld.js
opentok-3.0.3 sample/HelloWorld/public/js/helloworld.js
opentok-3.0.2 sample/HelloWorld/public/js/helloworld.js
opentok-3.0.1 sample/HelloWorld/public/js/helloworld.js
opentok-3.0.0 sample/HelloWorld/public/js/helloworld.js
opentok-2.5.0 sample/HelloWorld/public/js/helloworld.js
opentok-2.4.1 sample/HelloWorld/public/js/helloworld.js
opentok-2.4.0 sample/HelloWorld/public/js/helloworld.js