{"id":16994693,"url":"https://github.com/ehzhang/nunchuck","last_synced_at":"2025-06-12T13:36:02.250Z","repository":{"id":19318150,"uuid":"22556314","full_name":"ehzhang/nunchuck","owner":"ehzhang","description":"📲 multi-device hardware data synchronization for mobile browsers","archived":false,"fork":false,"pushed_at":"2014-08-06T18:06:46.000Z","size":1735,"stargazers_count":242,"open_issues_count":8,"forks_count":22,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-02-27T21:50:24.276Z","etag":null,"topics":["accelerometer","html5","phone"],"latest_commit_sha":null,"homepage":"http://nunchuckjs.org","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ehzhang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-02T19:59:38.000Z","updated_at":"2023-04-11T15:17:30.000Z","dependencies_parsed_at":"2022-09-10T20:11:28.646Z","dependency_job_id":null,"html_url":"https://github.com/ehzhang/nunchuck","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehzhang%2Fnunchuck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehzhang%2Fnunchuck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehzhang%2Fnunchuck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehzhang%2Fnunchuck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ehzhang","download_url":"https://codeload.github.com/ehzhang/nunchuck/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243858802,"owners_count":20359257,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["accelerometer","html5","phone"],"created_at":"2024-10-14T03:46:17.053Z","updated_at":"2025-03-17T09:30:41.092Z","avatar_url":"https://github.com/ehzhang.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nunchuck.js\n\nA library for mobile web-based control of browser applications.\n\nOverview\n--------\n\nWe provide a library that easily allows developers to integrate mobile browser controls into desktop browser-based javascript games with very few (\u003c15) lines of code.\n\nMade with :heart: at YCHacks 2014! \n\nPull requests and feature suggestions are welcome.\n\nDemo\n------\n\n#### Plane Game\n\nYou can play our multiplayer fighter plane demo by navigating to [http://nunchuckjs.com](http://nunchuckjs.com/planegame) in any desktop browser.\n\nUse your phone as a controller by navigating to [http://nunchuckjs.com](http://nunchuckjs.com) on a mobile browser, then selecting \"CONNECT.\" Then, choose a username and enter the room ID on the screen of the desktop browser. You will see a plane spawn in the screen that responds to your phone's movements.\n\nTilt left or right to steer. Tilt forward to accelerate or backwards to decelerate. Press A to fire bullets. Don't run into other planes or bullets, or your plane will crash! Press start to respawn.\n\n#### Mario Kart\n\nYou can play our multiplayer MarioKart demo by navigating to [http://nunchuckjs.com/snes](http://nunchuckjs.com/snes) in any desktop browser.\n\nUse your phone as a controller by navigating to [http://nunchuckjs.com](http://nunchuckjs.com) on a mobile browser, then selecting \"GAMEPAD.\" You will then be able to use the arrowkeys to select a character. Tilt your phone down or press \"B\" to select.\n\nTilt left or right to steer, and tilt forwards and backwards to accelerate and decelerate, respectively. Press A to use items.\n\n\nQuickstart\n----------\n\nDownload nunchuck.js and refer to it in any html file to get started!\n\n```javascript\n// Socket code in app.js\nrequire('./server/nunchuck-server')(io);\n```\n\n```html\n// Web browser view\n\u003cscript src=\"path/to/nunchuck.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n\tvar socket = io();\n\tvar n = nunchuck.init('host', socket);\n    n.onJoin(function(data){\n        // do something with data from sender\n\n        n.receive(function(data){\n        \t// do something with data from sender\n        })\n    });\n\u003c/script\u003e\n```\n\nDocumentation\n-------------\n\n### Buttons\n\nnunchuck.js responds to both acceleration and button push events. You can customize the buttons in the mobile browser view. Assign each button a class \"nunchuck-button.\" Also assign each button a unique ID (e.g. \"LEFT\", \"RIGHT\", etc.) that will be sent to the receiver (the desktop browser) when that button is pressed.\n\nSample Usage:\n```html\n\u003cdiv class=\"d-pad\"\u003e\n    \u003cbutton class=\"nunchuck-button horizontal\" id=\"LEFT\"\u003e\u003c/button\u003e\n    \u003cbutton class=\"nunchuck-button vertical\" id=\"DOWN\"\u003e\u003c/button\u003e\n    \u003cbutton class=\"nunchuck-button vertical\" id=\"UP\"\u003e\u003c/button\u003e\n    \u003cbutton class=\"nunchuck-button horizontal\" id=\"RIGHT\"\u003e\u003c/button\u003e\n\u003c/div\u003e\n\u003cdiv class=\"left commands\"\u003e\n    \u003cbutton class=\"nunchuck-button\" id=\"START\"\u003eSTART\u003c/button\u003e\n    \u003cbutton class=\"nunchuck-button\" id=\"SELECT\"\u003eSELECT\u003c/button\u003e\n\u003c/div\u003e\n\u003cdiv class=\"right commands\"\u003e\n\t\u003cbutton class=\"nunchuck-button\" id=\"B\"\u003eB\u003c/button\u003e\n\t\u003cbutton class=\"nunchuck-button\" id=\"A\"\u003eA\u003c/button\u003e\n\u003c/div\u003e\n```\n\n### nunchuck.onJoin(callback)\n\nFired when a phone connects to a channel corresponding to this particular web browser view.\n\nThe phone sends a JSON object with the following spec:\n```javascript\n{\n  username: \"ksiegel\",\n  id: \"1234\",\n  success: true,\n  msg: \"\"\n}\n```\n\nData              | Description                               \n----------------- | -----------------------------------------------------\nusername          | (string) inputted username of player \nid                | (integer) generated ID of player \nsuccess           | (boolean) whether or not the controller successfully joined a room\nmsg               | (string) error message if success was false\n\nSample Usage:\n```javascript\nn.receive(function(data){\n\tvar user_id = data.id;\n})\n```\n\n\n### nunchuck.receive(callback)\n\nFired on a phone acceleration, button press, or button release event.\n\nThe phone sends a JSON object with the following spec:\n```javascript\n{\n  username: \"ksiegel\",\n  id: \"1234\",\n  buttons: [\"A\"],\n  orientation: \n  {\n    alpha : 0.0, // float - x axis orientation\n    beta : 0.0, // float - y axis orientation\n    gamma : 0.0, // float - z axis orientation\n  },\n  timestamp: \"1407091145\"\n}\n```\n\nData              | Description                               \n----------------- | ---------------------------------------------------\nusername          | (string) inputted username of player \nid                | (integer) generated ID of player \nbuttons           | (array) array of button IDs of buttons currently pressed by player\norientation.alpha | (float) degree/radian value for direction the device is\norientation.beta  | (float) degree/radian value for device's front-back tilt\norientation.gamma | (float) degree/radian value for device's left-right tilt  \ntimestamp         | (long) seconds since epoch\n\nSample Usage:\n```javascript\nvar socket = io();\nvar n = nunchuck.init('host', socket);\nn.onJoin(function(data){\n\tvar username = data.username;\n});\n```\n\nRun Locally\n-------------\nTo start the demo site locally:\n\n```sh\n$ npm install\n$ npm start\n```\n\nLicense\n-------------\nAvailable under the MIT License\n\nCopyright (c) 2014 [ehzhang](https://github.com/ehzhang), [ankushg](https://github.com/ankushg), [anubhav94](https://github.com/anubhav94), [kathrynsiegel](https://github.com/kathrynsiegel)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fehzhang%2Fnunchuck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fehzhang%2Fnunchuck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fehzhang%2Fnunchuck/lists"}