/*
JS library reference:
https://github.com/bistri/bistri-conference-js
*/
var localStream;
// initialize API client with application keys
// if you don't have your own, you can get them at:
// https://api.developers.bistri.com/login
bc.init ( {
appId: "38077edb",
appKey: "4f304359baa6d0fd1f9106aaeb116f33"
} );
// test if the browser is WebRTC compatible
if ( !bc.isCompatible () )
{
// if the browser is not compatible, display an alert
alert ( "your browser is not WebRTC compatible !" );
}
else
{
/* Set events handler */
// when local user is connected to the server
bc.signaling.bind ( "connected", function ()
{
// ask the user to access to his webcam and set the resolution to 320x240
bc.startStream ( {audio: true, video:true}, function( stream )
{
// set "localStream" variable with the local stream
localStream = stream;
// insert the local webcam stream into the page DOM
bc.attachStream ( stream, document.body, { mirror: true } );
// join a conference room called "conference_demo"
bc.joinRoom ( "conference_demo" );
} );
} );
// when the user has joined a room
bc.signaling.bind ( "joinedRoom", function ( result )
{
// then, for every single members already present in the room ...
result.members.forEach ( function ( member )
{
// ... request a call
bc.call ( member.id, "conference_demo", { stream: localStream } );
} )
});
// when a new remote stream is received
bc.streams.bind ( "streamAdded", function ( remoteStream )
{
// insert the new remote stream into the page DOM
bc.attachStream ( remoteStream, document.body );
} );
// when a new remote stream is received
bc.streams.bind ( "streamUpdated", function ( remoteStream )
{
// reattach the remote stream
bc.reattachStream ( remoteStream );
} );
// when a stream has been stopped
bc.streams.bind( "streamClosed", function ( stream )
{
// remove the stream from the page
bc.detachStream ( stream );
} );
// open a new session on the server
bc.connect();
}
video {
width: 320px;
}
External resources loaded into this fiddle: