parent
1b8244c8d7
commit
e8d1fec9b6
8 changed files with 101 additions and 125 deletions
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
@ -1,39 +0,0 @@ |
||||
const Icons = { |
||||
comet: (color) => { |
||||
// const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
||||
// star.setAttribute("viewBox", '0 0 100 100');
|
||||
|
||||
// const path = document.createElementNS("http://www.w3.org/2000/svg", 'path');
|
||||
|
||||
const obj = document.getElementById('TEST_OBJECT_SVG'); |
||||
|
||||
console.log(obj); |
||||
console.log(obj.contentDocument) |
||||
|
||||
return obj; |
||||
}, |
||||
|
||||
moon: (color) => { |
||||
|
||||
}, |
||||
|
||||
planet: (color) => { |
||||
|
||||
}, |
||||
|
||||
rocket: (color) => { |
||||
|
||||
}, |
||||
|
||||
spacesuit: (color) => { |
||||
|
||||
}, |
||||
|
||||
spider: (color) => { |
||||
|
||||
}, |
||||
|
||||
ufo: (color) => { |
||||
|
||||
}, |
||||
}; |
@ -1,35 +1,46 @@ |
||||
const WebSocket = require('ws'); |
||||
const DEBUG = (process.env.NODE_ENV !== "production"); |
||||
|
||||
const Messenger = { |
||||
messageOne: (ws, message) => {
|
||||
DEBUG && console.log(`Sending to only ${ws.id}:`); |
||||
DEBUG && console.log(message); |
||||
|
||||
ws.send(JSON.stringify(message)); |
||||
}, |
||||
|
||||
messageOthers: (ws, message) => {
|
||||
DEBUG && console.log(`Sending to other client(s):`); |
||||
DEBUG && console.log(message); |
||||
|
||||
wss.clients.forEach((client) => { |
||||
if (client !== ws && client.readyState === WebSocket.OPEN) { |
||||
client.send(JSON.stringify(message)); |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
messageAll: (message) => {
|
||||
DEBUG && console.log(`Sending to all ${wss.clients.size} client(s):`); |
||||
DEBUG && console.log(message); |
||||
|
||||
wss.clients.forEach((client) => { |
||||
if (client.readyState === WebSocket.OPEN) { |
||||
client.send(JSON.stringify(message)); |
||||
} |
||||
}); |
||||
}, |
||||
const Messenger = function() { |
||||
this.clients = {}; |
||||
}; |
||||
|
||||
Messenger.prototype.messageOne = function(ws, message) {
|
||||
DEBUG && console.log(`Sending to only ${ws.id}:`); |
||||
DEBUG && console.log(message); |
||||
|
||||
ws.send(JSON.stringify(message)); |
||||
}; |
||||
|
||||
Messenger.prototype.messageOthers = function(ws, message) {
|
||||
DEBUG && console.log(`Sending to other client(s):`); |
||||
DEBUG && console.log(message); |
||||
|
||||
Object.values(this.clients).forEach((client) => { |
||||
if (client !== ws && client.readyState === WebSocket.OPEN) { |
||||
client.send(JSON.stringify(message)); |
||||
} |
||||
}); |
||||
}; |
||||
|
||||
Messenger.prototype.messageAll = function(message) {
|
||||
DEBUG && console.log(`Sending to all ${wss.clients.size} client(s):`); |
||||
DEBUG && console.log(message); |
||||
|
||||
Object.values(this.clients).forEach((client) => { |
||||
if (client.readyState === WebSocket.OPEN) { |
||||
client.send(JSON.stringify(message)); |
||||
} |
||||
}); |
||||
}; |
||||
|
||||
Messenger.prototype.subscribe = function(ws) { |
||||
this.clients[ws.id] = ws; |
||||
}; |
||||
|
||||
Messenger.prototype.unsubscribe = function(ws) { |
||||
delete this.clients[ws.id]; |
||||
}; |
||||
|
||||
|
||||
module.exports = Messenger; |
Loading…
Reference in new issue