WebRTC channel from server.

This commit is contained in:
Miroslav Šedivý 2021-02-12 23:45:16 +01:00
parent 90aa2ce51a
commit 8a3b3f14cb

View File

@ -188,7 +188,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
return nil, err
}
_, err = connection.CreateDataChannel("data", nil)
dataChannel, err := connection.CreateDataChannel("data", nil)
if err != nil {
return nil, err
}
@ -213,12 +213,6 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
}
}
peer := &WebRTCPeerCtx{
api: api,
connection: connection,
changeVideo: changeVideo,
}
connection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
switch state {
case webrtc.PeerConnectionStateConnected:
@ -238,10 +232,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
}
})
connection.OnDataChannel(func(channel *webrtc.DataChannel) {
peer.dataChannel = channel
channel.OnMessage(func(message webrtc.DataChannelMessage) {
dataChannel.OnMessage(func(message webrtc.DataChannelMessage) {
if !session.IsHost() {
return
}
@ -250,9 +241,14 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
logger.Warn().Err(err).Msg("data handle failed")
}
})
session.SetWebRTCPeer(&WebRTCPeerCtx{
api: api,
connection: connection,
changeVideo: changeVideo,
dataChannel: dataChannel,
})
session.SetWebRTCPeer(peer)
return connection.LocalDescription(), nil
}