35 lines
816 B
React
35 lines
816 B
React
|
|
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();
|
||
|
|
}
|