最終更新:2020-04-15 (水) 21:43:51 (1465d)  

Socket.IO/クライアント
Top / Socket.IO / クライアント

https://socket.io/docs/client-api/

https://github.com/socketio/socket.io-client

<script src="/socket.io/socket.io.js"></script>

exports

  • exports.protocol?
  • exports.connect? -> lookup?([url][, options])
  • exports.Manager? =
  • exports.Socket?

io

  • 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/クラス

再接続

  • new Manager(url[, options])
    reconnectiontruewhether to reconnect automatically
    reconnectionAttemptsInfinitynumber of reconnection attempts before giving up
    reconnectionDelay1000how 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?5000maximum amount of time to wait between reconnections (5000). Each attempt increases the reconnection delay by 2x along with a randomization as above
    randomizationFactor0.50 <= randomizationFactor <= 1
    autoConnecttrueby 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);
// }

}}