mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
refactor: move media channel handling to common/ and setup duplex channel
a duplex media channel should be more realistic, you generally both send and receive media when doing video call and stuff
This commit is contained in:
parent
ff738ff045
commit
01bde142d4
5 changed files with 187 additions and 102 deletions
|
@ -48,6 +48,7 @@ import (
|
|||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/constants"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/event"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/media"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/namematcher"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/task"
|
||||
|
@ -451,18 +452,13 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(
|
|||
return nil, fmt.Errorf("accept: NewPeerConnection: %s", err)
|
||||
}
|
||||
|
||||
pc.OnTrack(func(remote *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
|
||||
log.Printf("Track has started streamId(%s) id(%s) rid(%s) \n", remote.StreamID(), remote.ID(), remote.RID())
|
||||
|
||||
for {
|
||||
rtcpBuf := make([]byte, 1500)
|
||||
for {
|
||||
if _, _, err := receiver.Read(rtcpBuf); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
// Start duplex media handling (both incoming and outgoing tracks)
|
||||
mediaChannel := media.NewMediaChannel()
|
||||
err = mediaChannel.Start(pc)
|
||||
if err != nil {
|
||||
log.Printf("Failed to setup proxy media channel: %v", err)
|
||||
}
|
||||
|
||||
pc.OnDataChannel(func(dc *webrtc.DataChannel) {
|
||||
log.Printf("New Data Channel %s-%d\n", dc.Label(), dc.ID())
|
||||
|
@ -512,6 +508,9 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(
|
|||
}
|
||||
sf.EventDispatcher.OnNewSnowflakeEvent(event.EventOnProxyConnectionOver{Country: country})
|
||||
|
||||
// Clean up media channel
|
||||
mediaChannel.Stop()
|
||||
|
||||
conn.dc = nil
|
||||
dc.Close()
|
||||
pw.Close()
|
||||
|
@ -838,7 +837,7 @@ func (sf *SnowflakeProxy) Start() error {
|
|||
err = sf.checkNATType(config, sf.NATProbeURL)
|
||||
if err != nil {
|
||||
// non-fatal error. Log it and continue
|
||||
log.Printf(err.Error())
|
||||
log.Printf("%s", err.Error())
|
||||
setCurrentNATType(NATUnknown)
|
||||
}
|
||||
sf.EventDispatcher.OnNewSnowflakeEvent(event.EventOnCurrentNATTypeDetermined{CurNATType: getCurrentNATType()})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue