Handling the active-share-change event when one joins the channel after someone shared the screen

Hey @vk-jangid

There’s a mistake in the generation of the reference document, the CaptureVideoOption is the type definition of the startVideo option. If you use the Video SDK via npm, there is a type hint.

P.S.
I will paste the option definition below:

interface CaptureVideoOption {
  /**
   * Id of the camera for capturing the video, if not specified, use system default
   */
  cameraId?: string | MobileVideoFacingMode;
  /**
   * Customized width of capture, 640 as default
   */
  captureWidth?: number;
  /**
   * Customized height of capture, 360 as
   */
  captureHeight?: number;
  /**
   * Is self video mirrored
   */
  mirrored?: boolean;
  /**
   * video element, only used in android platform or non-SharedArrayBuffer Chromium-like browser
   */
  videoElement?: HTMLVideoElement;
  /**
   * Is capture 720P video
   */
  hd?: boolean;
  /**
   * virtual background option
   */
  virtualBackground?: {
    /**
     * image url for virtual background
     * - If set a specific image, the url can be  a regular http|https url, base64 format or ObjectURL
     * - 'blur' : blur your background
     * - undefined : no virtual backround
     */
    imageUrl: string | 'blur' | undefined;
    /**
     * cropping the background image to an appropriate aspect ratio(16/9), default is false
     */
    cropped?: boolean;
  };
}

Thanks
Vic

Thanks for sharing the option details.
But, Please update the documentation and reference document as there are some issues there.

Hey @vic.yang

why does the device-change event get called when switching the microphone?
Because in the documentation, it is clearly mentioned that this event will get called only when some device is plugged or unplugged from the system.

Thanks
Vivek

Hey @vk-jangid

Thanks for your feedback.

We will improve the timing of the device-change event firing in the next release.

Thanks
Vic

Hey @vic.yang

If I call the muteShareAudio function just after startShareScreen then it is not working at all.
If I call this function in the share-audio-change event then it is working, but it is throwing an error -
{type: 'INTERNAL_ERROR'}
and I think because of this error getShareAudioStatus is giving the value of isShareAudioMuted as false.
but in actuality, the shared tab audio is muted.

NOTE: Here I am Sharing the screen with the tab audio

Can you please look into this once?

Also, I request you to please work on your documentation, it has a lot of issues.
Like, in the chat section, to send a message to a specific participant, the “sendMessage” function is mentioned there, but it throws an error of “sendMessage is not a function”.
“send” is the actual function to do that.

Issues like this waste a lot of our time.

Hey @vk-jangid

Could you share the code snippet that cause the issue?
I tested it on my device with the following code, it works as expected.

async function screenShare() {
  await stream.startShareScreen(videoElm);
  await stream.muteShareAudio();
}

If you are using the event callback way to mute share audio, that’s OK. And we will fix the incorrect return value in the next version.

let isMutedInFirstShare = false;
client.on("share-audio-change", async (payload) => {
  if (payload.state === "on") {
    if (!isMutedInFirstShare) {
      await stream.muteShareAudio();
      isMutedInFirstShare = true;
    }
  }
});

Hope this can help you.

Thanks
Vic

Hi @vic.yang

I am also doing the same thing, but for me, after doing this my mic gets turned off immediately.

await mediaStream.startShareScreen(document.querySelector('#self-screen'));
await mediaStream.muteShareAudio();

Also, I logged the share-audio-change event, and in that only one event is coming with
{ state: 'on' } .

Hey @vk-jangid

In Video SDK, the microphone and chrome tab audio cannot work at the same time so far. As this article introduced, we provide the ‘share-audio-change’ event to notify the update.

Thanks
Vic

Yes, I know about this.

The reason for sharing the details about the event is that after sharing the screen if I am calling muteShareAudio then I should have gotten a new event of { state: ‘off’ }

But I am not getting that, that means the tab audio is not muted.

Hey @vk-jangid

Did you mean after the await stream.muteShareAudio(); statement , the share-audio-change event with payload “state=‘off’” doesn’t fire?

It works on my device, if it is convenient for you, could you share some pseudocode?

Thanks
Vic

Yes, for me the event for “state = off” not coming.

I think for some reason muteShareAudio is not working.
I am not using ShareArrayBuffer, is this can affect the working of muteShareAudio?

Hey @vk-jangid

The share-audio has nothing to do with SharedArrayBuffer. Could you try our sample app?

Thanks
Vic

Ok, I will check this in the sample app.

Also, I found another issue: if I call startAudio() function without the microphone permission allowed in the browser, it throws an error of “USER_FORBIDDEN_MICROPHONE”.
But if I call this function again, it is not throwing any error.

Hey @vk-jangid

Thanks for reporting the issue.

We have found the root cause and it will be fixed in the upcoming release.

Thanks
Vic

Hi @vic.yang

I am calling chat.getHistory() but every time it gives me an empty array even if there was chat before refreshing the page.

Thanks
Vivek

Hey @vk-jangid

Did you mean the chat history cleared after the page reloaded or the session failover?

Thanks
Vic

Yes, i am not getting any chat history after reloading the page.

Hey @vk-jangid

The Video SDK will not keep the chat history after reloading the page. You can choose a persistent way to handle the chat history.

Thanks
Vic

Oh Ok…
But in the documentation, it is mentioned that “it will be useful for the participants who join later”.

Hey @vk-jangid ,

Sorry for the confusion here, we will get the docs updated to reflect the functionality of the chat.getHistory() function.

-Tommy