WebRTC SetVideoID.

This commit is contained in:
Miroslav Šedivý 2021-02-05 17:57:33 +01:00
parent aa7a131da2
commit f62d36ac4f
3 changed files with 16 additions and 9 deletions

View File

@ -5,6 +5,7 @@ import "github.com/pion/webrtc/v3"
type WebRTCPeer interface { type WebRTCPeer interface {
SignalAnswer(sdp string) error SignalAnswer(sdp string) error
SignalCandidate(candidate webrtc.ICECandidateInit) error SignalCandidate(candidate webrtc.ICECandidateInit) error
SetVideoID(videoID string) error
Destroy() error Destroy() error
} }

View File

@ -137,7 +137,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session) (*webrtc.Sess
}) })
} }
audioTransceiver, err := connection.AddTransceiverFromTrack(manager.audioTrack, webrtc.RtpTransceiverInit{ _, err = connection.AddTransceiverFromTrack(manager.audioTrack, webrtc.RtpTransceiverInit{
Direction: webrtc.RTPTransceiverDirectionSendonly, Direction: webrtc.RTPTransceiverDirectionSendonly,
}) })
if err != nil { if err != nil {
@ -151,7 +151,8 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session) (*webrtc.Sess
return nil, err return nil, err
} }
if _, err := connection.CreateDataChannel("data", nil); err != nil { _, err = connection.CreateDataChannel("data", nil)
if err != nil {
return nil, err return nil, err
} }
@ -206,7 +207,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session) (*webrtc.Sess
settings: settings, settings: settings,
connection: connection, connection: connection,
configuration: configuration, configuration: configuration,
audioTransceiver: audioTransceiver, videoTracks: manager.videoTracks,
videoTransceiver: videoTransceiver, videoTransceiver: videoTransceiver,
}) })

View File

@ -1,6 +1,10 @@
package webrtc package webrtc
import "github.com/pion/webrtc/v3" import (
"fmt"
"github.com/pion/webrtc/v3"
)
type WebRTCPeerCtx struct { type WebRTCPeerCtx struct {
api *webrtc.API api *webrtc.API
@ -8,7 +12,7 @@ type WebRTCPeerCtx struct {
settings *webrtc.SettingEngine settings *webrtc.SettingEngine
connection *webrtc.PeerConnection connection *webrtc.PeerConnection
configuration *webrtc.Configuration configuration *webrtc.Configuration
audioTransceiver *webrtc.RTPTransceiver videoTracks map[string]*webrtc.TrackLocalStaticSample
videoTransceiver *webrtc.RTPTransceiver videoTransceiver *webrtc.RTPTransceiver
} }
@ -23,11 +27,12 @@ func (webrtc_peer *WebRTCPeerCtx) SignalCandidate(candidate webrtc.ICECandidateI
return webrtc_peer.connection.AddICECandidate(candidate) return webrtc_peer.connection.AddICECandidate(candidate)
} }
func (webrtc_peer *WebRTCPeerCtx) ReplaceAudioTrack(track webrtc.TrackLocal) error { func (webrtc_peer *WebRTCPeerCtx) SetVideoID(videoID string) error {
return webrtc_peer.audioTransceiver.Sender().ReplaceTrack(track) track, ok := webrtc_peer.videoTracks[videoID]
} if !ok {
return fmt.Errorf("videoID not found in available tracks")
}
func (webrtc_peer *WebRTCPeerCtx) ReplaceVideoTrack(track webrtc.TrackLocal) error {
return webrtc_peer.videoTransceiver.Sender().ReplaceTrack(track) return webrtc_peer.videoTransceiver.Sender().ReplaceTrack(track)
} }