@@ -36,7 +36,7 @@ const (
3636// peer-to-peer communications with another RTCPeerConnection instance in a
3737// browser, or to another endpoint implementing the required protocols.
3838type RTCPeerConnection struct {
39- sync.RWMutex
39+ mu sync.RWMutex
4040
4141 configuration RTCConfiguration
4242
@@ -237,15 +237,15 @@ func (pc *RTCPeerConnection) initConfiguration(configuration RTCConfiguration) e
237237// OnSignalingStateChange sets an event handler which is invoked when the
238238// peer connection's signaling state changes
239239func (pc * RTCPeerConnection ) OnSignalingStateChange (f func (RTCSignalingState )) {
240- pc .Lock ()
241- defer pc .Unlock ()
240+ pc .mu . Lock ()
241+ defer pc .mu . Unlock ()
242242 pc .onSignalingStateChangeHandler = f
243243}
244244
245245func (pc * RTCPeerConnection ) onSignalingStateChange (newState RTCSignalingState ) (done chan struct {}) {
246- pc .RLock ()
246+ pc .mu . RLock ()
247247 hdlr := pc .onSignalingStateChangeHandler
248- pc .RUnlock ()
248+ pc .mu . RUnlock ()
249249
250250 pcLog .Infof ("signaling state changed to %s" , newState )
251251 done = make (chan struct {})
@@ -265,23 +265,23 @@ func (pc *RTCPeerConnection) onSignalingStateChange(newState RTCSignalingState)
265265// OnDataChannel sets an event handler which is invoked when a data
266266// channel message arrives from a remote peer.
267267func (pc * RTCPeerConnection ) OnDataChannel (f func (* RTCDataChannel )) {
268- pc .Lock ()
269- defer pc .Unlock ()
268+ pc .mu . Lock ()
269+ defer pc .mu . Unlock ()
270270 pc .onDataChannelHandler = f
271271}
272272
273273// OnTrack sets an event handler which is called when remote track
274274// arrives from a remote peer.
275275func (pc * RTCPeerConnection ) OnTrack (f func (* RTCTrack )) {
276- pc .Lock ()
277- defer pc .Unlock ()
276+ pc .mu . Lock ()
277+ defer pc .mu . Unlock ()
278278 pc .onTrackHandler = f
279279}
280280
281281func (pc * RTCPeerConnection ) onTrack (t * RTCTrack ) (done chan struct {}) {
282- pc .RLock ()
282+ pc .mu . RLock ()
283283 hdlr := pc .onTrackHandler
284- pc .RUnlock ()
284+ pc .mu . RUnlock ()
285285
286286 pcLog .Debugf ("got new track: %+v" , t )
287287 done = make (chan struct {})
@@ -301,15 +301,15 @@ func (pc *RTCPeerConnection) onTrack(t *RTCTrack) (done chan struct{}) {
301301// OnICEConnectionStateChange sets an event handler which is called
302302// when an ICE connection state is changed.
303303func (pc * RTCPeerConnection ) OnICEConnectionStateChange (f func (ice.ConnectionState )) {
304- pc .Lock ()
305- defer pc .Unlock ()
304+ pc .mu . Lock ()
305+ defer pc .mu . Unlock ()
306306 pc .onICEConnectionStateChangeHandler = f
307307}
308308
309309func (pc * RTCPeerConnection ) onICEConnectionStateChange (cs ice.ConnectionState ) (done chan struct {}) {
310- pc .RLock ()
310+ pc .mu . RLock ()
311311 hdlr := pc .onICEConnectionStateChangeHandler
312- pc .RUnlock ()
312+ pc .mu . RUnlock ()
313313
314314 pcLog .Infof ("ICE connection state changed: %s" , cs )
315315 done = make (chan struct {})
@@ -773,9 +773,9 @@ func (pc *RTCPeerConnection) SetRemoteDescription(desc RTCSessionDescription) er
773773
774774 // Wire up the on datachannel handler
775775 sctp .OnDataChannel (func (d * RTCDataChannel ) {
776- pc .RLock ()
776+ pc .mu . RLock ()
777777 hdlr := pc .onDataChannelHandler
778- pc .RUnlock ()
778+ pc .mu . RUnlock ()
779779 if hdlr != nil {
780780 hdlr (d )
781781 }
@@ -1037,8 +1037,8 @@ func (pc *RTCPeerConnection) AddIceCandidate(s string) error {
10371037
10381038// GetSenders returns the RTCRtpSender that are currently attached to this RTCPeerConnection
10391039func (pc * RTCPeerConnection ) GetSenders () []* RTCRtpSender {
1040- pc .Lock ()
1041- defer pc .Unlock ()
1040+ pc .mu . Lock ()
1041+ defer pc .mu . Unlock ()
10421042
10431043 result := make ([]* RTCRtpSender , len (pc .rtpTransceivers ))
10441044 for i , tranceiver := range pc .rtpTransceivers {
@@ -1051,8 +1051,8 @@ func (pc *RTCPeerConnection) GetSenders() []*RTCRtpSender {
10511051
10521052// GetReceivers returns the RTCRtpReceivers that are currently attached to this RTCPeerConnection
10531053func (pc * RTCPeerConnection ) GetReceivers () []* RTCRtpReceiver {
1054- pc .Lock ()
1055- defer pc .Unlock ()
1054+ pc .mu . Lock ()
1055+ defer pc .mu . Unlock ()
10561056
10571057 result := make ([]* RTCRtpReceiver , len (pc .rtpTransceivers ))
10581058 for i , tranceiver := range pc .rtpTransceivers {
@@ -1066,8 +1066,8 @@ func (pc *RTCPeerConnection) GetReceivers() []*RTCRtpReceiver {
10661066
10671067// GetTransceivers returns the RTCRtpTransceiver that are currently attached to this RTCPeerConnection
10681068func (pc * RTCPeerConnection ) GetTransceivers () []* RTCRtpTransceiver {
1069- pc .Lock ()
1070- defer pc .Unlock ()
1069+ pc .mu . Lock ()
1070+ defer pc .mu . Unlock ()
10711071
10721072 return pc .rtpTransceivers
10731073}
@@ -1386,9 +1386,9 @@ func flattenErrs(errs []error) error {
13861386}
13871387
13881388func (pc * RTCPeerConnection ) iceStateChange (newState ice.ConnectionState ) {
1389- pc .Lock ()
1389+ pc .mu . Lock ()
13901390 pc .IceConnectionState = newState
1391- pc .Unlock ()
1391+ pc .mu . Unlock ()
13921392
13931393 pc .onICEConnectionStateChange (newState )
13941394}
@@ -1535,8 +1535,8 @@ func (pc *RTCPeerConnection) newRTCRtpTransceiver(
15351535 Sender : sender ,
15361536 Direction : direction ,
15371537 }
1538- pc .Lock ()
1539- defer pc .Unlock ()
1538+ pc .mu . Lock ()
1539+ defer pc .mu . Unlock ()
15401540 pc .rtpTransceivers = append (pc .rtpTransceivers , t )
15411541 return t
15421542}
0 commit comments