Created
November 17, 2017 14:40
-
-
Save jsrawan-mobo/d5c4784c01652e7c4b9de3c9cb7550f5 to your computer and use it in GitHub Desktop.
Join_Room_Agora
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
/** | |
* Get media and join | |
* @return : Observevable(stream) => the agora local stream, you will need to run .play(id) | |
*/ | |
joinRoom(room, email) { | |
// const self = this; | |
// if (this.localStream) { | |
// this.localStream.stop(); | |
// this.localStream.close(); | |
// } | |
var videoDevices; | |
var audioDevices; | |
getDevices().subscribe({ | |
"next": (data) => { | |
audioDevices = data.audioDevices; | |
videoDevices = data.videoDevices; | |
}, | |
"error": (err) => console.error(err) | |
}); | |
const client = window.AgoraRTC.createClient({"mode": "interop"}); | |
console.log("PARTID Create Client"); | |
client.init(this.agora_key, () => { | |
client.join(null, room, null, (uid) => { | |
const constraints = Conference.getConstraints(); | |
this.id = uid; | |
// this.signaling = new Signaling( | |
// this.id, | |
// this.agora_key, | |
// email, | |
// this.messageRecievedSubject, | |
// this.newParticipantSubject, | |
// this.updateParticipantSubject) | |
// this.signaling.joinRoom(room) | |
console.log("PARTID Joined: " + room + " Generated ID:" + this.id); | |
const localStream = window.AgoraRTC.createStream({ | |
"streamID": uid, | |
"audio": constraints.audio, | |
"video": constraints.video, | |
"cameraId": videoDevices[0].deviceId, | |
"microphoneId": audioDevices[0].deviceId, | |
"screen": false | |
}); | |
if (isMobile.Mobile()) { | |
localStream.setVideoProfile("120P"); | |
} else { | |
localStream.setVideoProfile("720p_3"); | |
} | |
localStream.init(() => { | |
console.log("getUserMedia successfully"); | |
this.localVideoSubject.next({ | |
"stream": localStream, | |
"id": uid | |
}); | |
client.publish(localStream, (err) => { | |
console.log("Local Video Stream error: " + err); | |
}); | |
client.on("stream-published", (evt) => { | |
console.log("Local Video Stream Acquired"); | |
}); | |
}, (err) => { | |
console.log("getUserMedia failed", err); | |
}); | |
}); | |
}); | |
client.on('error', (err) => { | |
console.log("PARTID Got error msg:", err.reason); | |
}); | |
client.on("stream-added", (evt) => { | |
const stream = evt.stream; | |
const id = stream.getId(); | |
console.log("PARTID Subscribe stream added id: " + id ); | |
client.subscribe(stream, (err) => { | |
console.log("Subscribe stream failed", err); | |
}); | |
}); | |
client.on("stream-subscribed", (evt) => { | |
const stream = evt.stream; | |
const id = stream.getId(); | |
console.log("PARTID Subscribe remote stream successfully: " + id); | |
// this.remoteVideoSubject.next({ | |
// "stream": stream, | |
// "id": id, | |
// }); | |
}); | |
client.on('peer-leave', (evt) => { | |
var stream = evt.stream; | |
const id = stream.getId() | |
stream.stop(); | |
// this.removeVideoSubject.next(id); | |
}); | |
client.on('stream-removed', (evt) => { | |
var stream = evt.stream; | |
const id = stream.getId() | |
stream.stop(); | |
// this.removeVideoSubject.next(id); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment