set and subcribe handler added
This commit is contained in:
parent
6954969e6e
commit
f5e0ac2cbe
13
lib/ws.js
13
lib/ws.js
@ -5,9 +5,8 @@ let connections = [];
|
|||||||
|
|
||||||
export function init(cfg, db) {
|
export function init(cfg, db) {
|
||||||
wss = new WebSocketServer(cfg);
|
wss = new WebSocketServer(cfg);
|
||||||
console.log(cfg);
|
|
||||||
wss.on('connection', ws => {
|
wss.on('connection', ws => {
|
||||||
console.log('new connection')
|
|
||||||
connections.push(ws);
|
connections.push(ws);
|
||||||
|
|
||||||
ws.on('error', console.error);
|
ws.on('error', console.error);
|
||||||
@ -20,8 +19,18 @@ export function init(cfg, db) {
|
|||||||
|
|
||||||
switch (message.action) {
|
switch (message.action) {
|
||||||
case "set":
|
case "set":
|
||||||
|
db.persist(
|
||||||
|
message.subject,
|
||||||
|
message.filter,
|
||||||
|
message.field,
|
||||||
|
message.value
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "subscribe":
|
case "subscribe":
|
||||||
|
db.subscribe(
|
||||||
|
message.subject,
|
||||||
|
message.filter
|
||||||
|
).then(r => ws.send(r));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw 'invalid action "' + message.action + '"';
|
throw 'invalid action "' + message.action + '"';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user