{"id":20564607,"url":"https://github.com/yjs/y-protocols","last_synced_at":"2025-05-16T06:08:08.462Z","repository":{"id":39707309,"uuid":"169402266","full_name":"yjs/y-protocols","owner":"yjs","description":"Yjs encoding protocols","archived":false,"fork":false,"pushed_at":"2025-05-01T13:24:07.000Z","size":173,"stargazers_count":136,"open_issues_count":6,"forks_count":45,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-12T01:36:08.823Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/yjs.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},"funding":{"github":"dmonad","patreon":null,"open_collective":"y-collective","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-02-06T12:25:37.000Z","updated_at":"2025-05-06T15:36:20.000Z","dependencies_parsed_at":"2024-03-04T12:03:20.099Z","dependency_job_id":"695b68d6-e4dc-49f4-b2c6-4c648e075f49","html_url":"https://github.com/yjs/y-protocols","commit_stats":{"total_commits":70,"total_committers":11,"mean_commits":6.363636363636363,"dds":"0.48571428571428577","last_synced_commit":"a4dd5de756f1061eaca9c1b4ebb2013e74987a11"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjs%2Fy-protocols","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjs%2Fy-protocols/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjs%2Fy-protocols/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjs%2Fy-protocols/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yjs","download_url":"https://codeload.github.com/yjs/y-protocols/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253910085,"owners_count":21982694,"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":[],"created_at":"2024-11-16T04:28:06.520Z","updated_at":"2025-05-16T06:08:03.453Z","avatar_url":"https://github.com/yjs.png","language":"JavaScript","funding_links":["https://github.com/sponsors/dmonad","https://opencollective.com/y-collective"],"categories":["JavaScript"],"sub_categories":[],"readme":"# Yjs Protocols\n\u003e Binary encoding protocols for *syncing*, *awareness*, and *history information*\n\nThis API is unstable and subject to change.\n\n## API\n\n### Awareness Protocol\n\n```js\nimport * as awarenessProtocol from 'y-protocols/awareness.js'\n```\n\nThe Awareness protocol implements a simple network agnostic algorithm that\nmanages user status (who is online?) and propagate awareness information like\ncursor location, username, or email address. Each client can update its own\nlocal state and listen to state changes of remote clients.\n\nEach client has an awareness state. Remote awareness are stored in a Map that\nmaps from remote client id to remote awareness state. An *awareness state* is an\nincreasing clock attached to a schemaless json object.\n\nWhenever the client changes its local state, it increases the clock and\npropagates its own awareness state to all peers. When a client receives a remote\nawareness state, and overwrites the clients state if the received state is newer\nthan the local awareness state for that client. If the state is `null`, the\nclient is marked as offline. If a client doesn't receive updates from a remote\npeer for 30 seconds, it marks the remote client as offline. Hence each client\nmust broadcast its own awareness state in a regular interval to make sure that\nremote clients don't mark it as offline.\n\n#### awarenessProtocol.Awareness Class\n\n```js\nconst ydoc = new Y.Doc()\nconst awareness = new awarenessProtocol.Awareness(ydoc)\n```\n\n\u003cdl\u003e\n  \u003cb\u003e\u003ccode\u003eclientID:number\u003c/code\u003e\u003c/b\u003e\n  \u003cdd\u003eA unique identifier that identifies this client.\u003c/dd\u003e\n  \u003cb\u003e\u003ccode\u003egetLocalState():Object\u0026lt;string,any\u0026gt;|null\u003c/code\u003e\u003c/b\u003e\n  \u003cdd\u003eGet the local awareness state.\u003c/dd\u003e\n  \u003cb\u003e\u003ccode\u003esetLocalState(Object\u0026lt;string,any\u0026gt;|null)\u003c/code\u003e\u003c/b\u003e\n  \u003cdd\u003e\nSet/Update the local awareness state. Set `null` to mark the local client as\noffline.\n  \u003c/dd\u003e\n  \u003cb\u003e\u003ccode\u003esetLocalStateField(string, any)\u003c/code\u003e\u003c/b\u003e\n  \u003cdd\u003e\nOnly update a single field on the local awareness object. Does not do\nanything if the local state is not set.\n  \u003c/dd\u003e\n  \u003cb\u003e\u003ccode\u003egetStates():Map\u0026lt;number,Object\u0026lt;string,any\u0026gt;\u0026gt;\u003c/code\u003e\u003c/b\u003e\n  \u003cdd\u003e\nGet all client awareness states (remote and local). Maps from clientID to\nawareness state.\n  \u003c/dd\u003e\n  \u003cb\u003e\u003ccode\u003e\non('change', ({ added: Array\u0026lt;number\u0026gt;, updated: Array\u0026lt;number\u0026gt;\nremoved: Array\u0026lt;number\u0026gt; }, [transactionOrigin:any]) =\u003e ..)\n  \u003c/code\u003e\u003c/b\u003e\n  \u003cdd\u003e\nListen to remote and local state changes on the awareness instance.\n  \u003c/dd\u003e\n  \u003cb\u003e\u003ccode\u003e\non('update', ({ added: Array\u0026lt;number\u0026gt;, updated: Array\u0026lt;number\u0026gt;\nremoved: Array\u0026lt;number\u0026gt; }, [transactionOrigin:any]) =\u003e ..)\n  \u003c/code\u003e\u003c/b\u003e\n  \u003cdd\u003e\nListen to remote and local awareness changes on the awareness instance.\nThis event is called even when the awarenes state does not change.\n  \u003c/dd\u003e\n\u003c/dl\u003e\n\n### License\n\n[The MIT License](./LICENSE) © Kevin Jahns\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyjs%2Fy-protocols","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyjs%2Fy-protocols","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyjs%2Fy-protocols/lists"}