app.js: wss.broadcast = function broadcast(data) { wss.clients.forEach(function(client) { client.send(data); }); };
function each(Client) 这个 each 可以省略掉
app.js function onConnect() { let user = this.user; let msg = createMessage('join', user, ${user.name} joined.); this.wss.broadcast(msg); // build user list: let users = this.wss.clients.map(function (client) { return client.user; }); //this.wss.broadcast(createMessage('list', user, users)); this.send(createMessage('list', user, users)); }
${user.name} joined.
下面这2句是相等的 this.wss.broadcast(createMessage('list', user, users)); this.send(createMessage('list', user, users));
Sign in to make a reply
深圳邦道营销管理咨询公司
app.js: wss.broadcast = function broadcast(data) { wss.clients.forEach(function(client) { client.send(data); }); };
app.js function onConnect() { let user = this.user; let msg = createMessage('join', user,
${user.name} joined.
); this.wss.broadcast(msg); // build user list: let users = this.wss.clients.map(function (client) { return client.user; }); //this.wss.broadcast(createMessage('list', user, users)); this.send(createMessage('list', user, users)); }下面这2句是相等的 this.wss.broadcast(createMessage('list', user, users)); this.send(createMessage('list', user, users));