I try start livestream video on open page, follow doc for setup and create token, init, join, start video. Session is started, users are join on session, but video doesn’t show. I try with canvas and video tags.
on first render get error in console:
canvas is falsy
on click start button get error:
You must pass a <video>
element to start video capture for Chromium browser, Android browser, and Chrome without SharedArrayBuffer support.
zoom/videosdk:1.1.7,
import React, {
FC,
useCallback,
useContext,
useEffect,
useRef,
useState,
useMemo
} from 'react';
import ZoomContext from 'core/components/ZoomClientContext';
import { KJUR } from 'jsrsasign';
import { ChatClient, MediaStream } from "./index-types";
import ZoomVideo, { ConnectionState } from "@zoom/videosdk";
import style from './index.module.scss';
import LivestreamUI from './LivestreamUI/livestreamui';
export const LivestreamVideoComp = (props: any) => {
const client: any = useContext(ZoomContext);
const canvasRef = useRef<HTMLCanvasElement | null>(null);
const videoRef = useRef<HTMLVideoElement | null>(null);
useEffect(() => {
const init = async () => {
const token = generateVideoToken(
"test",
"password"
);
console.log('token', token);
await client.init();
try {
await client.join(
"test",
token,
"userIdd",
"password",
)
const stream = await client.getMediaStream();
await stream.startVideo();
changeHandler()
} catch (e: any) {
setIsLoading(false);
console.log(e.reason);
}
};
init();
}, []);
const changeHandler = async () => {
client.on('peer-video-state-change', async (payload: { action: any; userId: any; }) => {
console.log('payload', payload);
const {
action,
userId
} = payload;
if (action === 'Start') {
await stream.renderVideo(videoRef.current, userId, 1280, 720, 0, 0, 3);
} else if (action === 'Stop') {
await stream.stopRenderVideo();
}
})
}
const stop = async () => {
const stream = await client.getMediaStream();
await stream.stopVideo();
await stream.renderVideo();
}
const start = async () => {
const stream = await client.getMediaStream();
await stream.startVideo();
changeHandler()
}
function generateVideoToken(topic: any, password = "") {
let signature = "";
// try {
const iat = Math.round(new Date().getTime() / 1000);
const exp = iat + 60 * 60 * 2;
// Header
const oHeader = { alg: "HS256", typ: "JWT" };
// Payload
const oPayload = {
app_key: sdkKey,
iat,
exp,
tpc: topic,
pwd: password,
user_identity: userIdd,
version: 1
};
// Sign JWT
const sHeader = JSON.stringify(oHeader);
const sPayload = JSON.stringify(oPayload);
signature = KJUR.jws.JWS.sign("HS256", sHeader, sPayload, sdkSecret);
return signature;
}
return (
<div className={style.videoBox}>
<div style={{ display: 'flex', justifyContent: 'center', position: 'absolute', zIndex: 4 }}>
<button style={{ width: 100, height: 30 }} onClick={() => stop()}>stop</button>
<button style={{ width: 100, height: 30 }} onClick={() => start()}>start</button>
</div>
<video
className={style.videoCanvas}
//id="video-canvas"
// width="1600"
// height="900"
ref={videoRef}
/>
{/* <canvas
id={SELF_VIDEO_ID}
className={style.previewVideo}
ref={canvasRef}
width="1600"
height="900"
/> */}
</div>
);
};
- Device: Macbook Pro M1
- OS: [e.g. macOS 11]
- Browser: Chrome, Firefox
- Browser Version 96.0.4664.110 (Official Build) (arm64)