mirror of
https://github.com/langhuihui/monibuca.git
synced 2025-12-24 13:48:04 +08:00
fix: webrtc batch bug
This commit is contained in:
@@ -2,6 +2,7 @@ package plugin_webrtc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -92,6 +93,30 @@ func (wsh *WebSocketHandler) Go() (err error) {
|
||||
}); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
wsh.OnICECandidate(func(ice *ICECandidate) {
|
||||
if ice != nil {
|
||||
wsh.Info(ice.ToJSON().Candidate)
|
||||
}
|
||||
})
|
||||
// 监听ICE连接状态变化
|
||||
wsh.OnICEConnectionStateChange(func(state ICEConnectionState) {
|
||||
wsh.Debug("ICE connection state changed", "state", state.String())
|
||||
if state == ICEConnectionStateFailed {
|
||||
wsh.Error("ICE connection failed")
|
||||
}
|
||||
})
|
||||
|
||||
wsh.OnConnectionStateChange(func(state PeerConnectionState) {
|
||||
wsh.Info("Connection State has changed:" + state.String())
|
||||
switch state {
|
||||
case PeerConnectionStateConnected:
|
||||
|
||||
case PeerConnectionStateDisconnected, PeerConnectionStateFailed, PeerConnectionStateClosed:
|
||||
wsh.Stop(errors.New("connection state:" + state.String()))
|
||||
}
|
||||
})
|
||||
|
||||
// 创建并发送应答
|
||||
if answer, err := wsh.GetAnswer(); err == nil {
|
||||
wsh.sendAnswer(answer.SDP)
|
||||
|
||||
@@ -452,32 +452,6 @@ type SingleConnection struct {
|
||||
Connection
|
||||
}
|
||||
|
||||
func (c *SingleConnection) Start() (err error) {
|
||||
c.OnICECandidate(func(ice *ICECandidate) {
|
||||
if ice != nil {
|
||||
c.Info(ice.ToJSON().Candidate)
|
||||
}
|
||||
})
|
||||
// 监听ICE连接状态变化
|
||||
c.OnICEConnectionStateChange(func(state ICEConnectionState) {
|
||||
c.Debug("ICE connection state changed", "state", state.String())
|
||||
if state == ICEConnectionStateFailed {
|
||||
c.Error("ICE connection failed")
|
||||
}
|
||||
})
|
||||
|
||||
c.OnConnectionStateChange(func(state PeerConnectionState) {
|
||||
c.Info("Connection State has changed:" + state.String())
|
||||
switch state {
|
||||
case PeerConnectionStateConnected:
|
||||
|
||||
case PeerConnectionStateDisconnected, PeerConnectionStateFailed, PeerConnectionStateClosed:
|
||||
c.Stop(errors.New("connection state:" + state.String()))
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (c *SingleConnection) Receive() {
|
||||
c.OnTrack(func(track *TrackRemote, receiver *RTPReceiver) {
|
||||
c.Info("OnTrack", "kind", track.Kind().String(), "payloadType", uint8(track.Codec().PayloadType))
|
||||
|
||||
Reference in New Issue
Block a user