Page tree
Skip to end of metadata
Go to start of metadata

Integrating SkywayJS into your Platform

Please note

  • Socket.IO client javascript has to be loaded before SkylinkJS library.
  • To use the complete version that is packed with Socket.IO, please use the Complete Packaged version of SkylinkJS.
  • To know more about the AdapterJS functions like attachMediaStream and more, please visit AdapterJS page for the documentation.

  • To view more other functionality like chat, file transfers and other settings like the call duration, please check the documentation here.

To initialize SkylinkJS, simply call:

var sl = new Skylink();
sl.init('APP_KEY');

To use the events provided in SkylinkJS, use:

sw.on('event_name', function (param1, param2) {
 // .. do something
}); 

Here's a simple example to make a Video/Audio call:

var sl = new Skylink();
sl.init('APP_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(); } 

Example in the HTML page. Add this in the <body> tag

<video id="localVideo" autoplay="autoplay"></video>
<div id="peerVideoList"></div>
<button type="button" onclick="joinRoom()">Start Call</button>
<button type="button" onclick="leaveRoom()">End Call</button>
 
  • No labels