Skip to content

Switch Stream

Basic Usage

typescript
player.switchStream('webrtc://localhost/live/newstream');

Example

typescript
const player = new RtcPlayer({
  url: 'webrtc://localhost/live/camera1',
  api: 'http://localhost:1985/rtc/v1/play/',
  video: videoElement,
});

player.on('state', (state) => {
  if (state === RtcState.SWITCHED) {
    console.log('Switched');
  }
});

player.play();

// Switch to another source after 3 seconds
setTimeout(() => {
  player.switchStream('webrtc://localhost/live/camera2');
}, 3000);

Notes

  1. Triggers SWITCHINGSWITCHED state during switching
  2. Automatically closes old connection and creates new one

基于 MIT 许可证发布