0

I wanted to detect switch off and switch on event on Twilio network bandwidth API. I am following this article (https://www.twilio.com/docs/video/tutorials/using-bandwidth-profile-api).

This is my configuration for api.

  bandwidthProfile: {
          video: {
            mode: 'grid',
            trackSwitchOffMode: 'detected',
            maxSubscriptionBitrate: 2400000, // 2.4MB
            dominantSpeakerPriority: 'high',
            maxTracks: 3,
            renderDimensions: {
              high: { width: 1080, height: 720 },
              standard: { width: 640, height: 480 },
              low: { width: 160, height: 80 }
            }
          }
        },

I am getting isSwitchOff value false every time.

Thanks in advance

Edit This is the code where isSwitchedOff is used:

const [isSwitchedOff, setIsSwitchedOff] = useState(track && track.isSwitchedOff);
useEffect(() => {
  setIsSwitchedOff(track && track.isSwitchedOff)
  if (track) {
    const handleSwitchedOff = () => setIsSwitchedOff(true)
    const handleSwitchedOn = () => setIsSwitchedOff(false)
    track.on("switchedOff", handleSwitchedOff)
    track.on("switchedOn", handleSwitchedOn)
    return () => {
      track.off("switchedOff", handleSwitchedOff);
      track.off("switchedOn", handleSwitchedOn);
    };
  }}, [track]);
philnash
  • 70,667
  • 10
  • 60
  • 88
  • How are you detecting the switch offs? Are you looking for `isSwitchOff` or [`isSwitchedOff`](https://www.twilio.com/docs/video/tutorials/using-bandwidth-profile-api#programming-with-video-track-switch-offs)? – philnash Feb 16 '21 at 01:23
  • Yes, I am looking for isSwitchedOff. It's a typo in question but right in my code. – Arsalan Subhan Feb 16 '21 at 04:53
  • 1
    Ok, when are you calling on `isSwitchedOff`? What events are you listening to? – philnash Feb 16 '21 at 04:54
  • Yes i am calling isSwitchedOff – Arsalan Subhan Feb 16 '21 at 04:58
  • Can you share the full context, the function in which you are calling that? Please edit your question with the code. – philnash Feb 16 '21 at 05:00
  • This is my react code `const [isSwitchedOff, setIsSwitchedOff] = useState( track && track.isSwitchedOff ); useEffect(() => { setIsSwitchedOff(track && track.isSwitchedOff) if (track) { const handleSwitchedOff = () => setIsSwitchedOff(true) const handleSwitchedOn = () => setIsSwitchedOff(false) track.on("switchedOff", handleSwitchedOff) track.on("switchedOn", handleSwitchedOn) return () => { track.off("switchedOff", handleSwitchedOff); track.off("switchedOn", handleSwitchedOn); }; } }, [track]);` – Arsalan Subhan Feb 16 '21 at 05:04
  • So, you are saying that the tracks are always switched on? Is this a problem? How are you triggering the conditions for the track to be switched off? – philnash Feb 16 '21 at 05:08
  • I am following this repo. https://github.com/twilio/twilio-video-app-react – Arsalan Subhan Feb 16 '21 at 05:24
  • Are you saying that the tracks are always switched on? Is this a problem? How are you triggering the conditions for the track to be switched off? – philnash Feb 16 '21 at 05:25
  • I want to know if the video SwitchedOff by Twillio due to low bandwidth so I can show some message to other participants but I'm always getting isSwitchedOff false. – Arsalan Subhan Feb 16 '21 at 05:33
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/228782/discussion-between-philnash-and-arsalan-subhan). – philnash Feb 16 '21 at 05:34

0 Answers0