mirror of
https://github.com/ianramzy/decentralized-video-chat.git
synced 2025-02-22 16:05:03 +08:00
removed debug code
This commit is contained in:
parent
58bc2858ea
commit
64ef2b4196
@ -94,12 +94,9 @@ var VideoChat = {
|
|||||||
VideoChat.localVideo.srcObject = stream;
|
VideoChat.localVideo.srcObject = stream;
|
||||||
// Now we're ready to join the chat room.
|
// Now we're ready to join the chat room.
|
||||||
VideoChat.socket.emit("join", roomHash);
|
VideoChat.socket.emit("join", roomHash);
|
||||||
// Receive its own uuid
|
|
||||||
VideoChat.socket.on("uuid", (uuid) => (VideoChat.uuid = uuid));
|
|
||||||
// Add listeners to the websocket
|
// Add listeners to the websocket
|
||||||
VideoChat.socket.on("full", chatRoomFull);
|
VideoChat.socket.on("full", chatRoomFull);
|
||||||
VideoChat.socket.on("offer", VideoChat.onOffer);
|
VideoChat.socket.on("offer", VideoChat.onOffer);
|
||||||
VideoChat.socket.on("ready", VideoChat.readyToCall);
|
|
||||||
VideoChat.socket.on("willInitiateCall", VideoChat.call);
|
VideoChat.socket.on("willInitiateCall", VideoChat.call);
|
||||||
// Set up listeners on the socket
|
// Set up listeners on the socket
|
||||||
VideoChat.socket.on("candidate", VideoChat.onCandidate);
|
VideoChat.socket.on("candidate", VideoChat.onCandidate);
|
||||||
@ -110,17 +107,9 @@ var VideoChat = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
// When we are ready to call, enable the Call button.
|
|
||||||
readyToCall: function (event) {
|
|
||||||
logIt("readyToCall");
|
|
||||||
},
|
|
||||||
call: function (uuid, room) {
|
|
||||||
logIt("Initiating call");
|
|
||||||
VideoChat.startCall(uuid);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Set up a callback to run when we have the ephemeral token to use Twilio's TURN server.
|
call: function (uuid, room) {
|
||||||
startCall: function (uuid) {
|
logIt("Initiating call with " + uuid);
|
||||||
VideoChat.socket.on(
|
VideoChat.socket.on(
|
||||||
"token",
|
"token",
|
||||||
VideoChat.establishConnection(uuid, function (a) {
|
VideoChat.establishConnection(uuid, function (a) {
|
||||||
@ -136,8 +125,8 @@ var VideoChat = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("establishing connection to", uuid);
|
console.log("establishing connection to", uuid);
|
||||||
|
// Initialise localICEcandidates for node uuid with empty array
|
||||||
VideoChat.localICECandidates[uuid] = []; // initialise uuid with empty array
|
VideoChat.localICECandidates[uuid] = [];
|
||||||
VideoChat.connected[uuid] = false;
|
VideoChat.connected[uuid] = false;
|
||||||
|
|
||||||
// Set up a new RTCPeerConnection using the token's iceServers.
|
// Set up a new RTCPeerConnection using the token's iceServers.
|
||||||
@ -191,8 +180,6 @@ var VideoChat = {
|
|||||||
case "connected":
|
case "connected":
|
||||||
logIt("connected");
|
logIt("connected");
|
||||||
// Once connected we no longer have a need for the signaling server, so disconnect
|
// Once connected we no longer have a need for the signaling server, so disconnect
|
||||||
// VideoChat.socket.off("token");
|
|
||||||
// VideoChat.socket.off("offer");
|
|
||||||
break;
|
break;
|
||||||
case "disconnected":
|
case "disconnected":
|
||||||
logIt("disconnected");
|
logIt("disconnected");
|
||||||
@ -251,12 +238,7 @@ var VideoChat = {
|
|||||||
|
|
||||||
// Create an offer that contains the media capabilities of the browser.
|
// Create an offer that contains the media capabilities of the browser.
|
||||||
createOffer: function (uuid) {
|
createOffer: function (uuid) {
|
||||||
console.log(
|
logIt(`createOffer to ${uuid} >>> Creating offer...`);
|
||||||
">>> Creating offer to UUID: ",
|
|
||||||
uuid,
|
|
||||||
". my UUID is",
|
|
||||||
VideoChat.socket.id
|
|
||||||
);
|
|
||||||
VideoChat.peerConnections[uuid].createOffer(
|
VideoChat.peerConnections[uuid].createOffer(
|
||||||
function (offer) {
|
function (offer) {
|
||||||
// If the offer is created successfully, set it as the local description
|
// If the offer is created successfully, set it as the local description
|
||||||
@ -280,22 +262,11 @@ var VideoChat = {
|
|||||||
createAnswer: function (offer, uuid) {
|
createAnswer: function (offer, uuid) {
|
||||||
logIt("createAnswer");
|
logIt("createAnswer");
|
||||||
rtcOffer = new RTCSessionDescription(JSON.parse(offer));
|
rtcOffer = new RTCSessionDescription(JSON.parse(offer));
|
||||||
console.log(
|
logIt(`>>> Creating answer to ${uuid}`);
|
||||||
"createAnswer: setting remote description of " +
|
|
||||||
uuid +
|
|
||||||
" on " +
|
|
||||||
VideoChat.socket.id
|
|
||||||
);
|
|
||||||
VideoChat.peerConnections[uuid].setRemoteDescription(rtcOffer);
|
VideoChat.peerConnections[uuid].setRemoteDescription(rtcOffer);
|
||||||
VideoChat.peerConnections[uuid].createAnswer(
|
VideoChat.peerConnections[uuid].createAnswer(
|
||||||
function (answer) {
|
function (answer) {
|
||||||
VideoChat.peerConnections[uuid].setLocalDescription(answer);
|
VideoChat.peerConnections[uuid].setLocalDescription(answer);
|
||||||
console.log(
|
|
||||||
">>> Creating answer to UUID: ",
|
|
||||||
uuid,
|
|
||||||
". my UUID is",
|
|
||||||
VideoChat.socket.id
|
|
||||||
);
|
|
||||||
VideoChat.socket.emit("answer", JSON.stringify(answer), roomHash, uuid);
|
VideoChat.socket.emit("answer", JSON.stringify(answer), roomHash, uuid);
|
||||||
},
|
},
|
||||||
function (err) {
|
function (err) {
|
||||||
@ -321,22 +292,9 @@ var VideoChat = {
|
|||||||
|
|
||||||
// When an answer is received, add it to the peerConnection as the remote description.
|
// When an answer is received, add it to the peerConnection as the remote description.
|
||||||
onAnswer: function (answer, uuid) {
|
onAnswer: function (answer, uuid) {
|
||||||
console.log(
|
logIt(`onAnswer <<< Received answer from ${uuid}`);
|
||||||
"onAnswer <<< Received answer",
|
|
||||||
uuid,
|
|
||||||
". my UUID is",
|
|
||||||
VideoChat.socket.id
|
|
||||||
);
|
|
||||||
|
|
||||||
// logIt("onAnswer <<< Received answer" + "");
|
|
||||||
var rtcAnswer = new RTCSessionDescription(JSON.parse(answer));
|
var rtcAnswer = new RTCSessionDescription(JSON.parse(answer));
|
||||||
// Set remote description of RTCSession
|
// Set remote description of RTCSession
|
||||||
console.log(
|
|
||||||
"onAnswer: setting remote description of " +
|
|
||||||
uuid +
|
|
||||||
" on " +
|
|
||||||
VideoChat.socket.id
|
|
||||||
);
|
|
||||||
VideoChat.peerConnections[uuid].setRemoteDescription(rtcAnswer);
|
VideoChat.peerConnections[uuid].setRemoteDescription(rtcAnswer);
|
||||||
// The caller now knows that the callee is ready to accept new ICE candidates, so sending the buffer over
|
// The caller now knows that the callee is ready to accept new ICE candidates, so sending the buffer over
|
||||||
VideoChat.localICECandidates[uuid].forEach((candidate) => {
|
VideoChat.localICECandidates[uuid].forEach((candidate) => {
|
||||||
@ -353,14 +311,8 @@ var VideoChat = {
|
|||||||
|
|
||||||
// Called when a stream is added to the peer connection
|
// Called when a stream is added to the peer connection
|
||||||
onAddStream: function (event, uuid) {
|
onAddStream: function (event, uuid) {
|
||||||
// if(VideoChat.counter > 4) {
|
|
||||||
// VideoChat.socket.disconnect();
|
|
||||||
// }else{
|
|
||||||
// VideoChat.counter++;
|
|
||||||
// }
|
|
||||||
logIt(
|
logIt(
|
||||||
"onAddStream <<< Received new stream from remote. Adding it..." + event
|
"onAddStream <<< Received new stream from remote. Adding it...");
|
||||||
);
|
|
||||||
// Create new remote video source in wrapper
|
// Create new remote video source in wrapper
|
||||||
// Create a <video> node
|
// Create a <video> node
|
||||||
var node = document.createElement("video");
|
var node = document.createElement("video");
|
||||||
|
@ -92,7 +92,7 @@ io.on("connection", function (socket) {
|
|||||||
// Existing callers initiates call with user
|
// Existing callers initiates call with user
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (numClients < 4) {
|
} else if (numClients < 5) {
|
||||||
socket.join(room);
|
socket.join(room);
|
||||||
logIt("Connected clients", room);
|
logIt("Connected clients", room);
|
||||||
for (var clientId in clients.sockets) {
|
for (var clientId in clients.sockets) {
|
||||||
@ -102,9 +102,6 @@ io.on("connection", function (socket) {
|
|||||||
// When the client is not the first to join the room, all clients are ready.
|
// When the client is not the first to join the room, all clients are ready.
|
||||||
logIt("Broadcasting ready message", room);
|
logIt("Broadcasting ready message", room);
|
||||||
socket.broadcast.to(room).emit("willInitiateCall", socket.id, room);
|
socket.broadcast.to(room).emit("willInitiateCall", socket.id, room);
|
||||||
// socket.emit("uuid", socket.id);
|
|
||||||
socket.emit("ready", room).to(room);
|
|
||||||
socket.broadcast.to(room).emit("ready", room);
|
|
||||||
} else {
|
} else {
|
||||||
logIt(
|
logIt(
|
||||||
"room already full with " + numClients + " people in the room.",
|
"room already full with " + numClients + " people in the room.",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user