26 | "readme": "# What it does\r\n\r\n###### Ability to create room variables for people that use socket.io. It was kind of strange to see that there was no room variable solution for socket.io out of the box. ######\r\n\r\n\r\n# How does it look?\r\n\r\n\tvar roomdata = require('roomdata'),\r\n\tio.sockets.on('connection', function (socket) {\r\n\t\t// Lets join/create a room:\r\n\t\troomdata.joinRoom(socket, \"testroom\"); // You do not have to create a room before joining it\r\n\t\t\r\n\t\t// You can define room variables:\r\n\t\troomdata.set(socket, \"gamedata\", {x:4, y:20}); // Creates a room variable\r\n\t\troomdata.set(socket, \"timesdied\", 5); // Can also be a number,string,boolean etc\r\n\t\t\r\n\t\t// Then on every socket that has joined the same room you can retrieve the values:\r\n\t\tconsole.log(roomdata.get(socket, \"gamedata\")); // Prints: { x: 4, y: 20 }\r\n\t\tconsole.log(roomdata.get(socket, \"gamedata\").y); // Prints: 20\r\n\t\t\r\n\t\t// Incrementing timesdied\r\n\t\tvar inc = roomdata.get(socket, \"timesdied\") + 10;\r\n\t\troomdata.set(socket, \"timesdied\", inc);\r\n\t\tconsole.log(roomdata.get(socket, \"timesdied\")); // Prints: 15\r\n\t\t\r\n\t\t// Standard variables when a room is created:\r\n\t\tconsole.log(roomdata.get(socket, \"users\")); // Prints: array full of current users in room (socket.id)\r\n\t\tconsole.log(roomdata.get(socket, \"room\")); // Prints: current room name this socket is in\r\n\t\tconsole.log(roomdata.get(socket, \"owner\")); // Prints: the socket.id that created the room\r\n\t\t\r\n\t\t// Important: It is not yet possible to use get and set if a socket is in two rooms at once!\r\n\t\t\r\n\t\t// Make sure to define a on disconnect handler and call roomdata.leaveRoom with the socket as parameter or roomdata.get(socket, \"users\") will not function well!\r\n\t\tsocket.on('disconnect', function() {\r\n\t\t\troomdata.leaveRoom(socket);\r\n\t\t});\r\n\t});\r\n![Example1](http://s14.postimg.org/7j43w0b81/roomdata1.png)\r\n\r\n\r\n# How do I use it?\r\n\r\n## 1. Start by installing the package:\r\n npm install roomdata\r\n\r\n## 2. Put this in your nodejs server file:\r\n\r\n var roomdata = require('roomdata');\r\n\t\r\n## 3. Now you can do stuff like:\r\n\r\n roomdata.joinRoom(socket, \"testroom\");\r\n\t\r\n\troomdata.set(socket, \"gamedata\", {x:4, y:20});\r\n\t\r\n\tconsole.log(roomdata.get(socket, \"gamedata\")); // Prints: { x: 4, y: 20 }\r\n\tconsole.log(roomdata.get(socket, \"gamedata\").y); // Prints: 20\r\n\t\r\n## 4. Make sure to define a disconnect handler and call roomdata.leaveRoom with socket as parameter\r\n \r\n socket.on('disconnect', function() {\r\n\t\troomdata.leaveRoom(socket);\r\n\t});\r\n\t\r\n# Contact\r\n You can contact me at specamps@gmail.com\r\n\r\n\t\r\n",
|