-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
49 lines (34 loc) · 915 Bytes
/
server.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
41
42
43
44
45
46
47
48
"use strict";
var fs = require('fs')
var connect = require('connect')
var goProHlsUrl = 'http://10.5.5.9:8080/live/amba.m3u8'
var video = require('./hls-stream')(goProHlsUrl)
var template = fs.readFileSync('./gopro.m3u8')
var indexHtml = fs.readFileSync('./index.html')
var app = connect()
.use(connect.logger({ format: 'dev' }))
.use('/gopro.m3u8', function(req, res) {
var pls = template
.toString()
.replace(/__sequence/g, Date.now())
res.writeHead(200, {
'Content-Type': 'application/vnd.apple.mpegurl',
'Content-Length': pls.length
})
res.end(pls)
})
.use('/gopro.ts', function(req, res) {
res.writeHead(200, {
'Content-Type': 'video/ts'
})
video.pipe(res)
})
.use('/', function(req, res) {
res.writeHead(200, {
'Content-Type': 'text/html',
'Content-Length': indexHtml.length
})
res.end(indexHtml);
})
.use(connect.errorHandler())
.listen(8000)