Sha256: 346e75df200075087b5da565357885cd5ddfe827d313c7599f3491355747daa5

Contents?: true

Size: 1.3 KB

Versions: 17

Compression:

Stored size: 1.3 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',
}, 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) {
    // Subscribe to the stream that caused this event, and place it into the element with id="subscribers" 
    session.subscribe(event.stream, 'subscribers', {
        insertMode: 'append',
    }, 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

17 entries across 17 versions & 1 rubygems

Version Path
opentok-4.10.0 sample/HelloWorld/public/js/helloworld.js
opentok-4.9.0 sample/HelloWorld/public/js/helloworld.js
opentok-4.8.1 sample/HelloWorld/public/js/helloworld.js
opentok-4.8.0 sample/HelloWorld/public/js/helloworld.js
opentok-4.7.1 sample/HelloWorld/public/js/helloworld.js
opentok-4.7.0 sample/HelloWorld/public/js/helloworld.js
opentok-4.6.0 sample/HelloWorld/public/js/helloworld.js
opentok-4.5.1 sample/HelloWorld/public/js/helloworld.js
opentok-4.5.0 sample/HelloWorld/public/js/helloworld.js
opentok-4.4.0 sample/HelloWorld/public/js/helloworld.js
opentok-4.3.0 sample/HelloWorld/public/js/helloworld.js
opentok-4.2.0 sample/HelloWorld/public/js/helloworld.js
opentok-4.1.2 sample/HelloWorld/public/js/helloworld.js
opentok-4.1.1 sample/HelloWorld/public/js/helloworld.js
opentok-4.1.0 sample/HelloWorld/public/js/helloworld.js
opentok-4.0.1 sample/HelloWorld/public/js/helloworld.js
opentok-4.0.0 sample/HelloWorld/public/js/helloworld.js