Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
var sl = new Skylink();
sl.init('APIAPP_KEY');

// A new Peer has joined the Room
sl.on('peerJoined', function(peerId, peerInfo){
  console.log('Peer ' + peerId + ' has joined the room');
  var peerVideo = document.createElement('video');
  peerVideo.id = peerId + '_video';
  peerVideo.autoplay = 'autoplay';
  document.getElementById('peerVideoList').appendChild(peerVideo);
});
// Peer has Audio/Video stream to add
sl.on('addPeerStream', function(peerId, stream){
  // attachMediaStream is a Adapter function
  attachMediaStream(document.getElementById(peerId + '_video'), stream);
});
// User's Audio/Video stream has been successfully added
sl.on('mediaAccessSuccess', function(stream){
  // attachMediaStream is a Adapter function
  attachMediaStream( document.getElementById('localVideo'), stream );
});
// A Peer has left the room
sl.on('peerLeft', function(peerId){
  var peer = document.getElementById(peerId + '_video');
  document.getElementById('peerVideoList').removeChild(peer);
}); 
 
function joinRoom () { sl.joinRoom({ audio : true, video : true }); }
function leaveRoom () { sl.leaveRoom(); } 

...