(connection)
| 2 | let messageIdx = 0; |
| 3 | |
| 4 | function addConnection(connection) { |
| 5 | connection.connectionId = ++connectionIdx; |
| 6 | addMessage('New connection #' + connectionIdx); |
| 7 | |
| 8 | connection.addEventListener('message', function(event) { |
| 9 | messageIdx++; |
| 10 | const data = JSON.parse(event.data); |
| 11 | const logString = 'Message ' + messageIdx + ' from connection #' + |
| 12 | connection.connectionId + ': ' + data.message; |
| 13 | addMessage(logString, data.lang); |
| 14 | maybeSetFruit(data.message); |
| 15 | connection.send('Received message ' + messageIdx); |
| 16 | }); |
| 17 | |
| 18 | connection.addEventListener('close', function(event) { |
| 19 | addMessage('Connection #' + connection.connectionId + ' closed, reason = ' + |
| 20 | event.reason + ', message = ' + event.message); |
| 21 | }); |
| 22 | }; |
| 23 | |
| 24 | /* Utils */ |
| 25 |
no test coverage detected