partysocket
Version:
A better WebSocket that Just Works™
1 lines • 2.35 kB
Source Map (JSON)
{"version":3,"file":"react.cjs","names":["useStableSocket","PartySocket","options","getOptionsThatShouldCauseRestartWhenChanged"],"sources":["../src/react.ts"],"sourcesContent":["import PartySocket from \"./index\";\nimport { useAttachWebSocketEventHandlers } from \"./use-handlers\";\nimport {\n getOptionsThatShouldCauseRestartWhenChanged,\n useStableSocket\n} from \"./use-socket\";\n\nimport type { PartySocketOptions } from \"./index\";\nimport type { EventHandlerOptions } from \"./use-handlers\";\nimport type { SocketOptions } from \"./use-socket\";\n\ntype UsePartySocketOptions = Omit<PartySocketOptions, \"host\"> &\n EventHandlerOptions &\n Pick<SocketOptions, \"enabled\"> & {\n host?: string | undefined;\n };\n\n// A React hook that wraps PartySocket\nexport default function usePartySocket(options: UsePartySocketOptions) {\n const { host, ...otherOptions } = options;\n\n const socket = useStableSocket({\n options: {\n host:\n host ||\n (typeof window !== \"undefined\"\n ? window.location.host\n : \"dummy-domain.com\"),\n ...otherOptions\n },\n createSocket: (options) => new PartySocket(options),\n createSocketMemoKey: (options) =>\n JSON.stringify([\n // NOTE: if query is defined as a function, the socket\n // won't reconnect when you change the function identity\n options.query,\n options.id,\n options.host,\n options.room,\n options.party,\n options.path,\n options.protocol,\n options.protocols,\n options.basePath,\n options.prefix,\n ...getOptionsThatShouldCauseRestartWhenChanged(options)\n ])\n });\n\n useAttachWebSocketEventHandlers(socket, options);\n\n return socket;\n}\n\nexport { default as useWebSocket } from \"./use-ws\";\n\n// TODO: remove the default export in a future breaking change\nexport { usePartySocket };\n"],"mappings":";;;;;;AAkBA,SAAwB,eAAe,SAAgC;CACrE,MAAM,EAAE,MAAM,GAAG,iBAAiB;CAElC,MAAM,SAASA,+BAAgB;EAC7B,SAAS;GACP,MACE,SACC,OAAO,WAAW,cACf,OAAO,SAAS,OAChB;GACN,GAAG;GACJ;EACD,eAAe,cAAY,IAAIC,0BAAYC,UAAQ;EACnD,sBAAsB,cACpB,KAAK,UAAU;GAGbA,UAAQ;GACRA,UAAQ;GACRA,UAAQ;GACRA,UAAQ;GACRA,UAAQ;GACRA,UAAQ;GACRA,UAAQ;GACRA,UAAQ;GACRA,UAAQ;GACRA,UAAQ;GACR,GAAGC,2DAA4CD,UAAQ;GACxD,CAAC;EACL,CAAC;AAEF,gDAAgC,QAAQ,QAAQ;AAEhD,QAAO"}