POC Relay: Relay

by bistri

HTML

<script src="https://api.bistri.com/bistri.conference.min.js"></script>

JavaScript

/*
    JS library reference:
    http://developers.bistri.com/webrtc-sdk/js-library-reference
*/

var stream;

onBistriConferenceReady = function () {

    bc.init( {
        "appId": "38077edb",
        "appKey": "4f304359baa6d0fd1f9106aaeb116f33"
    } );
    
    bc.signaling.bind( "onConnected", function () {
        bc.joinRoom( "relay" );
        bc.joinRoom( "broadcast" );
    } );

    bc.signaling.bind( "onJoinedRoom", function ( data ) {
        if( data.room == "broadcast" && stream ){
            data.members.forEach( function( member ){
                bc.call( member.id, "broadcast", { "stream": stream, "sendonly": true } );
            } );
        }
    } );

    bc.streams.bind( "onStreamAdded", function ( remoteStream ) {
        
         console.log( "stream added" )
        
       stream = remoteStream;
    } );
    
    bc.signaling.bind( "onPeerJoinedRoom", function ( data ) {
        
        console.log( data )
        
        if( stream ){
            bc.call( data.pid, data.room, { "stream": stream, "sendonly": true } );
        }
    } );
    

    bc.streams.bind( "onStreamClosed", function ( stream ) {
        bc.endCalls( "dummy" )
    } );

    bc.connect();
}