最終更新:2020-04-15 (水) 21:43:51 (1433d)
Socket.IO/クライアント
https://socket.io/docs/client-api/
https://github.com/socketio/socket.io-client
<script src="/socket.io/socket.io.js"></script>
exports
- https://github.com/socketio/socket.io-client/blob/master/dist/socket.io.dev.js
- io([url][, options]) = module.exports = exports = lookup?([url][, options]) = io.connect([url][, options])
- lookup(uri, opts)
- io = io.Manager
- return io.socket?
io
- io([url][, options]) = module.exports = exports = lookup?([url][, options]) = io.connect([url][, options])
- io.connect = lookup([url][, options])
- defaults to trying to connect to the host that serves the page.
- if (null == uri) uri = loc.protocol + '//' + loc.host;
socket
- socket = io() = io.connect() = io.Manager.socket? = io.socket?
Socket.IO/クラス
再接続
- new Manager(url[, options])
reconnection true whether to reconnect automatically reconnectionAttempts Infinity number of reconnection attempts before giving up reconnectionDelay 1000 how long to initially wait before attempting a new reconnection (1000). Affected by +/- randomizationFactor, for example the default initial delay will be between 500 to 1500ms. reconnectionDelayMax? 5000 maximum amount of time to wait between reconnections (5000). Each attempt increases the reconnection delay by 2x along with a randomization as above randomizationFactor 0.5 0 <= randomizationFactor <= 1 autoConnect true by setting this false, you have to call manager.open whenever you decide it’s appropriate
バインディング
取得
//not working // var usersInRoom = io.of('/').in(room).clients; // console.dir(usersInRoom); //not working // var clients = io.of('/').clients(room); // all users from room `room` // console.dir(clients); // //working for id io.of('/').in(room).clients(function(error, clients){ for(var id of clients){ var c = io.of('/').connected[id]; } }); //worked for id // var clients = io.nsps['/'].adapter.rooms[room].sockets; // for(client in clients){ // console.dir(client); // }
}}