0
整合JSEP我發現這個video conferencing prototype。但是由於ROAP協議已被JSEP取代,我無法運行它。中的WebRTC演示
我曾嘗試使用以下資源來解決這個問題:
我想很多人會喜歡有一個工作JSEP例子建。
<script>
var socket = new WebSocket('ws://mydomain.com:1337');
var sourcevid = document.getElementById('sourcevid');
var remotevid = document.getElementById('remotevid');
var localStream = null;
var peerConn = null;
var started = false;
var logg = function(s) { console.log(s); };
// when PeerConn is created, send setup data to peer via WebSocket
function onSignal(message) {
logg("Sending setup signal");
socket.send(message);
}
// when remote adds a stream, hand it on to the local video element
function onRemoteStreamAdded(event) {
logg("Added remote stream");
remotevid.src = window.webkitURL.createObjectURL(event.stream);
}
// when remote removes a stream, remove it from the local video element
function onRemoteStreamRemoved(event) {
logg("Remove remote stream");
remotevid.src = "";
}
function createPeerConnection() {
try {
logg("Creating peer connection");
peerConn = new webkitDeprecatedPeerConnection("STUN stun.l.google.com:19302", onSignal);
} catch (e) {
try {
peerConn = new webkitPeerConnection00("STUN stun.l.google.com:19302", onSignal);
} catch (e) {
console.log("Failed to create PeerConnection, exception: " + e.message);
}
}
peerConn.addEventListener("addstream", onRemoteStreamAdded, false);
peerConn.addEventListener("removestream", onRemoteStreamRemoved, false)
}
// start the connection upon user request
function connect() {
if (!started && localStream) {
createPeerConnection();
logg('Adding local stream...');
peerConn.addStream(localStream);
started = true;
} else {
alert("Local stream not running yet.");
}
}
// accept connection request
socket.addEventListener("message", onMessage, false);
function onMessage(evt) {
logg("RECEIVED: "+evt.data);
if (!started) {
createPeerConnection();
logg('Adding local stream...');
peerConn.addStream(localStream);
started = true;
}
// Message returned from other side
logg('Processing signaling message...');
peerConn.processSignalingMessage(evt.data);
}
function hangUp() {
logg("Hang up.");
peerConn.close();
peerConn = null;
started = false;
}
function startVideo() {
// Replace the source of the video element with the stream from the camera
try { //try it with spec syntax
navigator.webkitGetUserMedia({audio: true, video: true}, successCallback, errorCallback);
} catch (e) {
navigator.webkitGetUserMedia("video,audio", successCallback, errorCallback);
}
function successCallback(stream) {
sourcevid.src = window.webkitURL.createObjectURL(stream);
localStream = stream;
}
function errorCallback(error) {
console.error('An error occurred: [CODE ' + error.code + ']');
}
}
function stopVideo() {
sourcevid.src = "";
}
</script>
雖然此鏈接可以回答這個問題,最好是在這裏有答案的主要部件,並提供鏈接以供參考。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – LittleBobbyTables
對不起 - 通過我的手機在火車上快速添加答案!現在添加更多細節。 –
謝謝你的回覆。我只是不明白我如何使用webSocket來使用ROAP到JSEP庫(在本例中爲pc1&pc2)在兩個對等方之間進行通信。 – user574199