{"version":3,"file":"react.cjs","names":["useStableSocket","PartySocket","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,eAAAA,gBAAgB;EAC7B,SAAS;GACP,MACE,SACC,OAAO,WAAW,cACf,OAAO,SAAS,OAChB;GACN,GAAG;GACJ;EACD,eAAe,YAAY,IAAIC,cAAAA,YAAY,QAAQ;EACnD,sBAAsB,YACpB,KAAK,UAAU;GAGb,QAAQ;GACR,QAAQ;GACR,QAAQ;GACR,QAAQ;GACR,QAAQ;GACR,QAAQ;GACR,QAAQ;GACR,QAAQ;GACR,QAAQ;GACR,QAAQ;GACR,GAAGC,eAAAA,4CAA4C,QAAQ;GACxD,CAAC;EACL,CAAC;AAEF,gBAAA,gCAAgC,QAAQ,QAAQ;AAEhD,QAAO"}