-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
40 lines (33 loc) · 861 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var Overlay = require('./lib/overlay')
var hat = require('hat')
var ID_BITS = 160
var id = hat(ID_BITS)
console.log('my id:', id)
var overlay
if (typeof window === 'undefined') {
overlay = new Overlay(id, 8085, [])
}
else {
overlay = new Overlay(id, null, ['ws://localhost:8085'])
window.overlay = overlay
}
overlay.on('stream', function (id, name, str) {
console.log('incoming stream from node with id:', id, 'name:', name)
global.stream = str
str.on('data', function (data) {
console.log(id + ':', data.toString())
})
})
global.createStream = function (id, name) {
console.log('outgoing stream with id:', id)
overlay.openStream(id, name, {}, function (err, strs) {
if (err) {
return console.error(err)
}
var str = strs[0]
global.stream = str
str.on('data', function (data) {
console.log(id + ':', data.toString())
})
})
}