add: broadcast socket id for user sockets
This commit is contained in:
parent
ecde5d3d46
commit
1724f798ca
6 changed files with 48 additions and 16 deletions
|
@ -12,6 +12,14 @@
|
|||
return $.STREAMS[stream];
|
||||
});
|
||||
|
||||
self.define("get", ({ $ }, id) => {
|
||||
for (const stream of Object.values($.STREAMS)) {
|
||||
if (stream.id === id) {
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
self.define("subscribe", ({ $ }, stream) => {
|
||||
if (!$.USER) {
|
||||
console.warn("cannot subscribe without user id");
|
||||
|
@ -27,6 +35,7 @@
|
|||
const socket = new WebSocket(endpoint);
|
||||
|
||||
$.STREAMS[stream] = {
|
||||
id: null,
|
||||
socket,
|
||||
events: {
|
||||
message: () => {},
|
||||
|
@ -38,10 +47,17 @@
|
|||
return socket.send("Pong");
|
||||
}
|
||||
|
||||
return $.sock(stream).events.message(event.data);
|
||||
const data = JSON.parse(event.data);
|
||||
|
||||
if (data.method.Forward === "Key") {
|
||||
$.STREAMS[stream].id = data.data;
|
||||
return console.info(`${stream} ${data.data}`);
|
||||
}
|
||||
|
||||
return $.sock(stream).events.message(data);
|
||||
});
|
||||
|
||||
return socket;
|
||||
return $.STREAMS[stream];
|
||||
});
|
||||
|
||||
self.define("close", ({ $ }, stream) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue