Uncaught (in promise) DOMException: Could not start video source , Uncaught Error: The error you provided does not contain a stack trace
Uncaught (in promise) DOMException: Could not start video source , Uncaught Error: The error you provided does not contain a stack trace
大家好,我正在尝试 运行 使用反应、节点、套接字和 peerjs 进行 webrtc 视频通话,如果我尝试使用 chrome 开始视频聊天,如果我 运行 chrome 作为私人并作为第二个用户使用视频连接 link 它有效,但如果我尝试使用相同的视频从另一个浏览器连接 link 例如边缘或歌剧它不起作用而不是它控制台记录错误..
我的代码
import React from 'react'
import io from 'socket.io-client'
import Peer from 'peerjs'
import './ClassWall.css'
const socket = io.connect('http://localhost:4000/')
class LiveClass extends React.Component{
constructor(){
super()
this.state = {
userId :'',
classStatus: '',
}
}
async componentDidMount(){
const videoGrid = document.getElementById('video-grid')
const Myvideo = document.createElement('video')
Myvideo.muted = true
//set user id of logged in user
try {
const response = await fetch('http://localhost:4000/Auth//UserID/id',{
headers:{token:localStorage.token}
})
const Parse = await response.json()
this.setState({userId:Parse})
} catch (error) {
}
//get user id to connect through peer
const myPeer = new Peer(this.state.userId,{
host: '/',
port:4001
})
//connect and share video stream
try {
navigator.mediaDevices.getUserMedia({
video:true,
audio:true
}).then(stream=>{
this.AddVideoStream(Myvideo,stream)
socket.on('user-connected',userId=>{
connectToNewUser(userId,stream)
console.log('new user',userId)
})
})
myPeer.on('open',id =>{
socket.emit('join-class',this.props.match.params.id,id)
})
} catch (error) {
console.log('error',error)
}
this.checkIfClassTrue()
//get new user video stream and connect
async function connectToNewUser(userId,stream){
const call = await myPeer.call(userId,stream)
const video = document.createElement('video')
call.on('stream',userVideostream=>{
this.AddVideoStream(video,userVideostream)
})
call.on('close',()=>{
video.remove()
})
console.log('connected with user')
}
}
//check if its class
checkIfClassTrue = async()=>{
const response = await fetch(`http://localhost:4000/liveclass/${this.props.match.params.id}`)
const Parse = await response.json()
this.setState({classStatus:Parse})
}
//Add video stream
AddVideoStream = async(video,stream) =>{
const videoGrid = document.getElementById('video-grid')
video.srcObject = stream
video.addEventListener('loadedmetadata', () =>{
video.play()
})
videoGrid.append(video)
}
render(){
return(
<div>
{
this.state.classStatus === 'Not found'?
'not found':<div id="video-grid"></div>
}
</div>
)
}
}
export default LiveClass
连接其他浏览器时出错
Error1: Uncaught Error: The error you provided does not contain a stack trace.
Error 2: Uncaught (in promise) DOMException: Could not start video source
在大多数操作系统中,两个不同的进程不能同时打开相机。一种直接的选择是购买多台相机。
对于测试,Firefox media.navigator.streams.fake(在 about:config 中)和 Chrome 的 --use-fake-device-for-media-stream 选项很有用。
大家好,我正在尝试 运行 使用反应、节点、套接字和 peerjs 进行 webrtc 视频通话,如果我尝试使用 chrome 开始视频聊天,如果我 运行 chrome 作为私人并作为第二个用户使用视频连接 link 它有效,但如果我尝试使用相同的视频从另一个浏览器连接 link 例如边缘或歌剧它不起作用而不是它控制台记录错误..
我的代码
import React from 'react'
import io from 'socket.io-client'
import Peer from 'peerjs'
import './ClassWall.css'
const socket = io.connect('http://localhost:4000/')
class LiveClass extends React.Component{
constructor(){
super()
this.state = {
userId :'',
classStatus: '',
}
}
async componentDidMount(){
const videoGrid = document.getElementById('video-grid')
const Myvideo = document.createElement('video')
Myvideo.muted = true
//set user id of logged in user
try {
const response = await fetch('http://localhost:4000/Auth//UserID/id',{
headers:{token:localStorage.token}
})
const Parse = await response.json()
this.setState({userId:Parse})
} catch (error) {
}
//get user id to connect through peer
const myPeer = new Peer(this.state.userId,{
host: '/',
port:4001
})
//connect and share video stream
try {
navigator.mediaDevices.getUserMedia({
video:true,
audio:true
}).then(stream=>{
this.AddVideoStream(Myvideo,stream)
socket.on('user-connected',userId=>{
connectToNewUser(userId,stream)
console.log('new user',userId)
})
})
myPeer.on('open',id =>{
socket.emit('join-class',this.props.match.params.id,id)
})
} catch (error) {
console.log('error',error)
}
this.checkIfClassTrue()
//get new user video stream and connect
async function connectToNewUser(userId,stream){
const call = await myPeer.call(userId,stream)
const video = document.createElement('video')
call.on('stream',userVideostream=>{
this.AddVideoStream(video,userVideostream)
})
call.on('close',()=>{
video.remove()
})
console.log('connected with user')
}
}
//check if its class
checkIfClassTrue = async()=>{
const response = await fetch(`http://localhost:4000/liveclass/${this.props.match.params.id}`)
const Parse = await response.json()
this.setState({classStatus:Parse})
}
//Add video stream
AddVideoStream = async(video,stream) =>{
const videoGrid = document.getElementById('video-grid')
video.srcObject = stream
video.addEventListener('loadedmetadata', () =>{
video.play()
})
videoGrid.append(video)
}
render(){
return(
<div>
{
this.state.classStatus === 'Not found'?
'not found':<div id="video-grid"></div>
}
</div>
)
}
}
export default LiveClass
连接其他浏览器时出错
Error1: Uncaught Error: The error you provided does not contain a stack trace.
Error 2: Uncaught (in promise) DOMException: Could not start video source
在大多数操作系统中,两个不同的进程不能同时打开相机。一种直接的选择是购买多台相机。
对于测试,Firefox media.navigator.streams.fake(在 about:config 中)和 Chrome 的 --use-fake-device-for-media-stream 选项很有用。