UNPKG

@substrate-system/mergeparty

Version:
8 lines (7 loc) 1.85 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": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8CAEO;AACP,mBAA4B;AAC5B,MAAM,YAAQ,0BAAY,oBAAoB;AAcvC,MAAM,+BAA+B,+DAAuB;AAAA,EAlBnE,OAkBmE;AAAA;AAAA;AAAA,EAC/D,YAAa,SAAuC;AAGhD,UAAM,OAAO,QAAQ,QAAQ;AAC7B,UAAM,WAAW,KAAK,WAAW,SAAS,IAAI,UAAU;AACxD,UAAM,QAAQ,QAAQ,SAAS;AAC/B,UAAM,YAAY,KAAK,QAAQ,gBAAgB,EAAE;AACjD,UAAM,OAAO,QAAQ;AACrB,UAAM,MAAM,GAAG,QAAQ,GAAG,SAAS,YAAY,KAAK,IAAI,IAAI;AAG5D,UAAM,GAAG;AAET,UAAM,kCAAkC,GAAG;AAAA,EAC/C;AACJ;", "names": [] }