{"id":20277530,"url":"https://github.com/udamir/magx-client","last_synced_at":"2025-10-03T16:46:34.849Z","repository":{"id":103392404,"uuid":"291229318","full_name":"udamir/magx-client","owner":"udamir","description":"JavaScript Client for MagX server","archived":false,"fork":false,"pushed_at":"2021-06-30T08:35:11.000Z","size":181,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-04T01:42:31.604Z","etag":null,"topics":["js-client","magx"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/udamir.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-29T08:09:57.000Z","updated_at":"2023-03-10T14:05:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"6f044c40-dc18-40ec-b392-fedb237190fa","html_url":"https://github.com/udamir/magx-client","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/udamir/magx-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udamir%2Fmagx-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udamir%2Fmagx-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udamir%2Fmagx-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udamir%2Fmagx-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/udamir","download_url":"https://codeload.github.com/udamir/magx-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udamir%2Fmagx-client/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264853998,"owners_count":23673756,"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":["js-client","magx"],"created_at":"2024-11-14T13:18:49.524Z","updated_at":"2025-10-03T16:46:29.815Z","avatar_url":"https://github.com/udamir.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Magx JS client\n\u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/v/magx-client\"\u003e \u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/dm/magx-client?label=npm\"\u003e \u003cimg alt=\"CircleCI\" src=\"https://img.shields.io/circleci/build/github/udamir/magx-client?token=71d65bfb5432f9a6e372fd71a8edfe7e733b693f\"\u003e \u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/udamir/magx-client\"\u003e\n\n\nJavaScript/TypeScript Client for MagX multiplayer game server.\n\n## Installation\n\n### Installing the module\n```\nnpm install --save magx-client\n```\nand include it to your project\n```ts\nimport { Client } from \"magx-client\"\n```\n\n\n### CDN link\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/magx-client@0.7.1/dist/magx.js\"\u003e\u003c/script\u003e\n```\n\nor you can include magx-client package to server dependencies and use it on client:\n\n```html\n\u003cscript src=\"/magx\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\n### Connecting to server\n```js\nvar client = new MagX.Client({ address: \"localhost\", port: 3001, secure: true })\n\n// Authenticate\nawait client.authenticate({ login, password })\n\n// or verify your session\nawait client.verify(token)\n\n// Get avaliable rooms\nconst rooms = await client.getRooms(\"lobby\")\n\n// create new room\nconst room = await client.createRoom(name, params)\n\n// or join to existing room\nconst room = await client.joinRoom(roomId, params)\n\n// or reconnect to room\nconst room = await client.reconnect(roomId)\n```\n\n### Handle room events\n```js\n// new room state\nroom.onSnapshot((state) =\u003e {\n  console.log(\"initial room state:\", state)\n})\n\n// listen to patches coming from the server\nroom.onPatch((patch) =\u003e {\n  // this signal is triggered on each patch\n  console.log(\"room state patch:\", patch)\n})\n\n// listen to messages coming from the server\nroom.onMessage(\"move\", (data) =\u003e {\n  // this signal is triggered on each \"move\" message\n  console.log(\"new move message:\", data)\n})\n\n// listen to specified state changes\nroom.onChange(\"replace\", \"object/:id/*\", (patch, { id }) =\u003e updateObject(id, patch))\n\n// short alias for onChange event\nroom.onAdd(\"players/:id\", (patch, { id }) =\u003e addPlayer(id, patch.value)\nroom.onRemove(\"players/:id\", (patch, { id }) =\u003e removePlayer(id))\nroom.onReplace(\"players/:id/:prop\", (patch, { id, prop }) =\u003e updatePlayer(id, prop, patch.value))\n\n// server error occurred\nroom.onError((code, message) =\u003e {\n  console.log(\"error\", code, message);\n})\n\n// client left the room\nroom.onLeave(() =\u003e {\n  console.log(client.id, \"left\");\n})\n```\n\n### Use room methods\n```js\n// send message\nroom.send(type, data)\n\n// leave room\nroom.leave()\n\n// close room\nroom.close() {\n\n// update room params\nroom.update(update)\n```\n\n## Examples\n\nThe easiest way to try out magx-client is using the magx-example:\n```\ngit clone https://github.com/udamir/magx-examples.git\ncd magx-examples\nnpm install\n```\nTo run the MagX server, run ```npm start```\n\n# License\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fudamir%2Fmagx-client.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fudamir%2Fmagx-client?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fudamir%2Fmagx-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fudamir%2Fmagx-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fudamir%2Fmagx-client/lists"}