I made an application to send live audio with Socket.io. The problem is that it only works between tabs in the same Chrome window. When I try to send or receive audio from another PC or even from another window, this error appears:
GET blob:https://server/ce74cfe7-bb9c-40b0-9cb0-1138b22b1b11 404 (Not Found)
This is the code in main.js (of the page):
$(document).ready(function(){
var socket = io("https://server:4000", verify=false);
socket.on('audio stream', function(blob){
var video = document.querySelector('video');
video.src = blob;
});
$('#ptt').click(function(){
micOn();
document.getElementById("ptt").disabled = true;
document.getElementById("ptt-off").disabled = false;
});
$('#ptt-off').click(function(){
stream.getAudioTracks()[0].stop();
document.getElementById("ptt").disabled = false;
document.getElementById("ptt-off").disabled = true;
});
function micOn(){
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
var constraints = {
audio: true,
video: false
};
var video = document.querySelector('video');
function successCallback(stream) {
window.stream = stream; // stream available to console
var blob = window.URL.createObjectURL(stream);
socket.emit('audio stream', myName, blob);
}
function errorCallback(error) {
console.log('navigator.getUserMedia error: ', error);
}
navigator.getUserMedia(constraints, successCallback, errorCallback);
}
});
This is the code on the server (index.js):
socket.on('audio stream', function(blob){
socket.broadcast.emit('audio stream', blob);
});