-
Notifications
You must be signed in to change notification settings - Fork 5
/
local_server.js
46 lines (37 loc) · 1007 Bytes
/
local_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
const express = require('express')
const app = express()
var bodyParser = require('body-parser');
app.use(bodyParser.json());
var expressWs = require('express-ws')(app);
var fs = require('fs');
var socket;
var answer;
app.use(express.static('static'));
app.post('/skill',function(request,response){
var offer = {}
offer.type = 'offer'
offer.sdp = request.body.value
socket.send(JSON.stringify(offer));
setTimeout(function() {
response.send(answer);
answer = null;
}, 2000);
});
app.post('/event',function(request,response){
console.log(request.body)
var resp = {}
resp.status = "ok"
response.send(resp);
});
app.ws('/socket', function(ws, req) {
console.log("Websocket Connected");
socket = ws;
ws.on('message', function(msg) {
console.log("Message Recieved");
answer = JSON.parse(msg);
});
ws.on('close', function(ws){
console.log("Websocket Closed");
});
});
app.listen(8000, () => console.log('App listening on port 8000!'))