# Genesys Cloud Streaming Client The Genesys Cloud Streaming Client handles establishing and maintaining a websocket connection to the Genesys Cloud streaming services. This project uses our new XMPP based signaling for real time APIs. ## Installation ```bash npm install genesys-cloud-streaming-client ``` ## Browser Usage & Polyfills The streaming client uses Node.js built-in modules (`events`, `global`) that are not available natively in the browser. If you are using a bundler (Vite, Webpack, etc.), you will need to add polyfills for these. ### `global` The client references `global`, which does not exist in browsers. Alias it to `window`: **Vite** (`vite.config.ts`): ```ts export default defineConfig({ define: { global: 'window', }, }); ``` **Webpack** (`webpack.config.js`): ```js const webpack = require('webpack'); module.exports = { plugins: [ new webpack.ProvidePlugin({ global: ['window'], }), ], }; ``` ### `events` (EventEmitter) The client extends Node's `EventEmitter`. You need to polyfill the `events` module for browser environments. **Vite** — install the `events` polyfill and configure the alias: ```bash npm install events ``` ```ts // vite.config.ts import { defineConfig } from 'vite'; export default defineConfig({ resolve: { alias: { events: 'events', }, }, define: { global: 'window', }, }); ``` **Webpack** — Webpack 4 included this polyfill automatically. For Webpack 5, install and configure it: ```bash npm install events ``` ```js // webpack.config.js module.exports = { resolve: { fallback: { events: require.resolve('events/'), }, }, }; ``` ### `process` Some dependencies reference `process`. If you see errors about `process is not defined`, add a polyfill: **Vite**: ```bash npm install process ``` ```ts // vite.config.ts import { defineConfig } from 'vite'; export default defineConfig({ define: { global: 'window', 'process.env': {}, }, }); ``` **Webpack**: ```js const webpack = require('webpack'); module.exports = { plugins: [ new webpack.ProvidePlugin({ process: 'process/browser', }), ], }; ``` ## Usage The SDK is based on a simple structure of a core client object with a few properties and methods, and multiple extensions, each providing their own functionality. Some extensions are bundled with the client, and others can be added at runtime. See [Extensions](extensions.md) for details on implementing or adding an extension (or to request one be added to core). After creating an instance of the client, your client can add event handlers for various events and messages. `connected` and `disconnected` are examples of client events. Extensions are also based on event emitters. ### Importing The client is exported as a default export named `Client`. Import it like so: **ES Modules / TypeScript:** ```ts import StreamingClient from 'genesys-cloud-streaming-client'; ``` **CommonJS:** ```js const StreamingClient = require('genesys-cloud-streaming-client').default; ``` > Note: The class is exported as `Client` but you can name the import whatever you > like. `StreamingClient` is the conventional name used in consuming applications. > Older documentation may reference `GenesysCloudStreamingClient` — that name is only > used by the UMD browser bundle (loaded via `