WebRTC Video Conference Demo
Build on top of Bistri WebRTC API
by bistri
HTML
<script src="https://api.bistri.com/bistri.conference.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<div class="pane" id="pane_0">
<img src="http://static.tumblr.com/uzwqx7a/8VIm8jofz/logo.png">
</div>
<div class="pane" id="pane_1" style="display: none">
<input type="text" placeholder="Conference Name" id="room_field" class="form-control">
<br>
<input type="button" value="Join Conference Room" id="join" class="btn btn-info btn-default btn-block">
</div>
<div class="pane" id="pane_2" style="display: none">
<div id="video_container"></div>
<input type="button" value="Quit Conference Room" id="quit" class="btn btn-danger btn-default btn-block">
</div>
CSS
.pane {
margin: 20px;
text-align: center;
}
video {
width: 100%;
}
JavaScript
/*
JS library reference:
http://developers.bistri.com/webrtc-sdk/js-library-reference
*/
var room;
var members;
var localStream;
// when Bistri API client is ready, function
// "onBistriConferenceReady" is invoked
onBistriConferenceReady = function () {
// 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 !" );
// then stop the script execution
return;
}
// 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",
"debug": true
} );
/* Set events handler */
// when local user is connected to the server
bc.signaling.bind( "onConnected", function () {
// show pane with id "pane_1"
showPanel( "pane_1" );
} );
// when an error occured on the server side
bc.signaling.bind( "onError", function ( error ) {
// display an alert message
alert( error.text + " (" + error.code + ")" );
} );
// when the user has joined a room
bc.signaling.bind( "onJoinedRoom", function ( data ) {
// set the current room name
room = data.room;
members = data.members;
// ask the user to access to his webcam
bc.startStream( {audio: true, video:true}, function( stream ){
// affect stream to "localStream" var
localStream = stream;
// when webcam access has been granted
// show pane with id "pane_2"
showPanel( "pane_2" );
// insert the local webcam stream into div#video_container node
bc.attachStream( stream, q( "#video_container" ), { mirror: true } );
// then, for every single members present in the room ...
...