Make it work on Firefox

This commit is contained in:
Jerko Steiner 2016-04-24 10:37:30 -04:00
parent 537b67b1e1
commit 3b95107bbc
5 changed files with 27 additions and 29 deletions

View File

@ -1,3 +1,4 @@
const Promise = require('bluebird');
const debug = require('debug')('peer-calls:call');
const dispatcher = require('./dispatcher/dispatcher.js');
const getUserMedia = require('./browser/getUserMedia.js');
@ -13,37 +14,40 @@ dispatcher.register(action => {
function init() {
const callId = window.document.getElementById('callId').value;
getUserMedia({ video: true, audio: false })
Promise.all([connect(), getCameraStream()])
.spread((_socket, stream) => {
debug('initializing peer connection');
handshake.init(_socket, callId, stream);
});
}
function connect() {
return new Promise(resolve => {
socket.once('connect', () => {
notify.warn('Connected to server socket');
debug('socket connected');
resolve(socket);
});
socket.on('disconnect', () => {
notify.error('Server socket disconnected');
});
});
}
function getCameraStream() {
return getUserMedia({ video: true, audio: false })
.then(stream => {
debug('got our media stream:', stream);
dispatcher.dispatch({
type: 'add-stream',
userId: '_me_',
stream
});
return stream;
})
.catch(() => {
notify.alert('Could not get access to microphone & camera');
});
socket.once('connect', () => {
notify.warn('Connected to server socket');
debug('socket connected');
getUserMedia({ video: true, audio: true })
.then(stream => {
debug('forwarding stream to handshake');
handshake.init(socket, callId, stream);
})
.catch(err => {
notify.alert('Could not get access to camera!', true);
debug('error getting media: %s %s', err.name, err.message);
});
});
socket.on('disconnect', () => {
notify.error('Server socket disconnected');
});
}
module.exports = { init };

View File

@ -29,10 +29,6 @@ function create({ socket, user, initiator, stream }) {
iceServers: [{
url: 'stun:23.21.150.121',
urls: 'stun:23.21.150.121'
}, {
url: 'turn:numb.viagenie.ca',
credential: 'muazkh',
username: 'webrtc@live.com'
}]
}
});

View File

@ -40,8 +40,6 @@ if (__dirname.indexOf('/dist/') >= 0 || __dirname.indexOf('\\dist\\') >= 0) {
app.use('/call', callRouter);
app.use('/', siteRouter);
io.on('connection', socket => handleSocket(socket, io));
module.exports = { http, app };

View File

@ -10,7 +10,7 @@ router.use((req, res, next) => {
router.get('/', (req, res) => {
let prefix = 'call/';
if (req.url.charAt(req.url.length - 1) === '/') prefix = '';
if (req.url.charAt(req.originalUrl.length - 1) === '/') prefix = '';
res.redirect(prefix + uuid.v4());
});

View File

@ -16,7 +16,7 @@ html
div#container
form#form(method="get" action="call")
form#form(method="get" action="call/")
h1
img(src="res/peer-calls.svg" width="100%" alt="Peer Calls")
p Group peer-to-peer calls for everyone. Create a private room. Share the link.