Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aff1694

Browse files
committed
Add mock server
1 parent 4ca970c commit aff1694

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

radar/socketserver/mock.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const WebSocket = require('ws')
2+
3+
const wss = new WebSocket.Server({ port: 9999 })
4+
5+
function* gen() {
6+
let angle = 0
7+
while (angle <= 180) {
8+
yield { angle, distance: Math.floor(Math.random() * 30) }
9+
angle++
10+
}
11+
yield* gen()
12+
}
13+
14+
wss.on('connection', function connection(ws) {
15+
16+
const data = gen()
17+
18+
setInterval(() => {
19+
ws.send(JSON.stringify(data.next().value))
20+
}, 20)
21+
22+
})

0 commit comments

Comments
 (0)