spreadcast
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "spreadcast", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Broadcast a WebRTC stream to many subscribers", | ||
@@ -5,0 +5,0 @@ "main": "src/spreadcast.js", |
var _ = require('eakwell'); | ||
var Client = function(options) { | ||
var Client = function(container) { | ||
var self = this; | ||
@@ -49,2 +49,4 @@ | ||
var data = JSON.parse(event.data); | ||
if(!data._spreadcast) return; | ||
switch(data.type) { | ||
@@ -107,2 +109,3 @@ case 'offer': | ||
sockReady.then(function() { | ||
data._spreadcast = true; | ||
socket.send(JSON.stringify(data)); | ||
@@ -115,3 +118,3 @@ }); | ||
video.autoplay = true; | ||
options.container.appendChild(video); | ||
container.appendChild(video); | ||
return video; | ||
@@ -130,3 +133,3 @@ }; | ||
.then(function(stream) { | ||
localVideo = createVideoElement(); | ||
localVideo = localVideo || createVideoElement(); | ||
localVideo.muted = true; | ||
@@ -141,3 +144,3 @@ localVideo.srcObject = stream; | ||
var stop = function() { | ||
var terminate = function() { | ||
if(senderPeer) senderPeer.close(); | ||
@@ -157,10 +160,16 @@ senderPeer = null; | ||
} | ||
if(remoteVideo) remoteVideo.parentElement.removeChild(remoteVideo); | ||
if(localVideo) localVideo.parentElement.removeChild(localVideo); | ||
}; | ||
var reconnect = function() { | ||
stop(); | ||
terminate(); | ||
self.receive(roomName); | ||
}; | ||
var stop = function() { | ||
terminate(); | ||
if(remoteVideo) remoteVideo.parentElement.removeChild(remoteVideo); | ||
if(localVideo) localVideo.parentElement.removeChild(localVideo); | ||
localVideo = null; | ||
remoteVideo = null; | ||
}; | ||
@@ -183,3 +192,3 @@ self.publish = function(name, constraints) { | ||
senderPeer.onaddstream = function(e) { | ||
remoteVideo = createVideoElement(); | ||
remoteVideo = remoteVideo || createVideoElement(); | ||
remoteVideo.srcObject = e.stream; | ||
@@ -186,0 +195,0 @@ remoteStream = e.stream; |
@@ -8,3 +8,3 @@ var _ = require('eakwell'); | ||
var pingInterval = 10 * 1000; | ||
var maxLeechers = options.maxLeechers || 1; | ||
var maxLeechers = options.maxLeechers || 3; | ||
@@ -16,8 +16,6 @@ var closeRoom = function(roomName) { | ||
_.each(room.receivers, function(receiver) { | ||
try { | ||
send(receiver.socket, { | ||
type: 'stop', | ||
roomName: roomName | ||
}); | ||
} catch(e) {} | ||
send(receiver.socket, { | ||
type: 'stop', | ||
roomName: roomName | ||
}); | ||
}); | ||
@@ -35,2 +33,4 @@ }; | ||
var data = JSON.parse(msg); | ||
if(!data._spreadcast) return; | ||
console.log(data); | ||
@@ -147,3 +147,6 @@ | ||
var send = function(socket, data) { | ||
socket.send(JSON.stringify(data)); | ||
try { | ||
data._spreadcast = true; | ||
socket.send(JSON.stringify(data)); | ||
} catch(e) {} | ||
}; | ||
@@ -150,0 +153,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13319
349