UNPKG

@substrate-system/mergeparty

Version:
8 lines (7 loc) 2.11 kB
{ "version": 3, "sources": ["../../src/client/partykit-websocket-adapter.ts"], "sourcesContent": ["import {\n WebSocketClientAdapter\n} from '@automerge/automerge-repo-network-websocket'\nimport { createDebug } from '@substrate-system/debug'\nconst debug = createDebug('mergeparty:network')\n\ninterface PartyKitNetworkAdapterOptions {\n host?:string\n room:string\n party?:string\n}\n\n/**\n * A WebSocket network adapter that connects to PartyKit servers.\n * This is just a thin wrapper around the official\n * automerge `WebSocketClientAdapter`.\n * It constructs the correct PartyKit webSocket URL.\n */\nexport class PartykitNetworkAdapter extends WebSocketClientAdapter {\n constructor (options:PartyKitNetworkAdapterOptions) {\n // Construct the PartyKit WebSocket URL\n // PartyKit WebSocket URL format: ws://host/parties/<party>/<room>\n const host = options.host || 'localhost:1999'\n const protocol = host.startsWith('http://') ? 'ws://' : 'wss://'\n const party = options.party || 'main'\n const cleanHost = host.replace(/^https?:\\/\\//, '')\n const room = options.room\n const url = `${protocol}${cleanHost}/parties/${party}/${room}`\n\n // Call the parent constructor with the constructed URL\n super(url)\n\n debug('Connecting to PartyKit server:', url)\n }\n}\n"], "mappings": "4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAEO,uDACPC,EAA4B,mCAC5B,MAAMC,KAAQ,eAAY,oBAAoB,EAcvC,MAAMC,UAA+B,wBAAuB,CAlBnE,MAkBmE,CAAAC,EAAA,+BAC/D,YAAaC,EAAuC,CAGhD,MAAMC,EAAOD,EAAQ,MAAQ,iBACvBE,EAAWD,EAAK,WAAW,SAAS,EAAI,QAAU,SAClDE,EAAQH,EAAQ,OAAS,OACzBI,EAAYH,EAAK,QAAQ,eAAgB,EAAE,EAC3CI,EAAOL,EAAQ,KACfM,EAAM,GAAGJ,CAAQ,GAAGE,CAAS,YAAYD,CAAK,IAAIE,CAAI,GAG5D,MAAMC,CAAG,EAETT,EAAM,iCAAkCS,CAAG,CAC/C,CACJ", "names": ["partykit_websocket_adapter_exports", "__export", "PartykitNetworkAdapter", "__toCommonJS", "import_automerge_repo_network_websocket", "import_debug", "debug", "PartykitNetworkAdapter", "__name", "options", "host", "protocol", "party", "cleanHost", "room", "url"] }