mirror of
https://github.com/ianramzy/decentralized-video-chat.git
synced 2025-02-23 00:15:04 +08:00
fix bugs
This commit is contained in:
parent
18bb31c529
commit
3740ae6ff6
@ -6,7 +6,6 @@
|
|||||||
<link rel="shortcut icon" href="images/logo.svg">
|
<link rel="shortcut icon" href="images/logo.svg">
|
||||||
<link rel="stylesheet" href="../css/chat.css">
|
<link rel="stylesheet" href="../css/chat.css">
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
|
||||||
<script src="js/snackbar.js"></script>
|
|
||||||
<meta property="og:title" content="Join your friends call - Neonchat">
|
<meta property="og:title" content="Join your friends call - Neonchat">
|
||||||
<meta property="og:description" content="Click the link to join this chat room using Neonchat">
|
<meta property="og:description" content="Click the link to join this chat room using Neonchat">
|
||||||
<meta property="og:image" content="https://neonchat.io/images/preview.png">
|
<meta property="og:image" content="https://neonchat.io/images/preview.png">
|
||||||
|
@ -54,14 +54,14 @@ var VideoChat = {
|
|||||||
// noMediaStream function.
|
// noMediaStream function.
|
||||||
requestMediaStream: function (event) {
|
requestMediaStream: function (event) {
|
||||||
|
|
||||||
console.log("requestMediaStream");
|
logIt("requestMediaStream");
|
||||||
navigator.mediaDevices
|
navigator.mediaDevices
|
||||||
.getUserMedia({video: true, audio: true})
|
.getUserMedia({video: true, audio: true})
|
||||||
.then(stream => {
|
.then(stream => {
|
||||||
VideoChat.onMediaStream(stream);
|
VideoChat.onMediaStream(stream);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log(error);
|
logIt(error);
|
||||||
logIt('Failed to get local webcam video, check webcam privacy settings');
|
logIt('Failed to get local webcam video, check webcam privacy settings');
|
||||||
setTimeout(VideoChat.requestMediaStream, 1000);
|
setTimeout(VideoChat.requestMediaStream, 1000);
|
||||||
// alert("Please check your webcam browser privacy settings.")
|
// alert("Please check your webcam browser privacy settings.")
|
||||||
@ -75,7 +75,7 @@ var VideoChat = {
|
|||||||
VideoChat.onMediaStream(stream);
|
VideoChat.onMediaStream(stream);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log(error);
|
logIt(error);
|
||||||
logIt('No media stream for us.');
|
logIt('No media stream for us.');
|
||||||
alert("Please check your screen sharing browser privacy settings.")
|
alert("Please check your screen sharing browser privacy settings.")
|
||||||
});
|
});
|
||||||
@ -83,12 +83,12 @@ var VideoChat = {
|
|||||||
|
|
||||||
// The onMediaStream function receives the media stream as an argument.
|
// The onMediaStream function receives the media stream as an argument.
|
||||||
onMediaStream: function (stream) {
|
onMediaStream: function (stream) {
|
||||||
console.log("onMediaStream");
|
logIt("onMediaStream");
|
||||||
VideoChat.localStream = stream;
|
VideoChat.localStream = stream;
|
||||||
// Add the stream as video's srcObject.
|
// Add the stream as video's srcObject.
|
||||||
Snackbar.show({
|
Snackbar.show({
|
||||||
text: 'Share this URL with a friend to get started',
|
text: 'Share this URL with a friend to get started',
|
||||||
actionText: 'Copy URL',
|
actionText: 'Copy Link',
|
||||||
width: '355px',
|
width: '355px',
|
||||||
pos: 'top-left',
|
pos: 'top-left',
|
||||||
actionTextColor: '#8688ff',
|
actionTextColor: '#8688ff',
|
||||||
@ -120,16 +120,16 @@ var VideoChat = {
|
|||||||
|
|
||||||
// When we are ready to call, enable the Call button.
|
// When we are ready to call, enable the Call button.
|
||||||
readyToCall: function (event) {
|
readyToCall: function (event) {
|
||||||
// Show share URL
|
logIt("readyToCall");
|
||||||
console.log("readyToCall");
|
|
||||||
if (VideoChat.willInitiateCall) {
|
if (VideoChat.willInitiateCall) {
|
||||||
|
logIt("Initiating call")
|
||||||
VideoChat.startCall()
|
VideoChat.startCall()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set up a callback to run when we have the ephemeral token to use Twilio's TURN server.
|
// Set up a callback to run when we have the ephemeral token to use Twilio's TURN server.
|
||||||
startCall: function (event) {
|
startCall: function (event) {
|
||||||
console.log("startCall");
|
logIt("startCall");
|
||||||
logIt('>>> Sending token request...');
|
logIt('>>> Sending token request...');
|
||||||
VideoChat.socket.on('token', VideoChat.onToken(VideoChat.createOffer));
|
VideoChat.socket.on('token', VideoChat.onToken(VideoChat.createOffer));
|
||||||
VideoChat.socket.emit('token', roomHash);
|
VideoChat.socket.emit('token', roomHash);
|
||||||
@ -137,13 +137,15 @@ var VideoChat = {
|
|||||||
|
|
||||||
// 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) {
|
||||||
console.log("onToken");
|
logIt("onToken");
|
||||||
return function (token) {
|
return function (token) {
|
||||||
logIt('<<< Received token');
|
logIt('<<< Received token');
|
||||||
// Set up a new RTCPeerConnection using the token's iceServers.
|
// Set up a new RTCPeerConnection using the token's iceServers.
|
||||||
VideoChat.peerConnection = new RTCPeerConnection({iceServers: token.iceServers});
|
VideoChat.peerConnection = new RTCPeerConnection({iceServers: token.iceServers});
|
||||||
// Add the local video stream to the peerConnection.
|
// Add the local video stream to the peerConnection.
|
||||||
VideoChat.peerConnection.addStream(VideoChat.localStream);
|
VideoChat.localStream.getTracks().forEach(function (track) {
|
||||||
|
VideoChat.peerConnection.addTrack(track, VideoChat.localStream);
|
||||||
|
});
|
||||||
// Set up callbacks for the connection generating iceCandidates or
|
// Set up callbacks for the connection generating iceCandidates or
|
||||||
// receiving the remote media stream.
|
// receiving the remote media stream.
|
||||||
VideoChat.peerConnection.onicecandidate = VideoChat.onIceCandidate;
|
VideoChat.peerConnection.onicecandidate = VideoChat.onIceCandidate;
|
||||||
@ -158,7 +160,7 @@ var VideoChat = {
|
|||||||
|
|
||||||
// When the peerConnection generates an ice candidate, send it over the socket to the peer.
|
// When the peerConnection generates an ice candidate, send it over the socket to the peer.
|
||||||
onIceCandidate: function (event) {
|
onIceCandidate: function (event) {
|
||||||
console.log("onIceCandidate");
|
logIt("onIceCandidate");
|
||||||
if (event.candidate) {
|
if (event.candidate) {
|
||||||
logIt(`<<< Received local ICE candidate from STUN/TURN server (${event.candidate.address})`);
|
logIt(`<<< Received local ICE candidate from STUN/TURN server (${event.candidate.address})`);
|
||||||
if (VideoChat.connected) {
|
if (VideoChat.connected) {
|
||||||
@ -177,7 +179,7 @@ var VideoChat = {
|
|||||||
// When receiving a candidate over the socket, turn it back into a real
|
// When receiving a candidate over the socket, turn it back into a real
|
||||||
// RTCIceCandidate and add it to the peerConnection.
|
// RTCIceCandidate and add it to the peerConnection.
|
||||||
onCandidate: function (candidate) {
|
onCandidate: function (candidate) {
|
||||||
console.log("onCandidate");
|
logIt("onCandidate");
|
||||||
rtcCandidate = new RTCIceCandidate(JSON.parse(candidate));
|
rtcCandidate = new RTCIceCandidate(JSON.parse(candidate));
|
||||||
logIt(`<<< Received remote ICE candidate (${rtcCandidate.address} - ${rtcCandidate.relatedAddress})`);
|
logIt(`<<< Received remote ICE candidate (${rtcCandidate.address} - ${rtcCandidate.relatedAddress})`);
|
||||||
VideoChat.peerConnection.addIceCandidate(rtcCandidate);
|
VideoChat.peerConnection.addIceCandidate(rtcCandidate);
|
||||||
@ -185,7 +187,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 () {
|
createOffer: function () {
|
||||||
console.log("createOffer");
|
logIt("createOffer");
|
||||||
logIt('>>> Creating offer...');
|
logIt('>>> Creating offer...');
|
||||||
VideoChat.peerConnection.createOffer(
|
VideoChat.peerConnection.createOffer(
|
||||||
function (offer) {
|
function (offer) {
|
||||||
@ -208,7 +210,7 @@ var VideoChat = {
|
|||||||
// description to the peerConnection object. Then the answer is created in the
|
// description to the peerConnection object. Then the answer is created in the
|
||||||
// same manner as the offer and sent over the socket.
|
// same manner as the offer and sent over the socket.
|
||||||
createAnswer: function (offer) {
|
createAnswer: function (offer) {
|
||||||
console.log("createAnswer");
|
logIt("createAnswer");
|
||||||
return function () {
|
return function () {
|
||||||
logIt('>>> Creating answer...');
|
logIt('>>> Creating answer...');
|
||||||
VideoChat.connected = true;
|
VideoChat.connected = true;
|
||||||
@ -230,7 +232,7 @@ var VideoChat = {
|
|||||||
// When a browser receives an offer, set up a callback to be run when the
|
// When a browser receives an offer, set up a callback to be run when the
|
||||||
// ephemeral token is returned from Twilio.
|
// ephemeral token is returned from Twilio.
|
||||||
onOffer: function (offer) {
|
onOffer: function (offer) {
|
||||||
console.log("onOffer");
|
logIt("onOffer");
|
||||||
logIt('<<< Received offer');
|
logIt('<<< Received offer');
|
||||||
VideoChat.socket.on('token', VideoChat.onToken(VideoChat.createAnswer(offer)));
|
VideoChat.socket.on('token', VideoChat.onToken(VideoChat.createAnswer(offer)));
|
||||||
VideoChat.socket.emit('token', roomHash);
|
VideoChat.socket.emit('token', roomHash);
|
||||||
@ -239,7 +241,7 @@ var VideoChat = {
|
|||||||
// When an answer is received, add it to the peerConnection as the remote
|
// When an answer is received, add it to the peerConnection as the remote
|
||||||
// description.
|
// description.
|
||||||
onAnswer: function (answer) {
|
onAnswer: function (answer) {
|
||||||
console.log("onAnswer");
|
logIt("onAnswer");
|
||||||
logIt('<<< Received answer');
|
logIt('<<< Received answer');
|
||||||
var rtcAnswer = new RTCSessionDescription(JSON.parse(answer));
|
var rtcAnswer = new RTCSessionDescription(JSON.parse(answer));
|
||||||
VideoChat.peerConnection.setRemoteDescription(rtcAnswer);
|
VideoChat.peerConnection.setRemoteDescription(rtcAnswer);
|
||||||
@ -257,7 +259,7 @@ var VideoChat = {
|
|||||||
// When the peerConnection receives the actual media stream from the other
|
// When the peerConnection receives the actual media stream from the other
|
||||||
// browser, add it to the other video element on the page.
|
// browser, add it to the other video element on the page.
|
||||||
onAddStream: function (event) {
|
onAddStream: function (event) {
|
||||||
console.log("onAddStream");
|
logIt("onAddStream");
|
||||||
logIt('<<< Received new stream from remote. Adding it...');
|
logIt('<<< Received new stream from remote. Adding it...');
|
||||||
VideoChat.remoteVideo.srcObject = event.stream;
|
VideoChat.remoteVideo.srcObject = event.stream;
|
||||||
Snackbar.close();
|
Snackbar.close();
|
||||||
@ -336,8 +338,6 @@ Snackbar.show({
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// auto get media
|
// auto get media
|
||||||
// VideoChat.requestScreenStream();
|
// VideoChat.requestScreenStream();
|
||||||
VideoChat.requestMediaStream();
|
VideoChat.requestMediaStream();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user