Please do not forget to add a link to a Playground to get a faster answer:
this.myPeer.on('call', (call: MediaConnection) => {
const fromUserId: string = call.metadata.fromSessionId
if (!this.onCalledPeers.has(call.peer)) {
this.onCallList.push(call)
console.log("收到call metadata", call.metadata)
const fromUserId: string = call.metadata.fromSessionId
const video = document.createElement('video');
video.playsInline = true
video.autoplay = false;
video.preload = "none";
video.controls = true;
this.onCalledPeers.set(call.peer, { call, video });
call.answer()
call.on('stream', (userVideoStream: MediaStream) => {
video.crossOrigin = "anonymous";
video.srcObject = userVideoStream;
const videoMaterial = new StandardMaterial('textVid', this.scene);
videoMaterial.allowShaderHotSwapping = false;
video.pause();
video.addEventListener('loadedmetadata', () => {
video.play();
const scene = store.getState().room.rscene
videoMaterial.specularColor = new Color3(0, 0, 0); // 设置让它不反光
const videoTexture = new VideoTexture('video', video, scene, true, true);
videoMaterial.diffuseTexture = videoTexture;
store.getState().room.rscene!.getMeshByID("video-plane-" + userId)!.material = videoMaterial;
});
});
}
});