mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
WebRTC channel from server.
This commit is contained in:
parent
90aa2ce51a
commit
8a3b3f14cb
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user