> For a complete documentation index, fetch https://docs.voximplant.ai/llms.txt

# Web SDK v5 migration guide

Voximplant Web SDK v5 has introduced major breaking changes to provide more functionality and improve the SDK scalability. This guide explains how to smoothly migrate the application code base to use the new API.

## What is new

Voximplant Web SDK v5 introduces a modular architecture that provides greater flexibility and optimizations for web applications:

* **Performance**: fast initialization by loading only the necessary modules
* **Configuration flexibility**: enable only the functionality you need
* **Smaller bundle size**: tree shaking reduces the overall application size
* **Stability**: module isolation prevents cascading failures — an error in one module does not affect others
* **Easier debugging**: separation of functionality simplifies issue isolation
* **Scalability**: easier adoption of new SDK features

## Add Voximplant SDK to your project

You can install Voximplant Web SDK via npm or yarn:

```bash
npm install @voximplant/websdk --save
# OR
yarn add @voximplant/websdk
```

## Modular system and SDK initialization

Voximplant Web SDK v5 comes with a modular architecture.

First, you need to initialize the [Core](/api-reference/websdk5/core/core) instance.

SDK initialization parameters in v4 ([Voximplant.Config](https://voximplant.com/docs/references/websdk/voximplant/config)) are removed and replaced with the parameters in other APIs:

* [Voximplant.Config.H264First](https://voximplant.com/docs/references/websdk/voximplant/config#h264first) → [CallSettings.preferredVideoCodec](/api-reference/websdk5/call/callsettings#preferredvideocodec) and [ConferenceSettings.preferredVideoCodec](/api-reference/websdk5/conference/conferencesettings#preferredvideocodec)
* [Voximplant.Config.enableTrace](https://voximplant.com/docs/references/websdk/voximplant/config#enabletrace), [Voximplant.Config.showDebugInfo](https://voximplant.com/docs/references/websdk/voximplant/config#showdebuginfo), [Voximplant.Config.showWarnings](https://voximplant.com/docs/references/websdk/voximplant/config#showwarnings) are replaced with the new [logger configuration](/api-reference/websdk5/core/logger/overview). See the “Capture SDK logs” section for more details
* [Voximplant.Config.localVideoContainerId](https://voximplant.com/docs/references/websdk/voximplant/config#localvideocontainerid), [Voximplant.Config.remoteVideoContainerId](https://voximplant.com/docs/references/websdk/voximplant/config#remotevideocontainerid), [Voximplant.Config.videoContainerId](https://voximplant.com/docs/references/websdk/voximplant/config#videocontainerid) are removed. See the “Stream module” section for more details
* [Voximplant.Config.rtcStatsCollectionInternal](https://voximplant.com/docs/references/websdk/voximplant/config#rtcstatscollectioninterval) → [CallSettings.statsCollectionInterval](/api-reference/websdk5/call/callsettings#statsreportinterval) and [ConferenceSettings.statsCollectionInterval](/api-reference/websdk5/conference/conferencesettings#statsreportinterval)

From v4:

```javascript
const sdk = VoxImplant.getInstance();
await sdk.init({
  node: $ACCOUNT_NODE
});
```

To v5:

```javascript
import { Core } from '@voximplant/websdk';
const core = Core.init({}); // NOTE: the account node is now set on the connection stage
```

The [Core](/api-reference/websdk5/core/core) acts as an IoC container for all Voximplant Web SDK modules. Each module has its own loader that creates and configures the module, and a token that allows you to obtain the module instance from anywhere in your app.

Modules:

* **Client** — provides seamless connectivity and authentication for your app users on the Voximplant cloud platform. Registered by default after [Core.init](/api-reference/websdk5/core/core#init) call and available via the [Core.client](/api-reference/websdk5/core/core#client) property
* **Call** module — provides the API to initiate and manage voice and video calls
* **Conference** module — enables you to build audio and video conferencing solutions
* **Messaging** module — allows you to build robust messaging features, including public and private groups, channels, or private chats
* **Stream** module — provides the API to manage audio and video streams
* **SmartQueue** module — lets you change and monitor call center agent status for calls and messaging
* **NoiseSuppressionBalanced** — offers advanced noise suppression for audio calls with moderate CPU usage
* **NoiseSuppressionAggressive** — provides advanced noise suppression for audio calls in noisy environments

### Register modules

```javascript
import { Core, StreamLoader, CallLoader } from '@voximplant/websdk';
const core = Core.init({});

// module is registered synchronously
core.registerModules([
  StreamLoader(),
  CallLoader(),
]);

// module is registered asynchronously
import('@voximplant/websdk/modules/noise-suppression-balanced')
  .then( noiseSuppressionModule => {
    const { NoiseSuppressionBalancedLoader } = noiseSuppressionModule
    core.registerModules([NoiseSuppressionBalancedLoader()])
  })
```

### Get module

```javascript
// returns undefined if module is not registered
const streamModule = core.getModule(streamToken);

// resolves after the NoiseSuppressionBalanced module has registered, never rejects
const noiseSuppressionModule = await core.getModuleAsync(noiseSuppressionBalancedToken)
```

## Watchable

Voximplant Web SDK v5 provides a new mechanism to handle the SDK properties changes — the [Watchable](/api-reference/websdk5/core/watchable/overview) reactive type. Watchables are used across all SDK modules.

Watchables can be of 2 types:

* [ReadOnlyWatchable](/api-reference/websdk5/core/watchable/readonlywatchable) — reactive type for immutable structures and primitives with read-only values
* [Watchable](/api-reference/websdk5/core/watchable/watchable) (read-write) — reactive type for immutable structures and primitives with the value that can be read or set anytime

To subscribe to a value change, use the [Watchable.watch](/api-reference/websdk5/core/watchable/watchable#watch) API that allows specifying a callback function and [options](/api-reference/websdk5/core/watchable/watchoptions) to customize the behavior.

Example:

```javascript
core.client.state.watch((newState) => {
   if (newState === ClientState.Disconnected) {
        // Process user disconnected, i.e. redirect to login screen
   }
})
```

## Connect and authenticate the Voximplant users

The [Client](/api-reference/websdk5/core/client) interface provides the API to connect and authenticate the Voximplant users.

Notable changes:

* Account node is now a required parameter for the [Client.connect](/api-reference/websdk5/core/client#connect) API and is not required on the SDK initialization
* The result of connect and login operations can be handled only with the promises that the SDK returns. [Voximplant.Events.ConnectionEstablished](https://voximplant.com/docs/references/websdk/voximplant/events#connectionestablished), [Voximplant.Events.ConnectionFailed](https://voximplant.com/docs/references/websdk/voximplant/events#connectionfailed), and [Voximplant.Events.AuthResults](https://voximplant.com/docs/references/websdk/voximplant/events#authresult) events are removed
* Error message descriptions represented by the string type are replaced with error objects [ConnectionErrors](/api-reference/websdk5/core/connectionerrors/overview) and [LoginErrors](/api-reference/websdk5/core/loginerrors/overview) thrown by the SDK API
* Method parameters are represented as separate interfaces (e.g., [PasswordLoginOptions](/api-reference/websdk5/core/passwordloginoptions)). This improves code readability
* [ClientEvent.Disconnected](/api-reference/websdk5/core/events/clientevent#disconnected) event provides the reason the connection to the Voximplant Cloud is closed
* [Client.getClientState](https://voximplant.com/docs/references/websdk/voximplant/client#getclientstate) is replaced with a read-only [Client.state](/api-reference/websdk5/core/client#state) watchable property
* To (un)subscribe to the client events, use [Client.addEventListener](/api-reference/websdk5/core/client#addeventlistener) instead of [Client.on](https://voximplant.com/docs/references/websdk/voximplant/client#on) and [Client.removeEventListener](/api-reference/websdk5/core/client#removeeventlistener) instead of [Client.off](https://voximplant.com/docs/references/websdk/voximplant/client#off)

### Connect and log in with password

From v4:

```javascript
const sdk = VoxImplant.getInstance();
const ACCOUNT_NODE = VoxImplant.ConnectionNode.NODE_n; // Replace NODE_n with your account node.
await sdk.init({
  node: ACCOUNT_NODE
});
await sdk.connect();
await sdk.login("username@app.account.voximplant.com","password");
```

To v5:

```javascript
import { Core, ConnectionNode } from '@voximplant/websdk';

const core = Core.init({});
const { client } = core;
const ACCOUNT_NODE = ConnectionNode.NODE_n; // Replace NODE_n with your account node.
await client.connect({
  node: ACCOUNT_NODE,
});
await client.login({
  username: "username@app.account.voximplant.com",
  password: "password",
});
```

### Connect and log in with one time key

From v4:

```javascript
const username = `username@$app.account.voximplant.com`;

const sdk = VoxImplant.getInstance();
await sdk.init({
  node: ACCOUNT_NODE
});

// Connect to the cloud and request a key
await sdk.connect()
sdk.requestOneTimeLoginKey(username);

// Listen to the server response
sdk.addEventListener(VoxImplant.Events.AuthResult, async (e) => {
  if (e.result) {
    // Login is successful
  } else if (e.code == 302) {
    const { key } = e;
    // IMPORTANT: You should always calculate the token on your backend!
    const hashRequest = await fetch('https://your.backend.com/', {
      method: 'POST',
      body: JSON.stringify({
        username,
        key,
      }),
    });

    const token = await hashRequest.json();
    sdk.loginWithOneTimeKey(username, token);
  }
});
```

To v5:

```javascript
import { Core, ConnectionNode } from '@voximplant/websdk';

const core = Core.init({});
const { client } = core;
const ACCOUNT_NODE = ConnectionNode.NODE_n; // Replace NODE_n with your account node.
const username = "username@app.account.voximplant.com";

await client.connect({
  node: ACCOUNT_NODE,
});
const key = await client.requestOneTimeKey({
  username,
});

// IMPORTANT: You should always calculate the token on your backend!
const hashRequest = await fetch('https://your.backend.com/', {
  method: 'POST',
  body: JSON.stringify({
    username,
    key,
  }),
});

const hash = await hashRequest.json();

const loginData = await client.loginOneTimeKey({
  username,
  hash,
});
```

## Stream module

Voximplant Web SDK v5 provides a separate `Stream` module to manage audio and video streams. Unlike the previous SDK version, audio/video streams should be created and managed on the application side. This approach gives more flexibility for the application to implement such functionality as video preview and camera configuration.

The `Stream` module gives the ability to manage streams in 2 ways:

1. Manually via a low level API represented by the [StreamManager](/api-reference/websdk5/stream/streammanager) and [Hardware](/api-reference/websdk5/stream/hardware) interfaces
2. With the helpers:

* [DeviceTrackerHelper](/api-reference/websdk5/stream/devicetrackerhelper) — simplifies handling audio and video device changes during an active call or conference.
* [AudioProcessor](/api-reference/websdk5/stream/audioprocessor) — gives the ability to preprocess audio before sending it within a call or conference

> **Please note**
>
> This guide provides the code samples via the DeviceTrackerHelper API

First, you need to register the `Stream` module:

```javascript
import { streamToken, StreamLoader } from '@voximplant/websdk/modules/stream';
const core = Core.init({});
core.registerModules([StreamLoader()]);
```

Create a `DeviceTrackerHelper` instance and enable it:

```typescript
const streamModule = core.getModule(streamToken)!;
const deviceTracker = streamModule.createHelper(StreamHelper.DeviceTracker);
deviceTracker.enableTracker();
```

### Show the local preview

Voximplant Web SDK v5 has changed the approach to render local and remote streams. To render a stream, you should create a renderer ([AudioRenderer](/api-reference/websdk5/stream/renderermanager#createaudiorenderer) or [VideoRenderer](/api-reference/websdk5/stream/renderermanager#createvideorenderer)) and mount it yourself to the DOM. The [RendererManager](/api-reference/websdk5/stream/renderermanager) interface provides the API to manage existing renderers.

> **Please note**
>
> It is important to remove audio and video renderers when a stream associated with the renderer does not exist anymore, for example, when a call or conference has ended, video sending is disabled on a participant side, or local preview has hidden.

For the remote streams — handle call or conferences events, the local streams — handle the user interactions on the UI side.

From v4:

```javascript
await sdk.init({
  node: VoxImplant.ConnectionNode.NODE_n,
  // id of the HTMLElement that is used as a default container for local video elements
  localVideoContainerId: 'local_video_holder',
});

await sdk.showLocalVideo(true);
```

To v5:

```javascript
const streamModule = core.getModule(streamToken);
const deviceTracker = streamModule.createHelper(StreamHelper.DeviceTracker);
deviceTracker.enableTracker();
await deviceTracker.startPreviewVideo();

const stream = deviceTracker.previewVideoStream.value;
const renderer = streamModule.rendererManager.createVideoRenderer(stream);
const videoElement = renderer.getElement();
// mount videoElement to any DOM element
document.getElementById('local_video_holder')?.appendChild(videoElement);
```

## Calls

Voximplant Web SDK v5 has the separate classes that represent a call and a conference. It provides a clearer visibility of the SDK functionality for calls and conferences.

Notable changes:

* Separated call and conference settings to start a call or a conference
* Separated call and conferences events
* Call events do not provide the Call instance that triggered an event, instead the call id is provided
* Endpoints are now available only for the conferences. Information about another call participant as well as its events is now available via the [Call](/api-reference/websdk5/call/call) API
* Updated [call states](/api-reference/websdk5/call/callstate) that can be tracked via the [Call.state](/api-reference/websdk5/call/call#state) watchable
* Screen sharing video stream does not replace a video stream in a video call. Remote participant now receives both streams: video and screen sharing
* Call API throw typed [errors](/api-reference/websdk5/call/errors/overview)
* [Call.setActive](https://voximplant.com/docs/references/websdk/voximplant/call#setactive) → [Call.hold](/api-reference/websdk5/call/call#hold)
* Autohold logic is changed — if an incoming call arrives while the user is in active call, the active call is put on hold when an incoming call is answered
* Call transfer is now available via the [CallManager.transferCall](/api-reference/websdk5/call/callmanager#transfercall) API

Call events changes:

* [CallEvents.ProgressToneStart](https://voximplant.com/docs/references/websdk/voximplant/callevents#progresstonestart) → [CallEvent.StartRinging](/api-reference/websdk5/call/callevents/callevent#startringing)
* [CallEvents.ProgressToneStop](https://voximplant.com/docs/references/websdk/voximplant/callevents#progresstonestop) → [CallEvent.StopRinging](/api-reference/websdk5/call/callevents/callevent#stopringing)
* [CallEvent.RemoteMediaAdded](/api-reference/websdk5/call/callevents/callevent#remotemediaadded) and [CallEvent.RemoteMediaRemoved](/api-reference/websdk5/call/callevents/callevent#remotemediaremoved) are triggered when a remote audio or video stream is available
* [CallEvents.ActiveUpdated](https://voximplant.com/docs/references/websdk/voximplant/callevents#activeupdated) event is removed. To handle the hold status of a call, use the [Call.isOnHold](/api-reference/websdk5/call/call#isonhold) watchable property
* [CallEvents.SharingStopped](https://voximplant.com/docs/references/websdk/voximplant/callevents#sharingstopped) event is removed. To handle any stream end, use the [StreamEvent.Ended](/api-reference/websdk5/stream/events/streamevent#ended) event from the `Streams` module. If the [DeviceTrackerHelper](/api-reference/websdk5/stream/devicetrackerhelper) is attached to a call, screen sharing stop event is going to be handled and processed automatically by the SDK.

Before you start using the `Call` module API, you should register the `Call` module via the [Core.registerModules](/api-reference/websdk5/core/core#registermodules) API:

```javascript
import { streamToken, StreamLoader } from '@voximplant/websdk/modules/stream';
import { callToken, CallLoader } from '@voximplant/websdk/modules/call-manager';
const core = Core.init({});
core.registerModules([StreamLoader(), CallLoader()]);
```

> **Please note**
>
> the `Streams` module is a required dependency for the `Call` module. If the `Streams` module is not registered, Call module registration fails with a [DependencyMissingError](/api-reference/websdk5/core/sharederrors/dependencymissingerror).

[CallManager](/api-reference/websdk5/call/callmanager) interface is the entry point to the `Call` module. It provides the API to create an outgoing call, handle incoming calls, and get all currently active calls.

### Start an outgoing audio call

From v4:

```javascript
const call = sdk.call({
  number: $DESTINATION
})
```

To v5:

```typescript
const callManager = core.getModule(callToken)!;
const streamModule = core.getModule(streamToken)!;

const deviceTracker = streamModule.createHelper(StreamHelper.DeviceTracker);
const call = callManager.createCall($DESTINATION);
deviceTracker.enableTracker();
deviceTracker.attachCall(call);
await call.start();
```

### Start an outgoing video call

From v4:

```javascript
const call = sdk.call({
  number: $DESTINATION,
  video: {
    sendVideo: true,
    receiveVideo: true,
  },
})
```

To v5:

```typescript
const callManager = core.getModule(callToken)!;
const streamModule = core.getModule(streamToken)!;

const deviceTracker = streamModule.createHelper(StreamHelper.DeviceTracker);
const call = callManager.createCall($DESTINATION);
deviceTracker.enableTracker();
deviceTracker.attachCall(call);
deviceTracker.shouldSendVideo.value = true;
await call.start();
```

### Handle incoming calls

From v4:

```javascript
sdk.on(VoxImplant.Events.IncomingCall, (e) => {
  const { call } = e;
  // add listeners to call
  processCallEvents(call);
  call.answer()
});
```

To v5:

```javascript
const callManager = core.getModule(callToken);
const streamModule = core.getModule(streamToken);
callManager.addEventListener(
  CallManagerEvent.IncomingCall,
  ({ payload }) => {
    const call = callManager.getCalls().get(payload.callId);
    const deviceTracker = streamModule.createHelper(StreamHelper.DeviceTracker);
    deviceTracker.enableTracker();
    deviceTracker.attachCall(call);

    // add listeners to call
    processCallEvents(call);
    call.answer();
  }
)
```

### Render remote audio

Voximplant Web SDK v5 has changed the approach to render local and remote streams. To render an audio stream, you should create an [AudioRenderer](/api-reference/websdk5/stream/audiorenderer) instance via the [RendererManager.createAudioRenderer](/api-reference/websdk5/stream/renderermanager#createaudiorenderer) API and mount it yourself to the DOM. The [RendererManager](/api-reference/websdk5/stream/renderermanager) interface provides the API to manage existing renderers.

To handle the audio stream events, subscribe to the [CallEvent.RemoteMediaAdded](/api-reference/websdk5/call/callevents/callevent#remotemediaadded) event via the [Call.addEventListener](/api-reference/websdk5/call/call#addeventlistener) API. Use the [CallRemoteMediaAddedPayload.type](/api-reference/websdk5/call/callevents/callremotemediaaddedpayload#type) property to determine the stream type.

> **Warning**
>
> Do not create audio renderers for local audio streams. Local audio streams are used to send audio to a call and should not be played for the current user.

```javascript
const remoteAudioContainer = document.getElementById('remote_audio_holder');
call.remoteStreams.watch( remoteStreamsSet => {
  remoteAudioContainer.replaceChildren();

  remoteStreamsSet.forEach( remoteStream => {
    if ([StreamType.Audio, StreamType.ScreenAudio].includes(remoteStream.type)) {
      const renderer = streamModule.rendererManager.createAudioRenderer(remoteStream);
      const audioElement = renderer.getElement();
      remoteAudioContainer.appendChild(audioElement);
    }
  })
})
```

### Render local and remote video

From v4:

```javascript
await sdk.init({
  // Other initialization options...
  localVideoContainerId: 'local_video_holder',
  remoteVideoContainerId: 'remote_video_holder',
});
```

To v5:

```javascript
const streamModule = core.getModule(streamToken);

const localVideoContainer = document.getElementById('local_video_holder');
call.localStreams.watch( localStreamsSet => {
  localStreamsSet.forEach( localStream => {
    if ([StreamType.Video, StreamType.ScreenVideo].includes(localStream.type)) {
      const renderer = streamModule.rendererManager.createVideoRenderer(localStream);
      const videoElement = renderer.getElement();
      localVideoContainer.appendChild(videoElement);
    }
  })
})

const remoteVideoContainer = document.getElementById('remote_video_holder');
call.remoteStreams.watch( remoteStreamsSet => {
  remoteVideoContainer.replaceChildren();

  remoteStreamsSet.forEach( remoteStream => {
    if ([StreamType.Video, StreamType.ScreenVideo].includes(remoteStream.type)) {
      const renderer = streamModule.rendererManager.createVideoRenderer(remoteStream);
      const videoElement = renderer.getElement();
      remoteVideoContainer.appendChild(videoElement);
    }
  })
})
```

## Conferences

Voximplant Web SDK v5 has the separate classes that represent a call and a conference. It provides a clearer visibility of the SDK functionality for calls and conferences.

Notable changes:

* Separated call and conference settings to start a call or a conference
* Separated call and conferences events
* Updated [conference states](/api-reference/websdk5/conference/conferencestate) that can be tracked via the [Conference.state](/api-reference/websdk5/conference/conference#state) watchable
* Conference API throw typed [errors](/api-reference/websdk5/conference/errors/overview)
* [Conference.endpoints](/api-reference/websdk5/conference/conference#endpoints) watchable can be used as alternative to the [ConferenceEvent.EndpointAdded](/api-reference/websdk5/conference/events/conferenceevent#endpointadded) and [ConferenceEvent.EndpointRemoved](/api-reference/websdk5/conference/events/conferenceevent#endpointremoved) events
* Starting screen sharing in a conference now adds a new endpoint with the screen sharing stream
* [Conference.voiceActivityDetected](/api-reference/websdk5/conference/conference#voiceactivitydetected) watchable notifies when a voice activity is detected on the current user in a conference
* [Endpoint.isMicrophoneMuted](/api-reference/websdk5/conference/endpoint#ismicrophonemuted) watchable notifies if a remote participant has muted its audio via the [Conference.muteMicrophone](/api-reference/websdk5/conference/conference#mutemicrophone) API
* [Endpoint.enableAll](https://voximplant.com/docs/references/websdk/voximplant/endpoint#enableall) API is replaced with the [Endpoint.startReceivingAudio](/api-reference/websdk5/conference/endpoint#startreceivingaudio) and [Endpoint.startReceivingVideo](/api-reference/websdk5/conference/endpoint#startreceivingvideo) API

Conference events changes:

* Conference and Endpoint events do not provide the Conference/Endpoint instance that triggered an event, instead the conference/endpoint id is provided
* [EndpointEvent.RemoteMediaAdded](/api-reference/websdk5/conference/endpointevents/endpointevent#remotemediaadded) and [EndpointEvent.RemoteMediaRemoved](/api-reference/websdk5/conference/endpointevents/endpointevent#remotemediaremoved) events provide a [RemoteStream](/api-reference/websdk5/stream/remotestream) instance. To render a remote audio or video stream, you should create an [AudioRenderer](/api-reference/websdk5/stream/renderermanager#createaudiorenderer) or [VideoRenderer](/api-reference/websdk5/stream/renderermanager#createvideorenderer) and put it into the DOM
* [EndpointEvents.VoiceStart](https://voximplant.com/docs/references/websdk/voximplant/endpointevents#voicestart) and [EndpointEvents.VoiceEnd](https://voximplant.com/docs/references/websdk/voximplant/endpointevents#voiceend) events are replaced with [Endpoint.voiceActivityDetected](/api-reference/websdk5/conference/endpoint#voiceactivitydetected) watchable
* [EndpointEvents.MediaRenderEnabled](https://voximplant.com/docs/references/websdk/voximplant/endpointevents#mediarenderenabled) event is replaced with [EndpointEvent.StartReceivingAudioStream](/api-reference/websdk5/conference/endpointevents/endpointevent#startreceivingaudiostream) and [EndpointEvent.StartReceivingVideoStream](/api-reference/websdk5/conference/endpointevents/endpointevent#startreceivingvideostream) events
* [EndpointEvents.MediaRenderDisabled](https://voximplant.com/docs/references/websdk/voximplant/endpointevents#mediarenderdisabled) event is replaced with [EndpointEvent.StopReceivingAudioStream](/api-reference/websdk5/conference/endpointevents/endpointevent#stopreceivingaudiostream) and [EndpointEvent.StopReceivingVideoStream](/api-reference/websdk5/conference/endpointevents/endpointevent#stopreceivingvideostream) events

Before you start using the `Conference` module API, you should register the `Conference` module via the [Core.registerModules](/api-reference/websdk5/core/core#registermodules) API:

```javascript
import { streamToken, StreamLoader } from '@voximplant/websdk/modules/stream';
import { conferenceToken, ConferenceLoader } from '@voximplant/websdk/modules/conference-manager';
const core = Core.init({});
core.registerModules([StreamLoader(), ConferenceLoader()]);
```

### Join a conference

From v4:

```javascript
// prepare settings
const conferenceSettings = {
  number: conferenceName,
  simulcast: true,
  video: {
    sendVideo: true,  // whether video is enabled
    receiveVideo: true
  },
};
const conference = sdk.callConference(conferenceSettings);
```

To v5:

```typescript
const conferenceManager = core.getModule(conferenceToken)!;
const streamModule = core.getModule(streamToken)!;
const deviceTracker = streamModule.createHelper(StreamHelper.DeviceTracker);

const conferenceSettings = {
  conferenceName: conferenceName,
  // simulcast enabled by default
  // no video settings here, just add video stream to conference
};

const conference = conferenceManager.createConference(conferenceSettings);
deviceTracker.enableTracker();
deviceTracker.attachConference(conference);
deviceTracker.shouldSendVideo.value = true; // if video should be enabled
await conference.join();
```

### Render remote audio

Voximplant Web SDK v5 has changed the approach to render local and remote streams. To render an audio stream, you should create an [AudioRenderer](/api-reference/websdk5/stream/audiorenderer) instance via the [RendererManager.createAudioRenderer](/api-reference/websdk5/stream/renderermanager#createaudiorenderer) API and mount it yourself to the DOM. The [RendererManager](/api-reference/websdk5/stream/renderermanager) interface provides the API to manage existing renderers.

To handle the audio stream events, subscribe to the [EndpointEvent.RemoteMediaAdded](/api-reference/websdk5/conference/endpointevents/endpointevent#remotemediaadded) event via the [Endpoint.addEventListener](/api-reference/websdk5/conference/endpoint#addeventlistener) API. Use the [EndpointRemoteMediaAddedPayload.type](/api-reference/websdk5/conference/endpointevents/endpointremotemediaaddedpayload#type) property to determine the stream type.

> **Warning**
>
> Do not create audio renderers for local audio streams. Local audio streams are used to send audio to a call and should not be played for the current user.

```javascript
const streamModule = core.getModule(streamToken);
const remoteAudioContainer = document.getElementById('remote_audio_holder');

const getRemoteAudioStreams = (conference) =>
    Array.from(conference.endpoints.value.values()).flatMap((endpoint) => endpoint.getAnyAudioStreams());

const renderConferenceRemoteAudio = (conference) => {
  const streams = getRemoteAudioStreams(conference);

  streams.forEach((stream) => {
    const audioRenderer = streamModule.rendererManager.createAudioRenderer(stream);
    const audioElement = audioRenderer.getElement();
    remoteAudioContainer.appendChild(audioElement);
  });
};

conference.endpoints.watch((endpointsMap) => {
  endpointsMap.forEach((endpoint) => {
    endpoint.addEventListener(EndpointEvent.RemoteMediaAdded, () => {
      renderConferenceRemoteAudio(conference);
    });

    endpoint.addEventListener(EndpointEvent.RemoteMediaRemoved, () => {
      renderConferenceRemoteAudio(conference);
    });
  });

  renderConferenceRemoteAudio(conference);
});
```

### Render local and remote video

From v4:

```javascript
await sdk.init({
  // Other initialization options...
  localVideoContainerId: 'local_video_holder',
  remoteVideoContainerId: 'remote_video_holder',
});
```

To v5:

```javascript
const streamModule = core.getModule(streamToken);
const localVideoContainer = document.getElementById('local_video_holder');

conference.localStreams.watch( localStreamsSet => {
  localStreamsSet.forEach( localStream => {
    if ([StreamType.Video, StreamType.ScreenVideo].includes(localStream.type)) {
      const renderer = streamModule.rendererManager.createVideoRenderer(localStream);
      const videoElement = renderer.getElement();
      localVideoContainer.appendChild(videoElement);
    }
  })
})

const remoteVideoContainer = document.getElementById('remote_video_holder');

const getRemoteVideoStreams = (conference) =>
    Array.from(conference.endpoints.value.values()).flatMap((endpoint) => endpoint.getAnyVideoStreams());

    const renderConferenceRemoteVideo = (conference) => {
      remoteVideoContainer.replaceChildren();
      const streams = getRemoteVideoStreams(conference);

    streams.forEach((stream) => {
      const videoRenderer = streamModule.rendererManager.createVideoRenderer(stream);
      const videoElement = videoRenderer.getElement();
      remoteVideoContainer.appendChild(videoElement);
    });
};

conference.endpoints.watch((endpointsMap) => {
  endpointsMap.forEach((endpoint) => {
    endpoint.addEventListener(EndpointEvent.RemoteMediaAdded, () => {
      renderConferenceRemoteVideo(conference);
    });

    endpoint.addEventListener(EndpointEvent.RemoteMediaRemoved, () => {
      renderConferenceRemoteVideo(conference);
    });
  });

  renderConferenceRemoteVideo(conference);
});
```

## SmartQueue

Voximplant Web SDK API to manage the agent’s status in contact center workspace has moved to a separate `SmartQueue` module.

Before you start using the `SmartQueue` module API, you should register the `SmartQueue` module via the [Core.registerModules](/api-reference/websdk5/core/core#registermodules) API:

```javascript
import { smartQueueToken, SmartQueueLoader } from '@voximplant/websdk/modules/smart-queue';
const core = Core.init({});
core.registerModules([SmartQueueLoader()]);
```

Notable changes:

* `SmartQueue` module does not support ACD v1
* Smart queue statuses are divided into 3 enums and the [SmartQueueStatus](/api-reference/websdk5/smartqueue/smartqueuestatus) union:
  * [SmartQueueAgentStatus](/api-reference/websdk5/smartqueue/smartqueueagentstatus) — statuses that can be set by an agent.
  * [SmartQueueSystemStatus](/api-reference/websdk5/smartqueue/smartqueuesystemstatus) — statuses that are automatically assigned and cannot be manually selected.
  * [SmartQueueCustomStatus](/api-reference/websdk5/smartqueue/smartqueuecustomstatus) — custom statuses that can be set by an agent.
* The API to set an agent status do not return the promise; to handle the set status operation result, you should use the events or watchables.
* The API to get an agent status are replaced with [SmartQueue.callStatus](/api-reference/websdk5/smartqueue/smartqueue#callstatus) and [SmartQueue.messagingStatus](/api-reference/websdk5/smartqueue/smartqueue#messagingstatus) watchable
* If a Voximplant user is authenticated, `SmartQueue` module automatically gets the current call and messaging statuses on the module initialization and if connection to the Voximplant Cloud has been restored after the network issues

### Set call and messaging status

From v4:

```javascript
const sdk = VoxImplant.getInstance();
await sdk.setOperatorACDStatus(newStatus);
await sdk.setOperatorSQMessagingStatus(newStatus);
```

To v5:

```javascript
const smartQueue = core.getModule(smartQueueToken);
smartQueue.setCallStatus(newStatus);
smartQueue.setMessagingStatus(newStatus);
```

### Handle status change

From v4:

```javascript
sdk.on(VoxImplant.Events.ACDStatusUpdated, (event) => {
  // handle status change
});

sdk.on(VoxImplant.Events.SQMessagingStatusUpdated, (event) => {
  // handle status change
});
```

To v5:

```javascript
smartQueue.addEventListener(SmartQueueEvent.CallStatusUpdated, (event) => {
  // handle status change
})
smartQueue.addEventListener(SmartQueueEvent.MessagingStatusUpdated, (event) => {
  // handle status change
})

// Or with watchable smartqueue properties
smartQueue.callStatus.watch( (newStatus, oldStatus) => {
  // handle status change
});
smartQueue.messagingStatus.watch( (newStatus, oldStatus) => {
  // handle status change
});
```

## Capture SDK logs

Voximplant Web SDK v5 provides a more flexible interface to capture SDK logs with extended information such as a log timestamp, time format selection, and a customizable prefix.

Log collection configuration is done for all modules at once and should be on the SDK initialization.

From v4:

```javascript
const sdk = VoxImplant.getInstance();
await sdk.init({
  showDebugInfo: false,
  showWarnings: true,
});
sdk.setLoggerCallback((log) => {
  // process a log message
});
```

To v5:

```javascript
const core = Core.init({
  logger: {
    enableConsoleLogger: false,
    prefix: 'MY_WEBSDK_APP',
    timeFormat: TimeFormat.Timestamp,   // change timestamp to unix time (ms)
    callbackLogLevel: LogLevel.Warning, // send errors and warnings to callback
    onLogCallback: (params) => {
      // process a log message
    }
  },
});
```