webrtc-sdk icon indicating copy to clipboard operation
webrtc-sdk copied to clipboard

Broadcasting using the library

Open jonohayon opened this issue 10 years ago • 9 comments

Hi, How can I use your library for broadcasting video & audio to peers? The readme says that it's possible, but I looked into the code and I haven't saw anything for doing it. Is it actually possible?

-- Jonathan

jonohayon avatar Mar 16 '15 14:03 jonohayon

Yes it is 😸 Sorry for late replay. Let me know if you'd like to see the code to make that happen.

stephenlb avatar May 22 '15 17:05 stephenlb

Hi! It would be awesome :)

--Jonathan

jonohayon avatar May 22 '15 18:05 jonohayon

Jonathan I'll post a sample here: https://github.com/stephenlb/webrtc-sdk#webrtc-video-and-audio-broadcasting-mode - I'll post it in this thread too. 1 sec.

stephenlb avatar May 22 '15 18:05 stephenlb

That's great! Thanks!

--Jonathan

jonohayon avatar May 22 '15 18:05 jonohayon

And btw, where can I find the ObjC library for WebRTC and the settings for using it with this library?

--Jonathan

jonohayon avatar May 22 '15 18:05 jonohayon

Obj-c you'll want http://xirsys.com

stephenlb avatar May 22 '15 18:05 stephenlb

Broadcaster with Audience Members

https://github.com/stephenlb/webrtc-sdk#webrtc-video-and-audio-broadcasting-mode

You'll start by opening the stream for the broadcaster so audience members can join in. Start broadcasting as the broadcaster:

Broadcaster

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Initialize the Broadcaster's Device
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
var broadcaster = PHONE({
    number        : "BROADCASTER",  // If you want more than one broadcaster, use unique ids
    publish_key   : 'pub-c-561a7378-fa06-4c50-a331-5c0056d0163c',
    subscribe_key : 'sub-c-17b7db8a-3915-11e4-9868-02ee2ddab7fe',
    ssl           : true
});

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Wait for New Viewers to Join
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
broadcaster.receive(function(new_viewer){
    new_viewer.connected(function(viewer){ /* ... */ }); // new viewer joined
    new_viewer.ended(function(viewer){ /* ... */ });  // viewer left
    //new_viewer.hangup();  // if you want to block the viewer
});

Viewer

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Initialize the Viewer's Device
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
var viewer = PHONE({
    number        : "VIEWER-"+new Date,
    publish_key   : 'pub-c-561a7378-fa06-4c50-a331-5c0056d0163c',
    subscribe_key : 'sub-c-17b7db8a-3915-11e4-9868-02ee2ddab7fe',
    ssl           : true
});

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Join a Broadcast as a Viewer
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
viewer.ready(function(){
    var broadcaster = phone.dial("BROADCASTER");
});

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Show Broadcast's Video Stream
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
viewer.receive(function(broadcaster){
    broadcaster.connected(function(broadcaster){
        document.body.appendChild(broadcaster.video);
    });
    broadcaster.ended(function(broadcaster){ /* broadcast ended */ });
});

stephenlb avatar May 22 '15 18:05 stephenlb

Thanks!!

-- Jonathan

jonohayon avatar May 22 '15 18:05 jonohayon

I've made a few tweaks, there may be a few bugs because I typed this up freeform.

stephenlb avatar May 22 '15 18:05 stephenlb