@@ -75,8 +75,7 @@ type PeerConnection struct {
75
75
76
76
// ICEConnectionState attribute returns the ICE connection state of the
77
77
// PeerConnection instance.
78
- // ICEConnectionState ICEConnectionState // FIXME SWAP-FOR-THIS
79
- ICEConnectionState ice.ConnectionState // FIXME REMOVE
78
+ iceConnectionState ICEConnectionState
80
79
81
80
// ConnectionState attribute returns the connection state of the
82
81
// PeerConnection instance.
@@ -103,7 +102,7 @@ type PeerConnection struct {
103
102
// OnConnectionStateChange func() // FIXME NOT-USED
104
103
105
104
onSignalingStateChangeHandler func (SignalingState )
106
- onICEConnectionStateChangeHandler func (ice. ConnectionState )
105
+ onICEConnectionStateChangeHandler func (ICEConnectionState )
107
106
onTrackHandler func (* Track )
108
107
onDataChannelHandler func (* DataChannel )
109
108
@@ -130,13 +129,12 @@ func (api *API) NewPeerConnection(configuration Configuration) (*PeerConnection,
130
129
Certificates : []Certificate {},
131
130
ICECandidatePoolSize : 0 ,
132
131
},
133
- isClosed : false ,
134
- negotiationNeeded : false ,
135
- lastOffer : "" ,
136
- lastAnswer : "" ,
137
- SignalingState : SignalingStateStable ,
138
- // ICEConnectionState: ICEConnectionStateNew, // FIXME SWAP-FOR-THIS
139
- ICEConnectionState : ice .ConnectionStateNew , // FIXME REMOVE
132
+ isClosed : false ,
133
+ negotiationNeeded : false ,
134
+ lastOffer : "" ,
135
+ lastAnswer : "" ,
136
+ SignalingState : SignalingStateStable ,
137
+ iceConnectionState : ICEConnectionStateNew ,
140
138
ICEGatheringState : ICEGatheringStateNew ,
141
139
ConnectionState : PeerConnectionStateNew ,
142
140
dataChannels : make (map [uint16 ]* DataChannel ),
@@ -300,13 +298,13 @@ func (pc *PeerConnection) onTrack(t *Track) (done chan struct{}) {
300
298
301
299
// OnICEConnectionStateChange sets an event handler which is called
302
300
// when an ICE connection state is changed.
303
- func (pc * PeerConnection ) OnICEConnectionStateChange (f func (ice. ConnectionState )) {
301
+ func (pc * PeerConnection ) OnICEConnectionStateChange (f func (ICEConnectionState )) {
304
302
pc .mu .Lock ()
305
303
defer pc .mu .Unlock ()
306
304
pc .onICEConnectionStateChangeHandler = f
307
305
}
308
306
309
- func (pc * PeerConnection ) onICEConnectionStateChange (cs ice. ConnectionState ) (done chan struct {}) {
307
+ func (pc * PeerConnection ) onICEConnectionStateChange (cs ICEConnectionState ) (done chan struct {}) {
310
308
pc .mu .RLock ()
311
309
hdlr := pc .onICEConnectionStateChangeHandler
312
310
pc .mu .RUnlock ()
@@ -481,10 +479,27 @@ func (pc *PeerConnection) createICETransport() *ICETransport {
481
479
t := pc .api .NewICETransport (pc .iceGatherer )
482
480
483
481
t .OnConnectionStateChange (func (state ICETransportState ) {
484
- // We convert the state back to the ICE state to not brake the
485
- // existing public API at this point.
486
- iceState := state .toICE ()
487
- pc .iceStateChange (iceState )
482
+ cs := ICEConnectionStateNew
483
+ switch state {
484
+ case ICETransportStateNew :
485
+ cs = ICEConnectionStateNew
486
+ case ICETransportStateChecking :
487
+ cs = ICEConnectionStateChecking
488
+ case ICETransportStateConnected :
489
+ cs = ICEConnectionStateConnected
490
+ case ICETransportStateCompleted :
491
+ cs = ICEConnectionStateCompleted
492
+ case ICETransportStateFailed :
493
+ cs = ICEConnectionStateFailed
494
+ case ICETransportStateDisconnected :
495
+ cs = ICEConnectionStateDisconnected
496
+ case ICETransportStateClosed :
497
+ cs = ICEConnectionStateClosed
498
+ default :
499
+ pcLog .Warnf ("OnConnectionStateChange: unhandled ICE state: %s" , state )
500
+ return
501
+ }
502
+ pc .iceStateChange (cs )
488
503
})
489
504
490
505
return t
@@ -1037,6 +1052,15 @@ func (pc *PeerConnection) AddICECandidate(s string) error {
1037
1052
return pc .iceTransport .AddRemoteCandidate (candidate )
1038
1053
}
1039
1054
1055
+ // ICEConnectionState returns the ICE connection state of the
1056
+ // PeerConnection instance.
1057
+ func (pc * PeerConnection ) ICEConnectionState () ICEConnectionState {
1058
+ pc .mu .RLock ()
1059
+ defer pc .mu .RUnlock ()
1060
+
1061
+ return pc .iceConnectionState
1062
+ }
1063
+
1040
1064
// ------------------------------------------------------------------------
1041
1065
// --- FIXME - BELOW CODE NEEDS RE-ORGANIZATION - https://w3c.github.io/webrtc-pc/#rtp-media-api
1042
1066
// ------------------------------------------------------------------------
@@ -1333,9 +1357,9 @@ func flattenErrs(errs []error) error {
1333
1357
return fmt .Errorf (strings .Join (errstrings , "\n " ))
1334
1358
}
1335
1359
1336
- func (pc * PeerConnection ) iceStateChange (newState ice. ConnectionState ) {
1360
+ func (pc * PeerConnection ) iceStateChange (newState ICEConnectionState ) {
1337
1361
pc .mu .Lock ()
1338
- pc .ICEConnectionState = newState
1362
+ pc .iceConnectionState = newState
1339
1363
pc .mu .Unlock ()
1340
1364
1341
1365
pc .onICEConnectionStateChange (newState )
0 commit comments