UNPKG

partysocket

Version:
45 lines (43 loc) 1.3 kB
import { PartySocket } from "./chunk-NLWAO4PP.mjs"; import { getOptionsThatShouldCauseRestartWhenChanged, useAttachWebSocketEventHandlers, useStableSocket, useWebSocket } from "./chunk-IYN7URSK.mjs"; import "./chunk-ZCZZNAX5.mjs"; // src/react.ts function usePartySocket(options) { const { host, ...otherOptions } = options; const socket = useStableSocket({ options: { host: host || (typeof window !== "undefined" ? window.location.host : "dummy-domain.com"), ...otherOptions }, createSocket: (options2) => new PartySocket(options2), createSocketMemoKey: (options2) => JSON.stringify([ // NOTE: if query is defined as a function, the socket // won't reconnect when you change the function identity options2.query, options2.id, options2.host, options2.room, options2.party, options2.path, options2.protocol, options2.protocols, options2.basePath, options2.prefix, ...getOptionsThatShouldCauseRestartWhenChanged(options2) ]) }); useAttachWebSocketEventHandlers(socket, options); return socket; } export { usePartySocket as default, usePartySocket, useWebSocket }; //# sourceMappingURL=react.mjs.map