JSFiddle - React, Tailwind, and code Playground
by bistri
HTML
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<script src="https://api.bistri.com/bistri.conference.min.js"></script>
<div class="pane" id="pane_0" style="display: none">
Waiting calls ...
</div>
<div class="pane" id="pane_1" style="display: none">
<div id="remote-video">
<div id="local-video"></div>
</div>
<div id="messages_container"></div>
<p>
<input type="text" placeholder="Message" id="message_field" class="form-control">
</p>
<input type="button" value="Send Message" id="send" class="btn btn-success btn-default btn-block">
<input type="button" value="Quit" id="quit" class="btn btn-danger btn-default btn-block">
</div>
CSS
.pane {
margin: 20px;
text-align: center;
}
.message {
text-align: left;
}
#messages_container {
height: 200px;
overflow-y: auto;
border: 1px solid #dedede;
padding: 10px;
margin-bottom: 2px;
}
video {
width: 100%;
}
#remote-video {
position: relative;
margin: 0 auto;
width: 320px;
height: 240px;
background-color: #c0c0c0;
}
#local-video {
position: absolute;
margin: 0 10px 10px 0;
right: 0;
bottom: 0;
width: 30%;
}
JavaScript
/*
JS library reference:
http://developers.bistri.com/webrtc-sdk/js-library-reference
*/
var room;
var localStream;
var users = {};
var dataChannels = {};
var userId = "support_1";
var userName = "John Doe";
onBistriConferenceReady = function () {
if ( !bc.isCompatible() ) {
alert( "your browser is not WebRTC compatible !" );
return;
}
bc.init( {
appId: "38077edb",
appKey: "4f304359baa6d0fd1f9106aaeb116f33",
userId: userId,
userName: userName,
debug: true
} );
/* Set events handler */
bc.signaling.bind( "onError", function () {
alert( error.text + " (" + error.code + ")" );
} );
bc.signaling.bind( "onIncomingRequest", function ( data ) {
if( !room ){
if( confirm( data.name + " is requesting assistance" ) ){
bc.joinRoom( data.room, 2 )
}
}
} );
bc.signaling.bind( "onConnected", function () {
showPanel( "pane_0" );
} );
bc.signaling.bind( "onJoinedRoom", function ( data ) {
function doCall(){
bc.startStream( "640x480", function( stream ){
localStream = stream;
bc.attachStream( stream, q( "#local-video" ), { mirror: true } );
for ( var i=0, max=data.members.length; i<max; i++ ) {
users[ data.members[ i ].id ] = data.members[ i ].name;
bc.openDataChannel( data.members[ i ].id, "chat", room );
}
} );
}
if( data.room.indexOf( "__video_" ) != -1 ){
doCall();
}
else{
room = data.room;
bc.signaling.joinRoom( "__video_" + data.room, data.capacity );
}
} );
bc.signaling.bind( "onJoinRoomError", function ( error ) {
alert( error.text + " (" + error.code + ")" );
} );
bc.signaling.bind( "onQuittedRoom",...