{"_id":"@azure/web-pubsub-chat-client","_rev":"2-f2311848fb1f660970df2b068eb3857c","name":"@azure/web-pubsub-chat-client","dist-tags":{"latest":"1.0.0-beta.2"},"versions":{"1.0.0-beta.1":{"name":"@azure/web-pubsub-chat-client","version":"1.0.0-beta.1","keywords":["azure","webpubsub","chat","realtime","messaging"],"author":{"name":"Microsoft"},"license":"MIT","_id":"@azure/web-pubsub-chat-client@1.0.0-beta.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},{"name":"microsoft1es","email":"npmjs@microsoft.com"},{"name":"microsoft-oss-releases","email":"microsoft-oss-publishing@microsoft.com"}],"homepage":"https://github.com/Azure/azure-webpubsub/","bugs":{"url":"https://github.com/Azure/azure-webpubsub/issues"},"tag":"latest","dist":{"shasum":"7934c48ab4ec43c3b8bf6a46ba0c04fdb3004d60","tarball":"https://registry.npmjs.org/@azure/web-pubsub-chat-client/-/web-pubsub-chat-client-1.0.0-beta.1.tgz","fileCount":30,"integrity":"sha512-Dz3CkmK7kD63PPm4J2isS64rQ6KjPWz6w7H7QJzmAuG3TEQzx0af7H/hJ2vYI9d5bsGB95qQVhWlYItny67lhQ==","signatures":[{"sig":"MEUCIQCF+wfJGgu8lN5S+21gfq9BHZzNn/kcs/B579YwAbdzvwIgUEas3RZYZise1UPR+Qfbnk2ZrXzr3enBGwFjObAs4is=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":827139},"main":"dist/index.js","type":"module","_from":"file:M:\\SvcFab\\_App\\MS.Ess.PackageManager.Publisher_App2\\temp\\21d70596-fda8-42d2-8833-ada3f0e759b0\\azure-web-pubsub-chat-client-v1.0.0-beta.1.tgz","types":"dist/index.d.ts","browser":"dist/browser/index.js","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"browser":{"types":"./dist/index.d.ts","default":"./dist/browser/index.js"}},"./package.json":"./package.json"},"scripts":{"test":"npx tsx --test tests/**/*.ts","build":"tsc -p tsconfig.json","test:one":"tsx --test --test-name-pattern","check-api":"api-extractor run","build:watch":"tsc -p tsconfig.json --watch","extract-api":"api-extractor run --local","build:bundle":"node scripts/esbuild.config.mjs && tsc -p tsconfig.json --emitDeclarationOnly","pack:publish":"node scripts/pack-for-publish.mjs","generate:types":"openapi-typescript swagger/openapi.yaml -o src/generatedTypes.ts && node -e \"const fs=require('fs');const c=fs.readFileSync('src/generatedTypes.ts','utf8');const schemas=[...c.matchAll(/^\\s{8}(\\w+):/gm)].map(m=>m[1]);const exports='\\n// Flattened schema exports\\nexport type Schemas = components[\\\"schemas\\\"];\\n'+schemas.map(s=>'export type '+s+' = Schemas[\\\"'+s+'\\\"];').join('\\n')+'\\n';fs.appendFileSync('src/generatedTypes.ts',exports)\"","test:integration":"tsx --test tests/integration.test.ts","test:start-server":"node .\\examples\\quickstart\\server.js"},"_npmUser":{"name":"microsoft1es","email":"npmjs@microsoft.com"},"_resolved":"M:\\SvcFab\\_App\\MS.Ess.PackageManager.Publisher_App2\\temp\\21d70596-fda8-42d2-8833-ada3f0e759b0\\azure-web-pubsub-chat-client-v1.0.0-beta.1.tgz","_integrity":"sha512-Dz3CkmK7kD63PPm4J2isS64rQ6KjPWz6w7H7QJzmAuG3TEQzx0af7H/hJ2vYI9d5bsGB95qQVhWlYItny67lhQ==","repository":{"url":"git+https://github.com/Azure/azure-webpubsub.git","type":"git"},"description":"Client SDK for building chat applications with Azure Web PubSub","directories":{},"_nodeVersion":"18.5.0","dependencies":{"ws":"^8.0.0","@azure/core-paging":"^1.6.2","@azure/abort-controller":"^2.1.2"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.21.0","esbuild":"^0.27.3","typescript":"^5.9.3","@types/node":"^25.0.3","@types/events":"^3.0.3","openapi-typescript":"^7.10.1","@microsoft/api-extractor":"^7.58.7","esbuild-plugin-polyfill-node":"^0.3.0"},"_npmOperationalInternal":{"tmp":"tmp/web-pubsub-chat-client_1.0.0-beta.1_1782116631400_0.6167349912738156","host":"s3://npm-registry-packages-npm-production"}},"1.0.0-beta.2":{"name":"@azure/web-pubsub-chat-client","version":"1.0.0-beta.2","description":"Client SDK for building chat applications with Azure Web PubSub","author":{"name":"Microsoft"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/Azure/azure-webpubsub.git"},"homepage":"https://github.com/Azure/azure-webpubsub/","bugs":{"url":"https://github.com/Azure/azure-webpubsub/issues"},"keywords":["azure","webpubsub","chat","realtime","messaging"],"type":"module","main":"dist/index.js","browser":"dist/browser/index.js","types":"dist/index.d.ts","exports":{".":{"browser":{"types":"./dist/index.d.ts","default":"./dist/browser/index.js"},"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./package.json":"./package.json"},"scripts":{"build":"tsc -p tsconfig.json","build:bundle":"node scripts/esbuild.config.mjs && tsc -p tsconfig.json --emitDeclarationOnly","build:watch":"tsc -p tsconfig.json --watch","pack:publish":"node scripts/pack-for-publish.mjs","generate:types":"openapi-typescript swagger/openapi.yaml -o src/generatedTypes.ts && node -e \"const fs=require('fs');const c=fs.readFileSync('src/generatedTypes.ts','utf8');const schemas=[...c.matchAll(/^\\s{8}(\\w+):/gm)].map(m=>m[1]);const exports='\\n// Flattened schema exports\\nexport type Schemas = components[\\\"schemas\\\"];\\n'+schemas.map(s=>'export type '+s+' = Schemas[\\\"'+s+'\\\"];').join('\\n')+'\\n';fs.appendFileSync('src/generatedTypes.ts',exports)\"","test:start-server":"node .\\examples\\quickstart\\server.js","test":"npx tsx --test tests/**/*.ts","test:integration":"tsx --test tests/integration.test.ts","test:one":"tsx --test --test-name-pattern","extract-api":"api-extractor run --local","check-api":"api-extractor run"},"dependencies":{"@azure/abort-controller":"^2.1.2","@azure/core-paging":"^1.6.2","ws":"^8.0.0"},"devDependencies":{"@microsoft/api-extractor":"^7.58.7","@types/events":"^3.0.3","@types/node":"^25.0.3","esbuild":"^0.27.3","esbuild-plugin-polyfill-node":"^0.3.0","openapi-typescript":"^7.10.1","tsx":"^4.21.0","typescript":"^5.9.3"},"_id":"@azure/web-pubsub-chat-client@1.0.0-beta.2","_integrity":"sha512-ce01RMuGQTuFKb6ZByV0E4ZFhriadfgjW7m7/y4vtGXyMNbAz3+WfBtufqY7Y6H+Bd2T8eCjVT60fYDykDHDfg==","_resolved":"M:\\SvcFab\\_App\\MS.Ess.PackageManager.Publisher_App1\\temp\\1ad0eb69-0ca4-483e-8a0a-8899300cde98\\azure-web-pubsub-chat-client-v1.0.0-beta.2.tgz","_from":"file:M:\\SvcFab\\_App\\MS.Ess.PackageManager.Publisher_App1\\temp\\1ad0eb69-0ca4-483e-8a0a-8899300cde98\\azure-web-pubsub-chat-client-v1.0.0-beta.2.tgz","tag":"latest","_nodeVersion":"18.5.0","dist":{"integrity":"sha512-ce01RMuGQTuFKb6ZByV0E4ZFhriadfgjW7m7/y4vtGXyMNbAz3+WfBtufqY7Y6H+Bd2T8eCjVT60fYDykDHDfg==","shasum":"ce4e65f5d4f1353ee605eaca5f610526816032f7","tarball":"https://registry.npmjs.org/@azure/web-pubsub-chat-client/-/web-pubsub-chat-client-1.0.0-beta.2.tgz","fileCount":30,"unpackedSize":823705,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCBToEQAMtj+mAzDqVN5cdAfdtZUrJTd9EwLXqRMvL+SgIgacqfXq0mHdR4ZQmtFSQ4xrTg6VPgvF9wv1RaJBhiCTg="}]},"_npmUser":{"name":"microsoft1es","email":"npmjs@microsoft.com"},"directories":{},"maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},{"name":"microsoft1es","email":"npmjs@microsoft.com"},{"name":"microsoft-oss-releases","email":"microsoft-oss-publishing@microsoft.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/web-pubsub-chat-client_1.0.0-beta.2_1782790176047_0.902614873429419"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-22T08:23:51.272Z","modified":"2026-06-30T03:29:36.375Z","1.0.0-beta.1":"2026-06-22T08:23:51.559Z","1.0.0-beta.2":"2026-06-30T03:29:36.202Z"},"bugs":{"url":"https://github.com/Azure/azure-webpubsub/issues"},"author":{"name":"Microsoft"},"license":"MIT","homepage":"https://github.com/Azure/azure-webpubsub/","keywords":["azure","webpubsub","chat","realtime","messaging"],"repository":{"type":"git","url":"git+https://github.com/Azure/azure-webpubsub.git"},"description":"Client SDK for building chat applications with Azure Web PubSub","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},{"name":"microsoft1es","email":"npmjs@microsoft.com"},{"name":"microsoft-oss-releases","email":"microsoft-oss-publishing@microsoft.com"}],"readme":"# Azure Web PubSub Chat Client SDK\n\nA client SDK for building chat applications with Azure Web PubSub.\n\n> ⚠️ **Internal Preview**: This package is currently for internal use only and is not ready for production.\n\n## Installation\n\n```bash\nnpm install @azure/web-pubsub-chat-client\n```\n\n## Quick Start\n\nFor a complete example, see [examples/quickstart](./examples/quickstart).\n\n```javascript\nimport { ChatClient } from '@azure/web-pubsub-chat-client';\n\n// Get client access URL from your server\nconst url = await fetch('/negotiate?userId=alice').then(r => r.json()).then(d => d.url);\n\n// Start directly with a client access URL...\nconst client = await ChatClient.start(url);\n\n// ...or with a credential (a callback that returns a client access URL):\n// const client = await ChatClient.start({ getClientAccessUrl: async () => url });\n\nconsole.log(`Started as: ${client.userId}`);\n\n// Listen for events\nclient.on('message', (event) => {\n  const msg = event.message;\n  console.log(`${msg.createdBy}: ${msg.content.text}`);\n});\n\nclient.on('room-joined', (event) => {\n  console.log(`Joined room: ${event.room.title}`);\n});\n\n// Create a room and send messages\nconst room = await client.createRoom('My Room', ['bob']);\nawait client.sendToRoom(room.roomId, 'Hello!');\n\n// Get message history (auto-paginating async iterator)\nfor await (const msg of client.listRoomMessages(room.roomId)) {\n  console.log(`${msg.createdBy}: ${msg.content.text}`);\n}\n\n// Manage room members\nawait client.addUserToRoom(room.roomId, 'charlie');\nawait client.removeUserFromRoom(room.roomId, 'charlie');\n\n// Cleanup\nawait client.stop();\n```\n\n## API\n\n### ChatClient\n\n#### Constructor\n\n```typescript\nnew ChatClient(credential: WebPubSubClientCredential)\n```\n\n`ChatClient` is constructed from a `WebPubSubClientCredential`. It builds and owns the underlying transport: `start()` connects and authenticates, `stop()` disconnects. The instance is constructed but not started — call `start()`, or use the static `ChatClient.start(...)` factory below (which also accepts a plain client-access URL) to construct-and-start in one step.\n\n#### Static Methods\n\n| Method | Description |\n|--------|-------------|\n| `ChatClient.start(clientAccessUrl, options?)` | Construct from a client-access URL and start (`options?: StartOptions`) |\n| `ChatClient.start(credential, options?)` | Construct from a `WebPubSubClientCredential` and start (`options?: StartOptions`) |\n\n#### Properties\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `userId` | `string` | Current user's ID (throws if not started). Read-only — set internally on `start()`. |\n| `rooms` | `RoomInfo[]` | Snapshot of currently joined rooms (not live-updated) |\n\n#### Methods\n\n| Method | Description |\n|--------|-------------|\n| `start(options?)` | Connect and authenticate. Idempotent; concurrent calls share one in-flight promise. After `stop()` the client can be started again. Accepts `{ abortSignal }`. |\n| `stop()` | Disconnect and reset client state. Returns `Promise<void>`. |\n| `createRoom(title, members, options?)` | Create a new room with initial members. The current user is automatically added to the members list. Options: `{ roomId?, abortSignal? }` — supply `roomId` to choose an explicit id, otherwise the service assigns one. |\n| `getRoomDetail(roomId, options?)` | Get the detailed view of a room (`RoomDetail`). Options: `{ withMembers?, abortSignal? }` — pass `withMembers: true` to populate the `members` list (omitted otherwise). |\n| `addUserToRoom(roomId, userId, options?)` | Add user to room (admin operation) |\n| `removeUserFromRoom(roomId, userId, options?)` | Remove user from room (admin operation) |\n| `sendToRoom(roomId, message, options?)` | Send text message to room, returns a `SendMessageResult` (`{ messageId }`) |\n| `listRoomMessages(roomId, options?)` | Paged async iterator over room message history (auto-paginates). Use `for await` to stream every message, or `.byPage({ maxPageSize })` to load up to `maxPageSize` messages at a time. `options = { startId?, endId?, maxPageSize?, abortSignal? }` |\n\nEvery asynchronous method accepts an optional final `options` argument\nextending `OperationOptions` (`{ abortSignal?: AbortSignalLike }`) to\ncancel in-flight invocations:\n\n```ts\nconst ac = new AbortController();\nsetTimeout(() => ac.abort(), 5000);\nawait client.sendToRoom(roomId, \"hi\", { abortSignal: ac.signal });\n```\n\n#### Errors\n\nOperations reject with a `ChatError` (extends `Error`) carrying a\nservice-defined `code`. Known codes are exposed as `KnownChatErrorCode`;\nthe service may return additional codes in newer versions, so always\nhandle the unknown-code case.\n\n```ts\nimport { ChatError, KnownChatErrorCode } from \"@azure/web-pubsub-chat-client\";\n\ntry {\n  await client.sendToRoom(roomId, \"hi\");\n} catch (err) {\n  if (err instanceof ChatError && err.code === KnownChatErrorCode.UnknownRoom) {\n    // re-join or refresh local state\n  } else {\n    throw err;\n  }\n}\n```\n\n| Code | Meaning |\n|------|---------|\n| `KnownChatErrorCode.RoomAlreadyExists` | Tried to create a room whose `roomId` is already in use. |\n| `KnownChatErrorCode.UserAlreadyInRoom` | Adding a user that is already a member. |\n| `KnownChatErrorCode.NoPermissionInRoom` | Caller lacks permission to perform the operation. |\n| `KnownChatErrorCode.NotStarted` | An API was called before `start()` resolved. |\n| `KnownChatErrorCode.UnknownRoom` | The room is not in the client's local cache (joined or created). |\n| `KnownChatErrorCode.InvalidServerResponse` | The service returned a malformed response. |\n\n#### Event Listeners\n\nChat events use the same shape as the underlying `WebPubSubClient`:\none `on(event, listener)` overload per event, returning `void`, paired\nwith `off(event, listener)` for removal. Pass the same callback\nreference to `off()` to unregister.\n\n```ts\nconst onMsg = (event) => {\n  console.log(event.message.content.text);\n};\nclient.on('message', onMsg);\n// later\nclient.off('message', onMsg);\n```\n\n| Event name | Listener argument | Description |\n|------------|-------------------|-------------|\n| `started` | `OnStartedArgs` | `start()` completed successfully — `userId` and `rooms` are populated. |\n| `stopped` | `OnStoppedArgs` | The client transitioned to not-started (explicit `stop()` or transport-driven). |\n| `message` | `OnMessageArgs` | New message received (or sent by this client). |\n| `room-joined` | `OnRoomJoinedArgs` | This client joined a room. |\n| `room-left` | `OnRoomLeftArgs` | This client left a room. |\n| `member-joined` | `OnMemberJoinedArgs` | Another user joined a room this client is in. |\n| `member-left` | `OnMemberLeftArgs` | Another user left a room this client is in. |\n\nThe underlying connection is managed internally and is not exposed. Use the\nchat-level `started` / `stopped` events for lifecycle notifications;\nlower-level connection events (`connected`, `disconnected`) are not\ncurrently surfaced.\n\n## Examples\n\nSee the [examples](./examples) directory for complete working examples.\n\n## License\n\nMIT\n","readmeFilename":"README.md"}