mirror of
https://github.com/ianramzy/decentralized-video-chat.git
synced 2025-02-23 16:35:03 +08:00
first attempt at resolving the issue
- join room even if no local video is available - set the local video's source when input media changes
This commit is contained in:
parent
0f59dc141c
commit
711e79d8dd
@ -39,9 +39,11 @@ var VideoChat = {
|
|||||||
// asking for access to both the video and audio streams. If the request is
|
// asking for access to both the video and audio streams. If the request is
|
||||||
// accepted callback to the onMediaStream function, otherwise callback to the
|
// accepted callback to the onMediaStream function, otherwise callback to the
|
||||||
// noMediaStream function.
|
// noMediaStream function.
|
||||||
requestMediaStream: function (event) {
|
requestMediaStream: function (reposition = true) {
|
||||||
logIt("requestMediaStream");
|
logIt("requestMediaStream");
|
||||||
rePositionLocalVideo();
|
if (reposition) {
|
||||||
|
rePositionLocalVideo();
|
||||||
|
}
|
||||||
navigator.mediaDevices
|
navigator.mediaDevices
|
||||||
.getUserMedia({
|
.getUserMedia({
|
||||||
video: true,
|
video: true,
|
||||||
@ -58,7 +60,7 @@ var VideoChat = {
|
|||||||
"Failed to get local webcam video, check webcam privacy settings"
|
"Failed to get local webcam video, check webcam privacy settings"
|
||||||
);
|
);
|
||||||
// Keep trying to get user media
|
// Keep trying to get user media
|
||||||
setTimeout(VideoChat.requestMediaStream, 1000);
|
// setTimeout(VideoChat.requestMediaStream, 1000);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -91,16 +93,13 @@ var VideoChat = {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
VideoChat.localVideo.srcObject = stream;
|
VideoChat.localVideo.srcObject = stream;
|
||||||
// Now we're ready to join the chat room.
|
|
||||||
VideoChat.socket.emit("join", roomHash);
|
if (VideoChat.peerConnection && VideoChat.localStream) {
|
||||||
// Add listeners to the websocket
|
VideoChat.localStream.getTracks().forEach(function (track) {
|
||||||
VideoChat.socket.on("full", chatRoomFull);
|
VideoChat.peerConnection.addTrack(track, VideoChat.localStream);
|
||||||
VideoChat.socket.on("offer", VideoChat.onOffer);
|
});
|
||||||
VideoChat.socket.on("ready", VideoChat.readyToCall);
|
}
|
||||||
VideoChat.socket.on(
|
|
||||||
"willInitiateCall",
|
|
||||||
() => (VideoChat.willInitiateCall = true)
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// When we are ready to call, enable the Call button.
|
// When we are ready to call, enable the Call button.
|
||||||
@ -120,6 +119,18 @@ var VideoChat = {
|
|||||||
VideoChat.socket.emit("token", roomHash);
|
VideoChat.socket.emit("token", roomHash);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
joinRoom: function () {
|
||||||
|
VideoChat.socket.emit("join", roomHash);
|
||||||
|
// Add listeners to the websocket
|
||||||
|
VideoChat.socket.on("full", chatRoomFull);
|
||||||
|
VideoChat.socket.on("offer", VideoChat.onOffer);
|
||||||
|
VideoChat.socket.on("ready", VideoChat.readyToCall);
|
||||||
|
VideoChat.socket.on(
|
||||||
|
"willInitiateCall",
|
||||||
|
() => (VideoChat.willInitiateCall = true)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
// When we receive the ephemeral token back from the server.
|
// When we receive the ephemeral token back from the server.
|
||||||
onToken: function (callback) {
|
onToken: function (callback) {
|
||||||
logIt("onToken");
|
logIt("onToken");
|
||||||
@ -130,9 +141,11 @@ var VideoChat = {
|
|||||||
iceServers: token.iceServers,
|
iceServers: token.iceServers,
|
||||||
});
|
});
|
||||||
// Add the local video stream to the peerConnection.
|
// Add the local video stream to the peerConnection.
|
||||||
VideoChat.localStream.getTracks().forEach(function (track) {
|
if (VideoChat.localStream) {
|
||||||
VideoChat.peerConnection.addTrack(track, VideoChat.localStream);
|
VideoChat.localStream.getTracks().forEach(function (track) {
|
||||||
});
|
VideoChat.peerConnection.addTrack(track, VideoChat.localStream);
|
||||||
|
});
|
||||||
|
}
|
||||||
// Add general purpose data channel to peer connection,
|
// Add general purpose data channel to peer connection,
|
||||||
// used for text chats, captions, and toggling sending captions
|
// used for text chats, captions, and toggling sending captions
|
||||||
dataChanel = VideoChat.peerConnection.createDataChannel("chat", {
|
dataChanel = VideoChat.peerConnection.createDataChannel("chat", {
|
||||||
@ -342,7 +355,7 @@ function getBrowserName() {
|
|||||||
|
|
||||||
// Basic logging class wrapper
|
// Basic logging class wrapper
|
||||||
function logIt(message, error) {
|
function logIt(message, error) {
|
||||||
console.log(message);
|
console.trace(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when socket receives message that room is full
|
// Called when socket receives message that room is full
|
||||||
@ -869,6 +882,8 @@ function startUp() {
|
|||||||
// get webcam on load
|
// get webcam on load
|
||||||
VideoChat.requestMediaStream();
|
VideoChat.requestMediaStream();
|
||||||
|
|
||||||
|
VideoChat.joinRoom();
|
||||||
|
|
||||||
// Captions hidden by default
|
// Captions hidden by default
|
||||||
captionText.text("").fadeOut();
|
captionText.text("").fadeOut();
|
||||||
|
|
||||||
@ -935,7 +950,11 @@ function startUp() {
|
|||||||
rePositionCaptions();
|
rePositionCaptions();
|
||||||
|
|
||||||
// On change media devices refresh page and switch to system default
|
// On change media devices refresh page and switch to system default
|
||||||
navigator.mediaDevices.ondevicechange = () => window.location.reload();
|
navigator.mediaDevices.ondevicechange = () => {
|
||||||
|
|
||||||
|
VideoChat.requestMediaStream(false);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
startUp();
|
startUp();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user