55 lines
2.9 KiB
Diff
55 lines
2.9 KiB
Diff
diff --git a/node_modules/react-native-tcp-socket/ios/TcpSockets.m b/node_modules/react-native-tcp-socket/ios/TcpSockets.m
|
|
index 0fe15d2..a5553c6 100644
|
|
--- a/node_modules/react-native-tcp-socket/ios/TcpSockets.m
|
|
+++ b/node_modules/react-native-tcp-socket/ios/TcpSockets.m
|
|
@@ -219,20 +219,35 @@ - (void)onWrittenData:(TcpSocketClient *)client msgId:(NSNumber *)msgId {
|
|
|
|
- (void)onConnect:(TcpSocketClient *)client {
|
|
GCDAsyncSocket *socket = [client getSocket];
|
|
- [self sendEventWithName:@"connect"
|
|
- body:@{
|
|
- @"id" : client.id,
|
|
- @"connection" : @{
|
|
- @"localAddress" : [socket localHost],
|
|
- @"localPort" :
|
|
- [NSNumber numberWithInt:[socket localPort]],
|
|
- @"remoteAddress" : [socket connectedHost],
|
|
- @"remotePort" : [NSNumber
|
|
- numberWithInt:[socket connectedPort]],
|
|
- @"remoteFamily" : [socket isIPv4] ? @"IPv4"
|
|
- : @"IPv6"
|
|
- }
|
|
- }];
|
|
+ NSString *localAddress = [socket localHost];
|
|
+ NSString *remoteAddress = [socket connectedHost];
|
|
+ // The socket can disconnect between this callback being queued and run,
|
|
+ // in which case the address getters return nil. Building the connection
|
|
+ // dictionary with a nil value throws NSInvalidArgumentException and
|
|
+ // crashes the app, so emit an error instead of the connect event -
|
|
+ // skipping silently would hang the JS side waiting for a callback.
|
|
+ if (localAddress != nil && remoteAddress != nil) {
|
|
+ [self sendEventWithName:@"connect"
|
|
+ body:@{
|
|
+ @"id" : client.id,
|
|
+ @"connection" : @{
|
|
+ @"localAddress" : localAddress,
|
|
+ @"localPort" :
|
|
+ [NSNumber numberWithInt:[socket localPort]],
|
|
+ @"remoteAddress" : remoteAddress,
|
|
+ @"remotePort" : [NSNumber
|
|
+ numberWithInt:[socket connectedPort]],
|
|
+ @"remoteFamily" : [socket isIPv4] ? @"IPv4"
|
|
+ : @"IPv6"
|
|
+ }
|
|
+ }];
|
|
+ } else {
|
|
+ [self sendEventWithName:@"error"
|
|
+ body:@{
|
|
+ @"id" : client.id,
|
|
+ @"error" : @"Socket disconnected before connect could be reported"
|
|
+ }];
|
|
+ }
|
|
}
|
|
|
|
- (void)onListen:(TcpSocketClient *)server {
|