-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
index.js
33 lines (29 loc) · 1019 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
var peerflix = require('peerflix')
var network = require('network-address')
var player = require('chromecast-player');
process.on('SIGINT', function() {
// we're doing some heavy lifting so it can take some time to exit... let's
// better output a status message so the user knows we're working on it :)
console.log('\nPeercast is exiting...')
process.exit()
})
module.exports = function(torrent, opts) {
if (!opts) opts = {}
var engine = peerflix(torrent, opts)
engine.server.on('listening', function() {
var addr = 'http://'+network()+':'+engine.server.address().port
player({
path: addr,
type: opts.type || 'video/mp4',
metadata: { title: engine.server.index.name }
}, function(err, p) {
if (err) return engine.emit('error', err)
p.on('status', function(status) {
engine.emit('chromecast-status', status)
})
engine.emit('chromecast-player', p)
engine.emit('chromecast-playing', engine.server.index)
});
})
return engine
}