-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserver.js
94 lines (74 loc) · 2.3 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var http=require("http")
var os=require("os")
var netInt=os.networkInterfaces()
var fs=require("fs")
var streamer=require("./streamer.js")
//var WebSocket=require("ws")
var server=http.createServer(function(req,res){
console.log("==>new connection: "+req.connection.remoteAddress+", url: "+req.url)
//res.end("Hi from Raspberry!")
var filename=req.url=="/"?"/index.html":req.url
var method=req.method.toLowerCase()
//console.log("==>method: "+method)
if(method=="get"&&req.url!="/videostream.mp4"){
var file=fs.createReadStream("www"+filename)
file.on("error",function(err){
console.log("Can't open file, err: "+err)
})
file.pipe(res)
}//if no videostream
else if(method=="get"&&req.url=="/videostream.mp4"){
console.log("==>video stream request....")
}//videostream
}).listen(8080)
var stream
//socket.io
var io = require('socket.io')(server)
io.on('connection', function (socket) {
socket.emit('data', { data: 'Hi from server' })
socket.on('data', function (data) {
console.log(data);
})
socket.on("start_stream",function(data){
console.log("==>start_stream")
startStream(socket)
})//start stream
socket.on("stop_stream",function(data){
console.log("==>stop_stream")
stopStream()
})//start stream
})//io
function startStream(socket){
console.log("==>starting stream...")
stream=new streamer.start(socket)
}//startStream
function stopStream(socket){
console.log("==>stoping stream...")
try{
stream.kill()
}catch(err){console.log(err)}
}//startStream
//websocket
//var wsServer=new WebSocket.Server({server})//{port:8081}
// wsServer.on("connection",function(ws){
// console.log("==>new ws client: ")
// ws.on("message",function(data){
// console.log("==>new ws message: "+data.toString())
// //ff_stream=new ffmpeg.start(wsServer)
// var j_data=JSON.parse(data.toString())
// if(j_data.action=="start_video"){
// console.log("==>starting video")
// ff_stream=new ffmpeg.start(wsServer)
// }//start video
// if(j_data.action=="stop_video"){
// console.log("==>stoping video")
// try{ff_stream.kill()}
// catch(e){console.log(e)}
// }//start video
// })//
// ws.on("close",function(){
// console.log("==>ws client closed: ")
// })//
// })//cconected socked
console.log("Server started from smb!")
console.log(netInt)