You've already forked obsidian-visualiser
Campaign sheet start
This commit is contained in:
@@ -1,22 +1,30 @@
|
||||
const TRIGGER_CHAR = {
|
||||
PING: String.fromCharCode(0x02),
|
||||
PONG: String.fromCharCode(0x03),
|
||||
STATUS: String.fromCharCode(0x04),
|
||||
};
|
||||
|
||||
export default defineWebSocketHandler({
|
||||
message(peer, message) {
|
||||
|
||||
switch(message.rawData)
|
||||
{
|
||||
case TRIGGER_CHAR.PING:
|
||||
peer.send(TRIGGER_CHAR.PONG);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
},
|
||||
open(peer) {
|
||||
const id = new URL(peer.request.url).pathname.split('/').slice(-1)[0];
|
||||
if(!id) return peer.close();
|
||||
peer.subscribe(`campaigns/${id}`);
|
||||
peer.publish(`campaigns/${id}`, true);
|
||||
|
||||
|
||||
peer.publish(`campaigns/${id}`, `${TRIGGER_CHAR.STATUS}`);
|
||||
},
|
||||
close(peer, details) {
|
||||
const id = new URL(peer.request.url).pathname.split('/').slice(-1)[0];
|
||||
if(!id) return peer.close();
|
||||
peer.publish(`campaigns/${id}`, false);
|
||||
peer.unsubscribe(`campaigns/${id}`);
|
||||
},
|
||||
error(peer, error) {
|
||||
console.error(error);
|
||||
}
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user