{"id":17466603,"url":"https://github.com/liammartens/ably-react","last_synced_at":"2025-04-04T19:49:01.546Z","repository":{"id":65565538,"uuid":"585730786","full_name":"LiamMartens/ably-react","owner":"LiamMartens","description":null,"archived":false,"fork":false,"pushed_at":"2023-09-08T04:44:09.000Z","size":399,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-14T12:17:24.869Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LiamMartens.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-01-05T23:28:26.000Z","updated_at":"2023-07-26T16:01:54.000Z","dependencies_parsed_at":"2024-10-30T08:30:01.990Z","dependency_job_id":null,"html_url":"https://github.com/LiamMartens/ably-react","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiamMartens%2Fably-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiamMartens%2Fably-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiamMartens%2Fably-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiamMartens%2Fably-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LiamMartens","download_url":"https://codeload.github.com/LiamMartens/ably-react/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247241040,"owners_count":20906923,"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-10-18T13:56:30.140Z","updated_at":"2025-04-04T19:49:01.525Z","avatar_url":"https://github.com/LiamMartens.png","language":"TypeScript","readme":"# ably-react\n**UNOFFICIAL**  \nOpinionated React library for using Ably channels and clients.\nThis library can handle multiple clients in a single page/app.\n\n## Getting started\n## Available hooks\n### useAbly\nThis hook registers and uses a realtime Ably client.\nYou can pass a name to the `useAbly` hook to register multiple clients.\n\nThis hook can be used any number of times. Each hook will register a lock on the client.\nIf all locks disappear the client will be destroyed and disconnected.\n\n```jsx\nimport { useAbly } from 'ably-react';\n\nfunction App() {\n  const ably = useAbly({\n    // OPTIONAL: whether to skip client initialization for now.\n    // useful when waiting for authentication\n    skip: false,\n    // OPTIONAL: can be used to identify the client\n    clientId: 'user-id',\n    // OPTIONAL [default: true]: whether to automatically connect the client\n    autoConnect: true,\n    // OPTIONAL [default: \"default\"]: the name to register the client under\n    // the library allows for multiple clients (named)\n    name: 'default',\n    // OPTIONAL: Callback used to authenticate. This callback is a promise as opposed.\n    authCallback: async (data) =\u003e {\n      return fetchToken();\n    },\n    // OPTIONAL: Any other options to pass through to the client\n    clientOptions: {},\n  });\n}\n```\n\n### useAblyClient\nThis hook simply gets a client from the context by name (`default` by default).\nIt does not register a lock on the client and simply returns the raw `Ably.Realtime` client.\n\n```js\nconst ablyClient = useAblyClient('default')\n```\n\n### useAblyClientStatus\nThis hook simply gets a the client status from the context by name (`default` by default)\nAs with the `useAblyClient` hook, this also does not register a lock on the client and simply returns the client status.\n\n```js\nconst ablyClientStatus = useAblyClientStatus('default')\n```\n\n### useChannel\nThis hook simply gets a channel reference.\n\n```js\nconst ably = useAbly()\nconst channel = useChannel(ably.client, 'my-channel')\n```\n\n### useChannelStatus\nThis hook will track and return the status of a channel.\n\n```js\nconst ably = useAbly()\nconst channel = useChannel(ably.client, 'my-channel')\nconst status = useChannelStatus(channel)\n```\n\n### useIsClientPresent\nThis hook will keep track of whether a specific client is present. This is useful for peer to peer like communication.\n\n```js\nconst ably = useAbly()\nconst channel = useChannel(ably.client, 'my-channel')\nconst isClientPresent = useIsClientPresent(channel, 'client-id', (error) =\u003e {\n  // do something on error\n});\n```\n\n### usePresent\nThis hook will announce it's presence on a channel (and remove it if not rendered).\n\n```js\nconst ably = useAbly()\nconst channel = useChannel(ably.client, 'my-channel')\nusePresent(channel)\n```\n\n### useRetryAttachUntil\nThis hook will retry attaching a channel until the callback returns `false`.\nThis is useful for recovering `failed` channel states.\n\n```js\nconst ably = useAbly()\nconst channel = useChannel(ably.client, 'my-channel')\nuseRetryAttachUntil(channel, 1000, (retryCount, event) =\u003e retryCount \u003e 3, (event) =\u003e {\n  // do something on failure\n});\n```\n\n### useHandshakeHandler\nThis hook should be used with the `waitForHandshake` utility (see below). This hook simply handles responding to a handshake request. (should only be rendered once per channel).\n\n```js\nconst ably = useAbly()\nconst channel = useChannel(ably.client, 'my-channel')\nuseHandshakeHandler(channel);\n```\n\n## Utilities\n### waitForAttached\nThis utility returns a promise which waits for a channel to be attached (or rejects on timeout if specified).\n\n```js\nawait waitForAttached(channel, 1000); // if timeout is omitted, the promise will never reject\n```\n\n### waitForMessage\nThis utility returns a promise which waits for a specific message from a channel (or rejects on timeout if specified).]\n\n```js\nawait waitForMessage(channel, (message) =\u003e message.name === 'ping', 1000); // if timeout is omitted, the promise will never reject\n```\n\n### waitForHandshake\nThis utility returns a promise which will send a handshake request (and retry per interval), until the handshake is accepted by another client.\n\n```js\nawait waitForHandshake(\n  channel,\n  1000 /* retry interval */,\n  1000 /* timeout */,\n  (message) =\u003e true, /* only accept handshake if ... */\n); // if timeout is omitted, the promise will never reject\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliammartens%2Fably-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliammartens%2Fably-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliammartens%2Fably-react/lists"}