{"version":3,"sources":["../../modules/react/sockets/index.ts"],"sourcesContent":["import { io, ManagerOptions, Socket, SocketOptions } from \"socket.io-client\";\r\n\r\n/**\r\n * Creates a Socket.IO client connection to a specific namespace.\r\n * \r\n * This helper function simplifies Socket.IO client setup by handling:\r\n * - Namespace normalization (ensures leading slash)\r\n * - Base URL resolution (from environment or current origin)\r\n * - Default Socket.IO configuration (path: '/wss', transports: ['websocket', 'polling'])\r\n * \r\n * @param namespace - The namespace to connect to (e.g., '/chat' or 'chat').\r\n *                    The namespace will be normalized to always start with '/'.\r\n *                    Must match the namespace pattern defined in your server's WSS routes.\r\n * @param opts - Optional Socket.IO client options that will override the defaults.\r\n * \r\n * @returns A Socket.IO client instance connected to the specified namespace.\r\n * \r\n * @example\r\n * ```ts\r\n * const socket = lolySocket('/chat');\r\n * socket.on('message', (data) => {\r\n *   console.log('Received:', data);\r\n * });\r\n * socket.emit('message', { text: 'Hello' });\r\n * ```\r\n */\r\nexport const lolySocket = (\r\n  namespace: string,\r\n  opts?: Partial<ManagerOptions & SocketOptions>\r\n): Socket => {\r\n  // Simplified: Always use the current origin in the browser\r\n  // Socket.IO handles the namespace automatically\r\n  if (typeof window === \"undefined\") {\r\n    throw new Error(\r\n      \"[loly:socket] lolySocket can only be called on the client side.\"\r\n    );\r\n  }\r\n\r\n  const normalizedNamespace = namespace.startsWith(\"/\") ? namespace : `/${namespace}`;\r\n  \r\n  // Socket.IO: io(namespace, { path: '/wss' })\r\n  // Socket.IO uses window.location.origin automatically\r\n  // The path '/wss' is the Socket.IO engine endpoint\r\n  // The namespace is handled in the handshake\r\n\r\n  const socket = io(normalizedNamespace, {\r\n    path: \"/wss\",\r\n    transports: [\"websocket\", \"polling\"],\r\n    autoConnect: true,\r\n    ...opts,\r\n  });\r\n\r\n  return socket;\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0D;AA0BnD,IAAM,aAAa,CACxB,WACA,SACW;AAGX,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,sBAAsB,UAAU,WAAW,GAAG,IAAI,YAAY,IAAI,SAAS;AAOjF,QAAM,aAAS,kBAAG,qBAAqB;AAAA,IACrC,MAAM;AAAA,IACN,YAAY,CAAC,aAAa,SAAS;AAAA,IACnC,aAAa;AAAA,IACb,GAAG;AAAA,EACL,CAAC;AAED,SAAO;AACT;","names":[]}