Created
March 14, 2020 10:06
-
-
Save shriyaRam/adcebffca7d03db5bb70d4c68b283765 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
function myfunction(){ | |
let handlefail = function(err){ | |
console.log("Error: ", err); | |
}; | |
let remotecontainer = document.getElementById("remote"); | |
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('local'); | |
// localstream.play('local', {fit: "contain"}, function(errState){ | |
// if (errState && errState.status !== "aborted"){ | |
// // The playback fails, probably due to browser policy. You can resume the playback by user gesture. | |
// localstream.resume(); | |
// } | |
// }); | |
// 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; | |
//client.subscribe(evt.stream, handlefail); | |
addremotestream(remotestream.getId()); | |
remotestream.play('remote'); | |
}); | |
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