123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- var server = null;
- if(window.location.protocol === 'http:')
- server = "http://192.168.131.21:8088/janus";
- else
- server = "https://192.168.131.21:8089/janus";
- var janus = null;
- var mixertest = null;
- var opaqueId = "audiobridgetest-"+Janus.randomString(12);
- var spinner = null;
- var myroom = 1001; // Demo room
- var myid = null;
- var webrtcUp = false;
- var audioenabled = false;
- $(document).ready(function() {
- Janus.init({debug: "all", callback: function() {
-
- janus = new Janus(
- {
- server: server,
- success: function() {
- janus.attach(
- {
- plugin: "janus.plugin.audiobridge",
- opaqueId: opaqueId,
- success: function(pluginHandle) {
- mixertest = pluginHandle;
-
- registerUsername();
- $('#start').removeAttr('disabled').html("Stop")
- .click(function() {
- $(this).attr('disabled', true);
- janus.destroy();
- });
- },
- error: function(error) {
- Janus.error(" -- Error attaching plugin...", error);
- },
- consentDialog: function(on) {
- Janus.debug("Consent dialog should be " + (on ? "on" : "off") + " now");
- },
- iceState: function(state) {
- Janus.log("ICE state changed to " + state);
- },
- mediaState: function(medium, on) {
- Janus.log("Janus " + (on ? "started" : "stopped") + " receiving our " + medium);
- },
- webrtcState: function(on) {
- Janus.log("Janus says our WebRTC PeerConnection is " + (on ? "up" : "down") + " now");
- },
- onmessage: function(msg, jsep) {
- Janus.debug(" ::: Got a message :::", msg);
- var event = msg["audiobridge"];
- Janus.debug("Event: " + event);
- if(event) {
- if(event === "joined") {
- // Successfully joined, negotiate WebRTC now
- if(msg["id"]) {
- myid = msg["id"];
- Janus.log("Successfully joined room " + msg["room"] + " with ID " + myid);
- if(!webrtcUp) {
- webrtcUp = true;
- // Publish our stream
- mixertest.createOffer(
- {
- media: { video: false}, // This is an audio only room
- success: function(jsep) {
- Janus.debug("Got SDP!", jsep);
- var publish = { request: "configure", muted: false };
- mixertest.send({ message: publish, jsep: jsep });
- },
- error: function(error) {
- Janus.error("WebRTC error:", error);
- }
- });
- }
- }
- }
- }
- if(jsep) {
- Janus.debug("Handling SDP as well...", jsep);
- mixertest.handleRemoteJsep({ jsep: jsep });
- }
- },
- onlocalstream: function(stream) {
- Janus.debug(" ::: Got a local stream :::", stream);
- },
- onremotestream: function(stream) {
- if($('#roomaudio').length === 0) {
- $('#mixedaudio').append('<audio class="rounded centered" id="roomaudio" width="100%" height="100%" autoplay/>');
- }
- Janus.attachMediaStream($('#roomaudio').get(0), stream);
- },
- oncleanup: function() {
- Janus.log(" ::: Got a cleanup notification :::");
- }
- });
- },
- error: function(error) {
- Janus.error(error);
- },
- destroyed: function() {
- window.location.reload();
- }
- });
- //});
- }});
- });
- function registerUsername() {
- username = "car_1";
- var register = { request: "join", room: myroom, display: username };
- mixertest.send({ message: register});
- }
|