🐛 FIX: 批量订阅

This commit is contained in:
dexter
2022-11-30 13:17:57 +08:00
parent 244985d683
commit 190a0161ba
2 changed files with 23 additions and 6 deletions

View File

@@ -53,6 +53,7 @@ func (suber *WebRTCBatcher) Start() (err error) {
func (suber *WebRTCBatcher) Signal(msg DataChannelMessage) {
var s Signal
var removeMap = map[string]string{"type": "remove", "streamPath": ""}
// var offer SessionDescription
if err := json.Unmarshal(msg.Data, &s); err != nil {
WebRTCPlugin.Error("Signal", zap.Error(err))
@@ -66,13 +67,27 @@ func (suber *WebRTCBatcher) Signal(msg DataChannelMessage) {
for _, streamPath := range s.StreamList {
sub := &WebRTCBatchSubscriber{}
sub.WebRTCIO = suber.WebRTCIO
if err = WebRTCPlugin.Subscribe(streamPath, sub); err == nil {
if err = WebRTCPlugin.SubscribeExist(streamPath, sub); err == nil {
suber.subscribers = append(suber.subscribers, sub)
go func() {
sub.PlayRTP()
b, _ := json.Marshal(map[string]string{"type": "remove", "streamPath": streamPath})
if sub.audioSender != nil {
suber.RemoveTrack(sub.audioSender)
}
if sub.videoSender != nil {
suber.RemoveTrack(sub.videoSender)
}
if sub.DC != nil {
sub.DC.Close()
}
removeMap["streamPath"] = streamPath
b, _ := json.Marshal(removeMap)
suber.signalChannel.SendText(string(b))
}()
} else {
removeMap["streamPath"] = streamPath
b, _ := json.Marshal(removeMap)
suber.signalChannel.SendText(string(b))
}
}
var answer string