WebRTC Audio 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;

// 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"
    } );
    
    /* 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;
        // ask the user to access to his webcam
        bc.startStream( "pure-audio", function( localStream ){
            // 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( localStream, q( "#video_container" ) );
            // then, for every single members present in the room ...
            for ( var i=0, max=data.members.length; i<max; i++ ) {
                // ... request a call
                bc.call( data.members[ i ].id, data.room, {"stream": localStream,...