Commit 829ee179 authored by nanahira's avatar nanahira

fix roomlist broadcast

parent 4ac3f97b
Pipeline #17710 passed with stages
in 11 minutes and 57 seconds
......@@ -12,6 +12,8 @@ room_data = (room)->
options: room.get_roomlist_hostinfo(), # Should be updated when MyCard client updates
arena: settings.modules.arena_mode.enabled && room.arena && settings.modules.arena_mode.mode
clients = new Set()
init = (http_server, ROOM_all)->
server = new WebSocketServer
server: http_server
......@@ -21,6 +23,8 @@ init = (http_server, ROOM_all)->
connection.send JSON.stringify
event: 'init'
data: room_data(room) for room in ROOM_all when room and room.established and (connection.filter == 'started' or !room.private) and ((room.duel_stage != 0) == (connection.filter == 'started'))
clients.add connection
connection.on('close', () -> clients.delete connection if clients.has connection)
create = (room)->
broadcast('create', room_data(room), 'waiting') if !room.private
......@@ -43,7 +47,7 @@ broadcast = (event, data, filter)->
message = JSON.stringify
event: event
data: data
for connection in server.clients when connection.filter == filter
for connection in Array.from(clients.values()) when connection.filter == filter
try
connection.send message
......
// Generated by CoffeeScript 2.6.1
(function() {
var WebSocketServer, _delete, broadcast, create, init, room_data, server, settings, start, update, url;
var WebSocketServer, _delete, broadcast, clients, create, init, room_data, server, settings, start, update, url;
WebSocketServer = require('ws').Server;
......@@ -36,6 +36,8 @@
};
};
clients = new Set();
init = function(http_server, ROOM_all) {
server = new WebSocketServer({
server: http_server
......@@ -43,7 +45,7 @@
return server.on('connection', function(connection, upgradeReq) {
var room;
connection.filter = url.parse(upgradeReq.url, true).query.filter || 'waiting';
return connection.send(JSON.stringify({
connection.send(JSON.stringify({
event: 'init',
data: (function() {
var i, len, results;
......@@ -57,6 +59,12 @@
return results;
})()
}));
clients.add(connection);
return connection.on('close', function() {
if (clients.has(connection)) {
return clients.delete(connection);
}
});
});
};
......@@ -98,7 +106,7 @@
event: event,
data: data
});
ref = server.clients;
ref = Array.from(clients.values());
results = [];
for (i = 0, len = ref.length; i < len; i++) {
connection = ref[i];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment