What the correct way to temporarily stop video/audio

What is the correct way to temporarily disable video/audio transmission from PUBLISHER client (an app) so it doesn’t transmit anything? The goal is CPU and Network load optimization on the server.

a) Disable Audio/Video track
b) Remove Transceiver
c) Set Transceiver to INACTIVE
d) Set Transceiver to STOPPED
e) Something else?

The same question applies to remote streams. If a client temporarily don’t wish to receive audio/video from a certain publisher.

Thank you!

Hi mike,
in our use case we send a custom signal (publish or unpublish video/audio) to the android client.
Inside the android app we handle the singal event und toggle camera or microphone.

private fun toggleCamera(isEnabled: Boolean) {
        Logger.info(if (isEnabled) "set camera to enabled" else "set camera to disabled")
        localClient?.getVideoTrack()?.setEnabled(isEnabled)
        callback.onCameraToggled(isEnabled)
    }

    private fun toggleMicrophone(isEnabled: Boolean) {
        Logger.info(if (isEnabled) "set micro to enabled" else "set micro to disabled")
        localClient?.getAudioTrack()?.setEnabled(isEnabled)
        callback.onMicrophoneToggled(isEnabled)
    }

Then, we manually send the streamPropertyChangedEvent.

Thank you for your reply. I want to clarify that I don’t really care about any signaling. In other words it doesn’t matter for this topic how exactly we notify clients about the video/audio state on remote partners. The only thing I care is to minimize traffic and load on OpenVidu server and also safe the bandwidth for customers.

As I see, your solution is to enable/disable video tracks. I’m currently doing the same in my project (my approach to signaling is different, but it doesn’t matter). This works, but I’m curious if disabling the track effectively stops any data transfer or, for example, it still sends empty frames in the video track?

As I see, your solution is to enable/disable video tracks. I’m currently doing the same in my project (my approach to signaling is different, but it doesn’t matter). This works, but I’m curious if disabling the track effectively stops any data transfer or, for example, it still sends empty frames in the video track?

Disabling the video or audio track don’t stop data transfer. If you disable the video track - WebRTC will send empty frames. For our use case, this is very important - because we make a recording of the video track - and audio and video must be kept in sync while showing another video track of another participant.

It seems our use case is not a good best practice example for your use case :wink:

Oh, this is quite bad. In most of the time we have only audio track and video is off. Even audio often on for just one publisher, but we need to instantly switch between publishers (who is speaking now, who can hear and who is not) according to the game logic. We don’t record anything. So my current approach is to toggle (enable/disable) tracks. But it appears that our server most of the time wasting CPU on transferring empty frames. May be if I can optimize this can I have less servers for the same amount of players. This will safe me a lot of money.

Is there a way to completely disable data transfer for the track but keep user connected (because we need instant switch, we can’t afford players exit/enter room every 30 seconds or so)?

For example, what if I do something with Transceivers? Set their state to INACTIVE or to STOPPED? May be add/remove Transceivers?