webrtc-swarm
Advanced tools
Comparing version 2.2.0 to 2.3.0
20
index.js
@@ -10,6 +10,8 @@ var SimplePeer = require('simple-peer') | ||
if (!opts) opts = {} | ||
var wrap = opts.wrap || function (data) { return data } | ||
var unwrap = opts.unwrap || function (data) { return data } | ||
var swarm = new events.EventEmitter() | ||
var remotes = {} | ||
var me = cuid() | ||
var me = opts.uuid || cuid() | ||
debug('my uuid:', me) | ||
@@ -42,3 +44,5 @@ | ||
sending = true | ||
hub.broadcast(id, {from: me, signal: signals.shift()}, function () { | ||
var data = {from: me, signal: signals.shift()} | ||
data = wrap(data, id) | ||
hub.broadcast(id, data, function () { | ||
sending = false | ||
@@ -59,2 +63,5 @@ kick() | ||
hub.subscribe('all').pipe(through.obj(function (data, enc, cb) { | ||
data = unwrap(data, 'all') | ||
if (!data) return cb() | ||
debug('/all', data) | ||
@@ -76,3 +83,3 @@ if (data.from === me) { | ||
debug('connecting to new peer (as initiator)', data.from ) | ||
debug('connecting to new peer (as initiator)', data.from) | ||
var peer = new SimplePeer({ | ||
@@ -93,3 +100,5 @@ wrtc: opts.wrtc, | ||
if (swarm.peers.length >= swarm.maxPeers) return | ||
hub.broadcast('all', {type: 'connect', from: me}, function () { | ||
var data = {type: 'connect', from: me} | ||
data = wrap(data, 'all') | ||
hub.broadcast('all', data, function () { | ||
setTimeout(connect, Math.floor(Math.random() * 2000) + (swarm.peers.length ? 13000 : 3000)) | ||
@@ -100,2 +109,5 @@ }) | ||
hub.subscribe(me).once('open', connect).pipe(through.obj(function (data, enc, cb) { | ||
data = unwrap(data, me) | ||
if (!data) return cb() | ||
var peer = remotes[data.from] | ||
@@ -102,0 +114,0 @@ if (!peer) { |
{ | ||
"name": "webrtc-swarm", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Create a swarm of p2p connections using webrtc and a signalhub", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
6290
120