js. 現在、私はいくつかのテストを成功させました
- こんにちは世界
- イベントによるサーバーとクライアントの通信
- 多くの部屋
しかし、クライアントをクライアントに送信することはできません。socket.ioを使用します。
私がこれをしたい理由は、現在のクライアントのリストを持つことです
編集:
サーバー側に各ユーザーの情報を保存する必要があります
使ってみます
var io = require('socket.io');
var socket = io.listen(9876);
socket.on('connection', function(client) {
client.join('room');
console.log('new client ' + client.toString());
client.in('room').emit('list', client ); //<-- Error here
client.on('message', function(event) {
console.log('client message! ', event);
client.send(event);
});
client.on('chat', function(data) {
client.broadcast.in('room').emit('LDS', data);
client.in('room').emit('LDS', data);
});
client.on('disconnect', function() {
console.log('out');
});
});
しかし、このエラーをスローします
connections property is deprecated. Use getConnections() method
C:\Repos\InWeb\NO\node_modules\socket.io\lib\parser.js:75
data = JSON.stringify(ev);
^
TypeError: Converting circular structure to JSON
at Object.stringify (native)
元のアイデアは、このようにクライアントのリストを送信することです
var listClients;
socket.on('connection', function(client) {
client.join('room');
listClients.push(client);
client.in('room').emit('list', listClients); //<-- But throws same error
クライアントコンテキストによってエラーが発生したと思います
私はそれを修正することができますか?