我正在使用webrtc实现视频会议。我已经完成了,挂断按钮,但当我按下这个按钮并再次拨打电话时,视频会议效果不佳。
连接已完成,因为我看到了,但遥控器的相机无法开启。有时会出现这样的消息:“在SetRemoteDescription之前无法调用createAnswer。”。但是第一次从未出现过。
这是客户端中的挂断代码(在coffeeScript中):
@localStream.stop() if @localStream
@remoteVideo.stop()
@localVideo.stop()
我不知道为什么当我做挂机后再次打电话时,这个电话不起作用。
join: (video=true, friend) =>
parse_friend =
id : friend?.id
username : friend?.username
mail : friend?.mail
avatar : friend?.avatar
session = JSON.parse localStorage.getItem KEY
SOCKET.emit 'join', session.access_token, video, parse_friend
SOCKET.on 'ready', @readyToCall
SOCKET.on 'offer', @onOffer
token: =>
SOCKET.on 'token', @onToken @createOffer
SOCKET.emit 'token'
onToken: (callback) =>
(token) =>
@peerConnection = new RTCPeerConnection iceServers: configuration.iceServers
@peerConnection.addStream @localStream
@peerConnection.onicecandidate = @onIceCandidate
@peerConnection.onaddstream = @onAddStream
SOCKET.on 'candidate', @onCandidate
SOCKET.on 'answer', @onAnswer
callback()
return
hangUp: (friend) =>
session = JSON.parse localStorage.getItem KEY
@localStream.stop() if @localStream
SOCKET.emit 'hangUp', session.id, friend
onFinish: (value) =>
@localStream.stop() if @localStream
if @peerConnection then @peerConnection.close()
@trigger 'finish', value