Files
web-Iot/src/components/droneplayer.jsx

35 lines
816 B
React
Raw Normal View History

2026-05-11 14:59:36 +08:00
import VERTC, { RoomProfileType, StreamIndex } from "@volcengine/rtc";
let engine;
export async function joinRoom(container, appId, roomId, token, userId) {
console.info('joinRoom...');
const engine = VERTC.createEngine(appId);
await engine.joinRoom(token, roomId, { userId }, {
isAutoPublish: true,
isAutoSubscribeAudio: true,
isAutoSubscribeVideo: true,
roomProfileType: RoomProfileType.meeting,
});
engine.on(VERTC.events.onUserPublishStream, async (e) => {
if (!container) return;
// 清空旧内容
container.innerHTML = '';
await engine.setUserVisibility(false);
engine.setRemoteVideoPlayer(StreamIndex.STREAM_INDEX_MAIN, {
userId: e.userId,
renderDom: container,
visible: true,
});
});
}
export async function leaveRoom() {
if (engine) await engine.leaveRoom();
}