Remote video stream not displaying
RTCPeerConnection gets established and receives the clients reply which is 'answer' but does not show the remote video stream. The console log is shown below
console.log
From the log, the offer is sent to the peer which the peer sends back an answer that is console logged to display that it did actually send the answer back. I would greatly appreciate if you could take a look at my code pasted below and advise me how to go about rectifying it.
'use strict';
var localStream;
var remoteStream;
var isInitiator;
var configuration =
iceServers: [
urls: 'stun:stun.l.google.com:19302'
]
;
var pc = new RTCPeerConnection(configuration);
// Define action buttons.
const callButton = document.getElementById('callButton');
const hangupButton = document.getElementById('hangupButton');
/////////////////////////////////////////////
window.room = prompt('Enter room name:');
var socket = io.connect();
if (room !== '')
console.log('Message from client: Asking to join room ' + room);
socket.emit('create or join', room);
socket.on('created', function(room)
console.log('Created room ' + room);
isInitiator = true;
startVideo();
);
socket.on('joined', function(room)
console.log('joined: ' + room);
startVideo();
);
socket.on('log', function(array)
console.log.apply(console, array);
);
////////////////////////////////////////////////
function sendMessage(message)
socket.emit('message', message);
// This client receives a message
socket.on('message', function(message)
if (message.type === 'offer')
pc.setRemoteDescription(message);
console.log('Sending answer to peer.');
pc.createAnswer().then(
setLocalAndSendMessage,
onCreateSessionDescriptionError
);
else if (message.type === 'answer')
console.log('This is to check if answer was returned');
remoteStream = event.stream;
remoteVideo.srcObject = remoteStream;
pc.setRemoteDescription(message);
else if (message.type === 'candidate')
pc.addIceCandidate(candidate);
);
////////////////////////////////////////////////////
const localVideo = document.querySelector('#localVideo');
const remoteVideo = document.querySelector('#remoteVideo');
// Set up initial action buttons status: disable call and hangup.
callButton.disabled = true;
hangupButton.disabled = true;
// Add click event handlers for buttons.
callButton.addEventListener('click', callStart);
hangupButton.addEventListener('click', hangupCall);
function startVideo()
navigator.mediaDevices
.getUserMedia(
audio: true,
video: true
)
.then(gotStream)
.catch(function(e)
alert('getUserMedia() error: ' + e.name);
);
function gotStream(stream)
localVideo.srcObject = stream;
localStream = stream;
callButton.disabled = false;
function callStart()
createPeerConnection();
callButton.disabled = true;
hangupButton.disabled = false;
if (isInitiator)
console.log('Sending offer to peer');
pc.createOffer(setLocalAndSendMessage, handleCreateOfferError);
/////////////////////////////////////////////////////////
function createPeerConnection()
try
pc.onicecandidate = ( candidate ) => sendMessage( candidate );
pc.ontrack = event =>
if (remoteVideo.srcObject) return;
remoteVideo.srcObject = event.stream;
;
console.log('Created RTCPeerConnnection');
catch (e)
console.log('Failed to create PeerConnection, exception: ' + e.message);
alert('Cannot create RTCPeerConnection object.');
return;
function handleCreateOfferError(event)
console.log('createOffer() error: ', event);
function setLocalAndSendMessage(sessionDescription)
console.log('setLocalAndSendMessage sending message', sessionDescription);
pc.setLocalDescription(sessionDescription);
sendMessage(sessionDescription);
function onCreateSessionDescriptionError(error)
console.log('Failed to create session description: ' + error.toString());
function hangupCall()
pc.close();
pc = null;
javascript socket.io webrtc stun
add a comment |
RTCPeerConnection gets established and receives the clients reply which is 'answer' but does not show the remote video stream. The console log is shown below
console.log
From the log, the offer is sent to the peer which the peer sends back an answer that is console logged to display that it did actually send the answer back. I would greatly appreciate if you could take a look at my code pasted below and advise me how to go about rectifying it.
'use strict';
var localStream;
var remoteStream;
var isInitiator;
var configuration =
iceServers: [
urls: 'stun:stun.l.google.com:19302'
]
;
var pc = new RTCPeerConnection(configuration);
// Define action buttons.
const callButton = document.getElementById('callButton');
const hangupButton = document.getElementById('hangupButton');
/////////////////////////////////////////////
window.room = prompt('Enter room name:');
var socket = io.connect();
if (room !== '')
console.log('Message from client: Asking to join room ' + room);
socket.emit('create or join', room);
socket.on('created', function(room)
console.log('Created room ' + room);
isInitiator = true;
startVideo();
);
socket.on('joined', function(room)
console.log('joined: ' + room);
startVideo();
);
socket.on('log', function(array)
console.log.apply(console, array);
);
////////////////////////////////////////////////
function sendMessage(message)
socket.emit('message', message);
// This client receives a message
socket.on('message', function(message)
if (message.type === 'offer')
pc.setRemoteDescription(message);
console.log('Sending answer to peer.');
pc.createAnswer().then(
setLocalAndSendMessage,
onCreateSessionDescriptionError
);
else if (message.type === 'answer')
console.log('This is to check if answer was returned');
remoteStream = event.stream;
remoteVideo.srcObject = remoteStream;
pc.setRemoteDescription(message);
else if (message.type === 'candidate')
pc.addIceCandidate(candidate);
);
////////////////////////////////////////////////////
const localVideo = document.querySelector('#localVideo');
const remoteVideo = document.querySelector('#remoteVideo');
// Set up initial action buttons status: disable call and hangup.
callButton.disabled = true;
hangupButton.disabled = true;
// Add click event handlers for buttons.
callButton.addEventListener('click', callStart);
hangupButton.addEventListener('click', hangupCall);
function startVideo()
navigator.mediaDevices
.getUserMedia(
audio: true,
video: true
)
.then(gotStream)
.catch(function(e)
alert('getUserMedia() error: ' + e.name);
);
function gotStream(stream)
localVideo.srcObject = stream;
localStream = stream;
callButton.disabled = false;
function callStart()
createPeerConnection();
callButton.disabled = true;
hangupButton.disabled = false;
if (isInitiator)
console.log('Sending offer to peer');
pc.createOffer(setLocalAndSendMessage, handleCreateOfferError);
/////////////////////////////////////////////////////////
function createPeerConnection()
try
pc.onicecandidate = ( candidate ) => sendMessage( candidate );
pc.ontrack = event =>
if (remoteVideo.srcObject) return;
remoteVideo.srcObject = event.stream;
;
console.log('Created RTCPeerConnnection');
catch (e)
console.log('Failed to create PeerConnection, exception: ' + e.message);
alert('Cannot create RTCPeerConnection object.');
return;
function handleCreateOfferError(event)
console.log('createOffer() error: ', event);
function setLocalAndSendMessage(sessionDescription)
console.log('setLocalAndSendMessage sending message', sessionDescription);
pc.setLocalDescription(sessionDescription);
sendMessage(sessionDescription);
function onCreateSessionDescriptionError(error)
console.log('Failed to create session description: ' + error.toString());
function hangupCall()
pc.close();
pc = null;
javascript socket.io webrtc stun
Look in web console:TypeError: event is undefined; can't access its "stream" property
in the lineremoteStream = event.stream;
– jib
Nov 13 '18 at 20:31
Also, inpc.ontrack
you wantremoteVideo.srcObject = event.streams[0];
notevent.stream
.
– jib
Nov 13 '18 at 20:32
candidate
is also undefined.
– jib
Nov 13 '18 at 20:34
I fixed the pc.ontrack and did some changes to how the video get pulled using stream.gettrack which is now causing more errorsTypeError: stream.getTracks is not a function. (In 'stream.getTracks()', 'stream.getTracks' is undefined)
– Rj Tng
Nov 14 '18 at 1:24
This is basic debugging. Do aconsole.log(stream)
to learn what thestream
variable holds. It is clearly not a MediaStream object.
– jib
Nov 14 '18 at 2:33
add a comment |
RTCPeerConnection gets established and receives the clients reply which is 'answer' but does not show the remote video stream. The console log is shown below
console.log
From the log, the offer is sent to the peer which the peer sends back an answer that is console logged to display that it did actually send the answer back. I would greatly appreciate if you could take a look at my code pasted below and advise me how to go about rectifying it.
'use strict';
var localStream;
var remoteStream;
var isInitiator;
var configuration =
iceServers: [
urls: 'stun:stun.l.google.com:19302'
]
;
var pc = new RTCPeerConnection(configuration);
// Define action buttons.
const callButton = document.getElementById('callButton');
const hangupButton = document.getElementById('hangupButton');
/////////////////////////////////////////////
window.room = prompt('Enter room name:');
var socket = io.connect();
if (room !== '')
console.log('Message from client: Asking to join room ' + room);
socket.emit('create or join', room);
socket.on('created', function(room)
console.log('Created room ' + room);
isInitiator = true;
startVideo();
);
socket.on('joined', function(room)
console.log('joined: ' + room);
startVideo();
);
socket.on('log', function(array)
console.log.apply(console, array);
);
////////////////////////////////////////////////
function sendMessage(message)
socket.emit('message', message);
// This client receives a message
socket.on('message', function(message)
if (message.type === 'offer')
pc.setRemoteDescription(message);
console.log('Sending answer to peer.');
pc.createAnswer().then(
setLocalAndSendMessage,
onCreateSessionDescriptionError
);
else if (message.type === 'answer')
console.log('This is to check if answer was returned');
remoteStream = event.stream;
remoteVideo.srcObject = remoteStream;
pc.setRemoteDescription(message);
else if (message.type === 'candidate')
pc.addIceCandidate(candidate);
);
////////////////////////////////////////////////////
const localVideo = document.querySelector('#localVideo');
const remoteVideo = document.querySelector('#remoteVideo');
// Set up initial action buttons status: disable call and hangup.
callButton.disabled = true;
hangupButton.disabled = true;
// Add click event handlers for buttons.
callButton.addEventListener('click', callStart);
hangupButton.addEventListener('click', hangupCall);
function startVideo()
navigator.mediaDevices
.getUserMedia(
audio: true,
video: true
)
.then(gotStream)
.catch(function(e)
alert('getUserMedia() error: ' + e.name);
);
function gotStream(stream)
localVideo.srcObject = stream;
localStream = stream;
callButton.disabled = false;
function callStart()
createPeerConnection();
callButton.disabled = true;
hangupButton.disabled = false;
if (isInitiator)
console.log('Sending offer to peer');
pc.createOffer(setLocalAndSendMessage, handleCreateOfferError);
/////////////////////////////////////////////////////////
function createPeerConnection()
try
pc.onicecandidate = ( candidate ) => sendMessage( candidate );
pc.ontrack = event =>
if (remoteVideo.srcObject) return;
remoteVideo.srcObject = event.stream;
;
console.log('Created RTCPeerConnnection');
catch (e)
console.log('Failed to create PeerConnection, exception: ' + e.message);
alert('Cannot create RTCPeerConnection object.');
return;
function handleCreateOfferError(event)
console.log('createOffer() error: ', event);
function setLocalAndSendMessage(sessionDescription)
console.log('setLocalAndSendMessage sending message', sessionDescription);
pc.setLocalDescription(sessionDescription);
sendMessage(sessionDescription);
function onCreateSessionDescriptionError(error)
console.log('Failed to create session description: ' + error.toString());
function hangupCall()
pc.close();
pc = null;
javascript socket.io webrtc stun
RTCPeerConnection gets established and receives the clients reply which is 'answer' but does not show the remote video stream. The console log is shown below
console.log
From the log, the offer is sent to the peer which the peer sends back an answer that is console logged to display that it did actually send the answer back. I would greatly appreciate if you could take a look at my code pasted below and advise me how to go about rectifying it.
'use strict';
var localStream;
var remoteStream;
var isInitiator;
var configuration =
iceServers: [
urls: 'stun:stun.l.google.com:19302'
]
;
var pc = new RTCPeerConnection(configuration);
// Define action buttons.
const callButton = document.getElementById('callButton');
const hangupButton = document.getElementById('hangupButton');
/////////////////////////////////////////////
window.room = prompt('Enter room name:');
var socket = io.connect();
if (room !== '')
console.log('Message from client: Asking to join room ' + room);
socket.emit('create or join', room);
socket.on('created', function(room)
console.log('Created room ' + room);
isInitiator = true;
startVideo();
);
socket.on('joined', function(room)
console.log('joined: ' + room);
startVideo();
);
socket.on('log', function(array)
console.log.apply(console, array);
);
////////////////////////////////////////////////
function sendMessage(message)
socket.emit('message', message);
// This client receives a message
socket.on('message', function(message)
if (message.type === 'offer')
pc.setRemoteDescription(message);
console.log('Sending answer to peer.');
pc.createAnswer().then(
setLocalAndSendMessage,
onCreateSessionDescriptionError
);
else if (message.type === 'answer')
console.log('This is to check if answer was returned');
remoteStream = event.stream;
remoteVideo.srcObject = remoteStream;
pc.setRemoteDescription(message);
else if (message.type === 'candidate')
pc.addIceCandidate(candidate);
);
////////////////////////////////////////////////////
const localVideo = document.querySelector('#localVideo');
const remoteVideo = document.querySelector('#remoteVideo');
// Set up initial action buttons status: disable call and hangup.
callButton.disabled = true;
hangupButton.disabled = true;
// Add click event handlers for buttons.
callButton.addEventListener('click', callStart);
hangupButton.addEventListener('click', hangupCall);
function startVideo()
navigator.mediaDevices
.getUserMedia(
audio: true,
video: true
)
.then(gotStream)
.catch(function(e)
alert('getUserMedia() error: ' + e.name);
);
function gotStream(stream)
localVideo.srcObject = stream;
localStream = stream;
callButton.disabled = false;
function callStart()
createPeerConnection();
callButton.disabled = true;
hangupButton.disabled = false;
if (isInitiator)
console.log('Sending offer to peer');
pc.createOffer(setLocalAndSendMessage, handleCreateOfferError);
/////////////////////////////////////////////////////////
function createPeerConnection()
try
pc.onicecandidate = ( candidate ) => sendMessage( candidate );
pc.ontrack = event =>
if (remoteVideo.srcObject) return;
remoteVideo.srcObject = event.stream;
;
console.log('Created RTCPeerConnnection');
catch (e)
console.log('Failed to create PeerConnection, exception: ' + e.message);
alert('Cannot create RTCPeerConnection object.');
return;
function handleCreateOfferError(event)
console.log('createOffer() error: ', event);
function setLocalAndSendMessage(sessionDescription)
console.log('setLocalAndSendMessage sending message', sessionDescription);
pc.setLocalDescription(sessionDescription);
sendMessage(sessionDescription);
function onCreateSessionDescriptionError(error)
console.log('Failed to create session description: ' + error.toString());
function hangupCall()
pc.close();
pc = null;
javascript socket.io webrtc stun
javascript socket.io webrtc stun
asked Nov 13 '18 at 19:55
Rj TngRj Tng
518
518
Look in web console:TypeError: event is undefined; can't access its "stream" property
in the lineremoteStream = event.stream;
– jib
Nov 13 '18 at 20:31
Also, inpc.ontrack
you wantremoteVideo.srcObject = event.streams[0];
notevent.stream
.
– jib
Nov 13 '18 at 20:32
candidate
is also undefined.
– jib
Nov 13 '18 at 20:34
I fixed the pc.ontrack and did some changes to how the video get pulled using stream.gettrack which is now causing more errorsTypeError: stream.getTracks is not a function. (In 'stream.getTracks()', 'stream.getTracks' is undefined)
– Rj Tng
Nov 14 '18 at 1:24
This is basic debugging. Do aconsole.log(stream)
to learn what thestream
variable holds. It is clearly not a MediaStream object.
– jib
Nov 14 '18 at 2:33
add a comment |
Look in web console:TypeError: event is undefined; can't access its "stream" property
in the lineremoteStream = event.stream;
– jib
Nov 13 '18 at 20:31
Also, inpc.ontrack
you wantremoteVideo.srcObject = event.streams[0];
notevent.stream
.
– jib
Nov 13 '18 at 20:32
candidate
is also undefined.
– jib
Nov 13 '18 at 20:34
I fixed the pc.ontrack and did some changes to how the video get pulled using stream.gettrack which is now causing more errorsTypeError: stream.getTracks is not a function. (In 'stream.getTracks()', 'stream.getTracks' is undefined)
– Rj Tng
Nov 14 '18 at 1:24
This is basic debugging. Do aconsole.log(stream)
to learn what thestream
variable holds. It is clearly not a MediaStream object.
– jib
Nov 14 '18 at 2:33
Look in web console:
TypeError: event is undefined; can't access its "stream" property
in the line remoteStream = event.stream;
– jib
Nov 13 '18 at 20:31
Look in web console:
TypeError: event is undefined; can't access its "stream" property
in the line remoteStream = event.stream;
– jib
Nov 13 '18 at 20:31
Also, in
pc.ontrack
you want remoteVideo.srcObject = event.streams[0];
not event.stream
.– jib
Nov 13 '18 at 20:32
Also, in
pc.ontrack
you want remoteVideo.srcObject = event.streams[0];
not event.stream
.– jib
Nov 13 '18 at 20:32
candidate
is also undefined.– jib
Nov 13 '18 at 20:34
candidate
is also undefined.– jib
Nov 13 '18 at 20:34
I fixed the pc.ontrack and did some changes to how the video get pulled using stream.gettrack which is now causing more errors
TypeError: stream.getTracks is not a function. (In 'stream.getTracks()', 'stream.getTracks' is undefined)
– Rj Tng
Nov 14 '18 at 1:24
I fixed the pc.ontrack and did some changes to how the video get pulled using stream.gettrack which is now causing more errors
TypeError: stream.getTracks is not a function. (In 'stream.getTracks()', 'stream.getTracks' is undefined)
– Rj Tng
Nov 14 '18 at 1:24
This is basic debugging. Do a
console.log(stream)
to learn what the stream
variable holds. It is clearly not a MediaStream object.– jib
Nov 14 '18 at 2:33
This is basic debugging. Do a
console.log(stream)
to learn what the stream
variable holds. It is clearly not a MediaStream object.– jib
Nov 14 '18 at 2:33
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288560%2fremote-video-stream-not-displaying%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288560%2fremote-video-stream-not-displaying%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Look in web console:
TypeError: event is undefined; can't access its "stream" property
in the lineremoteStream = event.stream;
– jib
Nov 13 '18 at 20:31
Also, in
pc.ontrack
you wantremoteVideo.srcObject = event.streams[0];
notevent.stream
.– jib
Nov 13 '18 at 20:32
candidate
is also undefined.– jib
Nov 13 '18 at 20:34
I fixed the pc.ontrack and did some changes to how the video get pulled using stream.gettrack which is now causing more errors
TypeError: stream.getTracks is not a function. (In 'stream.getTracks()', 'stream.getTracks' is undefined)
– Rj Tng
Nov 14 '18 at 1:24
This is basic debugging. Do a
console.log(stream)
to learn what thestream
variable holds. It is clearly not a MediaStream object.– jib
Nov 14 '18 at 2:33