When state is RTCICEConnectionClosed in didObserveICEConnectionStateChange, peerID is nil.
- (void)peerConnection:(RTCPeerConnection *)peerConnection iceConnectionChanged:(RTCICEConnectionState)newState {
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate webRTC:self didObserveICEConnectionStateChange:newState forPeerWithID:[self identifierForPeer:peerConnection]];
});
}
Because after calling removePeerConnectionForID, RTCPeerConnection will be removed from self.peerConnections, and it is closed. Then, the peerConnection:(RTCPeerConnection *)peerConnection iceConnectionChanged:(RTCICEConnectionState)newState is called, [self identifierForPeer:peerConnection] will always be nil.
- (void)removePeerConnectionForID:(NSString *)identifier {
RTCPeerConnection* peer = self.peerConnections[identifier];
[self.peerConnections removeObjectForKey:identifier];
[self.peerToRoleMap removeObjectForKey:identifier];
[peer close];
}
When state is RTCICEConnectionClosed in didObserveICEConnectionStateChange, peerID is nil.
Because after calling
removePeerConnectionForID, RTCPeerConnection will be removed fromself.peerConnections, and it is closed. Then, thepeerConnection:(RTCPeerConnection *)peerConnection iceConnectionChanged:(RTCICEConnectionState)newStateis called,[self identifierForPeer:peerConnection]will always be nil.