Compare commits
No commits in common. "2cae020fbcdb58be46dc3bf787a88ebea46db2d2" and "c7bcf8e2ddf8854192ecb71989e478544b8d891f" have entirely different histories.
2cae020fbc
...
c7bcf8e2dd
|
@ -204,15 +204,6 @@ form label {
|
|||
|
||||
var pc = undefined;
|
||||
var dc = undefined;
|
||||
|
||||
function sendOffer() {
|
||||
if (pc.iceGatheringState == "complete") {
|
||||
sendJson({
|
||||
description: pc.localDescription
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function createRTCPeerConnection() {
|
||||
const pc = new RTCPeerConnection();
|
||||
log("Created RTCPeerConnection.");
|
||||
|
@ -223,17 +214,19 @@ form label {
|
|||
pc.oniceconnectionstatechange = e => {
|
||||
log("pc.oniceconnectionstatechange: " + pc.iceConnectionState);
|
||||
}
|
||||
pc.onicegatheringstatechange = async function(e) {
|
||||
pc.onicegatheringstatechange = e => {
|
||||
log("pc.onicegatheringstatechange: " + pc.iceGatheringState);
|
||||
sendOffer();
|
||||
}
|
||||
|
||||
pc.onicecandidate = ({candidate}) => sendJson({candidate});
|
||||
|
||||
// let the "negotiationneeded" event trigger offer generation
|
||||
// ... but only once icegathering is complete.
|
||||
pc.onnegotiationneeded = async function () {
|
||||
log("In pc.onnegotiationneeded...");
|
||||
await pc.setLocalDescription(await pc.createOffer());
|
||||
sendOffer();
|
||||
sendJson({
|
||||
description: pc.localDescription
|
||||
});
|
||||
}
|
||||
|
||||
pc.ontrack = ({streams: [stream]}) => {
|
||||
|
@ -269,7 +262,7 @@ form label {
|
|||
log("Data channel open, sending settings...")
|
||||
settings = readSettingsForm(true);
|
||||
sendJson({settings});
|
||||
startStreamingWithErorrHandling(false);
|
||||
startStartingWithErorrHandling(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,7 +321,7 @@ form label {
|
|||
pc.addTrack(track, stream);
|
||||
}
|
||||
}
|
||||
function startStreamingWithErorrHandling(fromButton) {
|
||||
function startStartingWithErorrHandling(fromButton) {
|
||||
startStreaming(fromButton)
|
||||
.then(() => {
|
||||
log("startStreaming() finished.");
|
||||
|
@ -339,7 +332,7 @@ form label {
|
|||
}
|
||||
|
||||
start.addEventListener("click", _ => {
|
||||
startStreamingWithErorrHandling(true)
|
||||
startStartingWithErorrHandling(true)
|
||||
});
|
||||
|
||||
async function receiveMessage(e) {
|
||||
|
@ -350,17 +343,26 @@ form label {
|
|||
if (data.ready) {
|
||||
// Ready message means client is open and ready for connection.
|
||||
pc = createRTCPeerConnection();
|
||||
} else if (data.requestSettings) {
|
||||
settings = readSettingsForm(true);
|
||||
startStartingWithErorrHandling(false);
|
||||
} else if (data.settings) {
|
||||
settings = data.settings;
|
||||
startStreamingWithErorrHandling(false);
|
||||
startStartingWithErorrHandling(false);
|
||||
} else if (data.description) {
|
||||
if (pc == undefined) pc = createRTCPeerConnection();
|
||||
await pc.setRemoteDescription(data.description);
|
||||
if (data.description.type == "offer") {
|
||||
log("Got an offer...");
|
||||
await pc.setLocalDescription(await pc.createAnswer());
|
||||
sendOffer();
|
||||
sendJson({
|
||||
description: pc.localDescription
|
||||
});
|
||||
}
|
||||
} else if (data.candidate) {
|
||||
if (pc == undefined) pc = createRTCPeerConnection();
|
||||
log("Adding ice candidate...");
|
||||
await pc.addIceCandidate(data.candidate);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user