Created
March 28, 2020 06:43
-
-
Save shriyaRam/e41f82c0a2f6a99530150313e9be5006 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var client = AgoraRTC.createClient(config); | |
function myfunction(){ | |
let handlefail = function(err){ | |
console.log("Error: ", err); | |
}; | |
let remotecontainer = document.getElementById("remote1"); | |
let remote_container = document.getElementById("remote2"); | |
let appid = document.getElementById("appid"); | |
function addremotestream(streamid){ | |
let newdiv = document.createElement("div"); | |
newdiv.id = streamid; | |
newdiv.style.transform = "rotateY(180deg)"; | |
remotecontainer.appendChild(newdiv); | |
} | |
var config = { | |
mode: "live", | |
codec: "h264" | |
} | |
var client = AgoraRTC.createClient(config); | |
//intialise the client | |
client.init(appid.value, function() { console.log("Agora client initialised!")}, handlefail); | |
client.join(null, "1024", null, function(uid) { | |
console.log("client " + uid + " joined channel"); | |
// Create a local stream | |
var localstream = AgoraRTC.createStream({ | |
streamID: uid, | |
audio:true, | |
video:true, | |
screen:false | |
}); | |
localstream.init(function() { | |
console.log("local stream initialized"); | |
//play the stream | |
localstream.play('local1'); | |
// publish the stream | |
client.publish(localstream, handlefail); | |
}, handlefail); | |
}, handlefail); | |
client.on('stream-added', function (evt) { | |
client.subscribe(evt.stream, handlefail); | |
}); | |
client.on("stream-subscribed",function(evt){ | |
var remotestream = evt.stream; | |
addremotestream(remotestream.getId()); | |
remotestream.play('remote2'); | |
}); | |
var client2 = AgoraRTC.createClient(config); | |
//intialise the client | |
client2.init(appid.value, function() { console.log("Second Agora client initialised!")}, handlefail); | |
client2.join(null, "1024", null, function(uid) { | |
console.log("client " + uid + " joined channel"); | |
// Create a local stream | |
var local_stream = AgoraRTC.createStream({ | |
streamID: uid, | |
audio:true, | |
video:true, | |
screen:false | |
}); | |
local_stream.init(function() { | |
console.log("local stream initialized"); | |
//play the stream | |
local_stream.play('local2'); | |
// publish the stream | |
client2.publish(local_stream, handlefail); | |
}, handlefail); | |
}, handlefail); | |
client2.on('stream-added', function (evt) { | |
client2.subscribe(evt.stream, handlefail); | |
}); | |
client2.on("stream-subscribed",function(evt){ | |
var remote_stream = evt.stream; | |
addremotestream(remote_stream.getId()); | |
remote_stream.play('remote1'); | |
}); | |
function removeVideoStream (evt) { | |
let stream = evt.stream; | |
stream.stop();//inbuilt method to stop stream set by stream.play() | |
let remDiv=document.getElementById(stream.getId()); | |
remDiv.parentNode.removeChild(remDiv); | |
console.log("Remote stream is removed " + stream.getId()); | |
} | |
client.on('stream-removed',removeVideoStream); | |
client.on('peer-leave',removeVideoStream); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment