2015-05-14 19:28:09 +03:00
|
|
|
/**
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-05-14 19:28:09 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-05-14 19:28:09 +03:00
|
|
|
*/
|
|
|
|
|
CocoaPods frameworks compatibility: Step 2 (#25619)
Summary:
This is my proposal for fixing `use_frameworks!` compatibility without breaking all `<React/*>` imports I outlined in https://github.com/facebook/react-native/pull/25393#issuecomment-508457700. If accepted, it will fix https://github.com/facebook/react-native/issues/25349.
It builds on the changes I made in https://github.com/facebook/react-native/pull/25496 by ensuring each podspec has a unique value for `header_dir` so that framework imports do not conflict. Every podspec which should be included in the `<React/*>` namespace now includes it's headers from `React-Core.podspec`.
The following pods can still be imported with `<React/*>` and so should not have breaking changes: `React-ART`,`React-DevSupport`, `React-CoreModules`, `React-RCTActionSheet`, `React-RCTAnimation`, `React-RCTBlob`, `React-RCTImage`, `React-RCTLinking`, `React-RCTNetwork`, `React-RCTPushNotification`, `React-RCTSettings`, `React-RCTText`, `React-RCTSettings`, `React-RCTVibration`, `React-RCTWebSocket` .
There are still a few breaking changes which I hope will be acceptable:
- `React-Core.podspec` has been moved to the root of the project. Any `Podfile` that references it will need to update the path.
- ~~`React-turbomodule-core`'s headers now live under `<turbomodule/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- ~~`React-turbomodulesamples`'s headers now live under `<turbomodulesamples/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- ~~`React-TypeSaferty`'s headers now live under `<TypeSafety/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511040967.
- ~~`React-jscallinvoker`'s headers now live under `<jscallinvoker/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- Each podspec now uses `s.static_framework = true`. This means that a minimum of CocoaPods 1.5 ([released in April 2018](http://blog.cocoapods.org/CocoaPods-1.5.0/)) is now required. This is needed so that the ` __has_include` conditions can still work when frameworks are enabled.
Still to do:
- ~~Including `React-turbomodule-core` with `use_frameworks!` enabled causes the C++ import failures we saw in https://github.com/facebook/react-native/issues/25349. I'm sure it will be possible to fix this but I need to dig deeper (perhaps a custom modulemap would be needed).~~ Addressed by https://github.com/facebook/react-native/pull/25619/commits/33573511f02f3502a28bad48e085e9a4b8608302.
- I haven't got Fabric working yet. I wonder if it would be acceptable to move Fabric out of the `<React/*>` namespace since it is new? �
## Changelog
[iOS] [Fixed] - Fixed compatibility with CocoaPods frameworks.
Pull Request resolved: https://github.com/facebook/react-native/pull/25619
Test Plan:
### FB
```
buck build catalyst
```
### Sample Project
Everything should work exactly as before, where `use_frameworks!` is not in `Podfile`s. I have a branch on my [sample project](https://github.com/jtreanor/react-native-cocoapods-frameworks) here which has `use_frameworks!` in its `Podfile` to demonstrate this is fixed.
You can see that it works with these steps:
1. `git clone git@github.com:jtreanor/react-native-cocoapods-frameworks.git`
2. `git checkout fix-frameworks-subspecs`
3. `cd ios && pod install`
4. `cd .. && react-native run-ios`
The sample app will build and run successfully. To see that it still works without frameworks, remove `use_frameworks!` from the `Podfile` and do steps 3 and 4 again.
### RNTesterPods
`RNTesterPodsPods` can now work with or without `use_frameworks!`.
1. Go to the `RNTester` directory and run `pod install`.
2. Run the tests in `RNTesterPods.xcworkspace` to see that everything still works fine.
3. Uncomment the `use_frameworks!` line at the top of `RNTester/Podfile` and run `pod install` again.
4. Run the tests again and see that it still works with frameworks enabled.
Reviewed By: PeteTheHeat
Differential Revision: D16465247
Pulled By: PeteTheHeat
fbshipit-source-id: cad837e9cced06d30cc5b372af1c65c7780b9e7a
2019-07-25 08:26:42 +03:00
|
|
|
#import <React/RCTWebSocketModule.h>
|
2015-05-14 19:28:09 +03:00
|
|
|
|
2016-07-18 17:12:19 +03:00
|
|
|
#import <objc/runtime.h>
|
|
|
|
|
2016-11-23 18:47:52 +03:00
|
|
|
#import <React/RCTConvert.h>
|
|
|
|
#import <React/RCTUtils.h>
|
|
|
|
|
CocoaPods frameworks compatibility: Step 2 (#25619)
Summary:
This is my proposal for fixing `use_frameworks!` compatibility without breaking all `<React/*>` imports I outlined in https://github.com/facebook/react-native/pull/25393#issuecomment-508457700. If accepted, it will fix https://github.com/facebook/react-native/issues/25349.
It builds on the changes I made in https://github.com/facebook/react-native/pull/25496 by ensuring each podspec has a unique value for `header_dir` so that framework imports do not conflict. Every podspec which should be included in the `<React/*>` namespace now includes it's headers from `React-Core.podspec`.
The following pods can still be imported with `<React/*>` and so should not have breaking changes: `React-ART`,`React-DevSupport`, `React-CoreModules`, `React-RCTActionSheet`, `React-RCTAnimation`, `React-RCTBlob`, `React-RCTImage`, `React-RCTLinking`, `React-RCTNetwork`, `React-RCTPushNotification`, `React-RCTSettings`, `React-RCTText`, `React-RCTSettings`, `React-RCTVibration`, `React-RCTWebSocket` .
There are still a few breaking changes which I hope will be acceptable:
- `React-Core.podspec` has been moved to the root of the project. Any `Podfile` that references it will need to update the path.
- ~~`React-turbomodule-core`'s headers now live under `<turbomodule/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- ~~`React-turbomodulesamples`'s headers now live under `<turbomodulesamples/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- ~~`React-TypeSaferty`'s headers now live under `<TypeSafety/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511040967.
- ~~`React-jscallinvoker`'s headers now live under `<jscallinvoker/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- Each podspec now uses `s.static_framework = true`. This means that a minimum of CocoaPods 1.5 ([released in April 2018](http://blog.cocoapods.org/CocoaPods-1.5.0/)) is now required. This is needed so that the ` __has_include` conditions can still work when frameworks are enabled.
Still to do:
- ~~Including `React-turbomodule-core` with `use_frameworks!` enabled causes the C++ import failures we saw in https://github.com/facebook/react-native/issues/25349. I'm sure it will be possible to fix this but I need to dig deeper (perhaps a custom modulemap would be needed).~~ Addressed by https://github.com/facebook/react-native/pull/25619/commits/33573511f02f3502a28bad48e085e9a4b8608302.
- I haven't got Fabric working yet. I wonder if it would be acceptable to move Fabric out of the `<React/*>` namespace since it is new? �
## Changelog
[iOS] [Fixed] - Fixed compatibility with CocoaPods frameworks.
Pull Request resolved: https://github.com/facebook/react-native/pull/25619
Test Plan:
### FB
```
buck build catalyst
```
### Sample Project
Everything should work exactly as before, where `use_frameworks!` is not in `Podfile`s. I have a branch on my [sample project](https://github.com/jtreanor/react-native-cocoapods-frameworks) here which has `use_frameworks!` in its `Podfile` to demonstrate this is fixed.
You can see that it works with these steps:
1. `git clone git@github.com:jtreanor/react-native-cocoapods-frameworks.git`
2. `git checkout fix-frameworks-subspecs`
3. `cd ios && pod install`
4. `cd .. && react-native run-ios`
The sample app will build and run successfully. To see that it still works without frameworks, remove `use_frameworks!` from the `Podfile` and do steps 3 and 4 again.
### RNTesterPods
`RNTesterPodsPods` can now work with or without `use_frameworks!`.
1. Go to the `RNTester` directory and run `pod install`.
2. Run the tests in `RNTesterPods.xcworkspace` to see that everything still works fine.
3. Uncomment the `use_frameworks!` line at the top of `RNTester/Podfile` and run `pod install` again.
4. Run the tests again and see that it still works with frameworks enabled.
Reviewed By: PeteTheHeat
Differential Revision: D16465247
Pulled By: PeteTheHeat
fbshipit-source-id: cad837e9cced06d30cc5b372af1c65c7780b9e7a
2019-07-25 08:26:42 +03:00
|
|
|
#import <React/RCTSRWebSocket.h>
|
2015-05-14 19:28:09 +03:00
|
|
|
|
|
|
|
@implementation RCTSRWebSocket (React)
|
|
|
|
|
|
|
|
- (NSNumber *)reactTag
|
|
|
|
{
|
|
|
|
return objc_getAssociatedObject(self, _cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setReactTag:(NSNumber *)reactTag
|
|
|
|
{
|
|
|
|
objc_setAssociatedObject(self, @selector(reactTag), reactTag, OBJC_ASSOCIATION_COPY_NONATOMIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2016-11-23 18:47:52 +03:00
|
|
|
@interface RCTWebSocketModule () <RCTSRWebSocketDelegate>
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-10-07 18:28:34 +03:00
|
|
|
@implementation RCTWebSocketModule
|
2015-05-14 19:28:09 +03:00
|
|
|
{
|
2017-07-26 18:12:12 +03:00
|
|
|
NSMutableDictionary<NSNumber *, RCTSRWebSocket *> *_sockets;
|
2018-01-26 20:06:14 +03:00
|
|
|
NSMutableDictionary<NSNumber *, id<RCTWebSocketContentHandler>> *_contentHandlers;
|
2015-05-14 19:28:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2017-07-26 18:12:12 +03:00
|
|
|
// Used by RCTBlobModule
|
|
|
|
@synthesize methodQueue = _methodQueue;
|
|
|
|
|
2016-05-12 18:29:39 +03:00
|
|
|
- (NSArray *)supportedEvents
|
|
|
|
{
|
|
|
|
return @[@"websocketMessage",
|
|
|
|
@"websocketOpen",
|
|
|
|
@"websocketFailed",
|
|
|
|
@"websocketClosed"];
|
|
|
|
}
|
2015-05-14 19:28:09 +03:00
|
|
|
|
2018-01-26 20:06:14 +03:00
|
|
|
- (void)invalidate
|
2015-05-14 19:28:09 +03:00
|
|
|
{
|
2018-01-26 20:06:14 +03:00
|
|
|
_contentHandlers = nil;
|
2015-11-14 21:25:00 +03:00
|
|
|
for (RCTSRWebSocket *socket in _sockets.allValues) {
|
2015-05-14 19:28:09 +03:00
|
|
|
socket.delegate = nil;
|
|
|
|
[socket close];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
WebSocket API change to make room for other connection options (SSL pinning)
Summary:
This is a simple groundwork PR to allow options to be passed to the `WebSocket` constructor. It represents a minor change to an undocumented part of the API, moving `headers` to within `options`.
This will be a BC for anyone manually specifying headers other than `origin` but a) that's not a common use case with WebSockets and b) it's not documented even in code and wouldn't currently pass a flow check.
NB: The third argument to the WebSocket constructor isn't part of the W3C spec, so I think this is a good place for RN-specific named parameters, better than adding a fourth argument. `protocols` needs to stay where it is, in line with the spec.
If this goes through I'd like to build on it by adding an additional connection option for SSL certificate pinning, as already supported by the underlying `okhttp` and `RCTSRWebSocket`. It could later be expanded for various other uses.
Currently, there's no way for a `WebSocket` user to specify any connection options other than url, protocol and headers. The fact that `WebSocket` connects in its constructor means any options have to go in there.
Connect to a websocket server using iOS and Android, observe the connection headers:
1. Without specifying `origin`, the default header should be set
2. Specifying it in the old way `new WebSocket(url, protocols, { origin: 'customorigin.com' })`
3. Specifying it in the new way `new WebSocket(url, protocols, { headers: { origin: 'customorigin.com' }})`.
I've tested myself using the test app with iOS and Android.
Closes https://github.com/facebook/react-native/pull/15334
Differential Revision: D5601675
Pulled By: javache
fbshipit-source-id: 5959d03a3e1d269b2c6775f3e0cf071ff08617bf
2017-08-10 15:59:36 +03:00
|
|
|
RCT_EXPORT_METHOD(connect:(NSURL *)URL protocols:(NSArray *)protocols options:(NSDictionary *)options socketID:(nonnull NSNumber *)socketID)
|
2015-05-14 19:28:09 +03:00
|
|
|
{
|
2016-03-15 21:48:42 +03:00
|
|
|
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
|
2017-07-26 18:12:12 +03:00
|
|
|
|
2017-05-24 19:36:40 +03:00
|
|
|
// We load cookies from sharedHTTPCookieStorage (shared with XHR and
|
|
|
|
// fetch). To get secure cookies for wss URLs, replace wss with https
|
|
|
|
// in the URL.
|
|
|
|
NSURLComponents *components = [NSURLComponents componentsWithURL:URL resolvingAgainstBaseURL:true];
|
|
|
|
if ([components.scheme.lowercaseString isEqualToString:@"wss"]) {
|
|
|
|
components.scheme = @"https";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load and set the cookie header.
|
|
|
|
NSArray<NSHTTPCookie *> *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:components.URL];
|
|
|
|
request.allHTTPHeaderFields = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];
|
2017-07-26 18:12:12 +03:00
|
|
|
|
2017-05-24 19:36:40 +03:00
|
|
|
// Load supplied headers
|
WebSocket API change to make room for other connection options (SSL pinning)
Summary:
This is a simple groundwork PR to allow options to be passed to the `WebSocket` constructor. It represents a minor change to an undocumented part of the API, moving `headers` to within `options`.
This will be a BC for anyone manually specifying headers other than `origin` but a) that's not a common use case with WebSockets and b) it's not documented even in code and wouldn't currently pass a flow check.
NB: The third argument to the WebSocket constructor isn't part of the W3C spec, so I think this is a good place for RN-specific named parameters, better than adding a fourth argument. `protocols` needs to stay where it is, in line with the spec.
If this goes through I'd like to build on it by adding an additional connection option for SSL certificate pinning, as already supported by the underlying `okhttp` and `RCTSRWebSocket`. It could later be expanded for various other uses.
Currently, there's no way for a `WebSocket` user to specify any connection options other than url, protocol and headers. The fact that `WebSocket` connects in its constructor means any options have to go in there.
Connect to a websocket server using iOS and Android, observe the connection headers:
1. Without specifying `origin`, the default header should be set
2. Specifying it in the old way `new WebSocket(url, protocols, { origin: 'customorigin.com' })`
3. Specifying it in the new way `new WebSocket(url, protocols, { headers: { origin: 'customorigin.com' }})`.
I've tested myself using the test app with iOS and Android.
Closes https://github.com/facebook/react-native/pull/15334
Differential Revision: D5601675
Pulled By: javache
fbshipit-source-id: 5959d03a3e1d269b2c6775f3e0cf071ff08617bf
2017-08-10 15:59:36 +03:00
|
|
|
[options[@"headers"] enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {
|
2016-03-15 21:48:42 +03:00
|
|
|
[request addValue:[RCTConvert NSString:value] forHTTPHeaderField:key];
|
|
|
|
}];
|
|
|
|
|
|
|
|
RCTSRWebSocket *webSocket = [[RCTSRWebSocket alloc] initWithURLRequest:request protocols:protocols];
|
2018-03-25 09:04:41 +03:00
|
|
|
[webSocket setDelegateDispatchQueue:_methodQueue];
|
2015-05-14 19:28:09 +03:00
|
|
|
webSocket.delegate = self;
|
|
|
|
webSocket.reactTag = socketID;
|
2015-11-25 14:09:00 +03:00
|
|
|
if (!_sockets) {
|
|
|
|
_sockets = [NSMutableDictionary new];
|
|
|
|
}
|
2015-05-14 19:28:09 +03:00
|
|
|
_sockets[socketID] = webSocket;
|
|
|
|
[webSocket open];
|
|
|
|
}
|
|
|
|
|
2017-07-26 18:12:12 +03:00
|
|
|
RCT_EXPORT_METHOD(send:(NSString *)message forSocketID:(nonnull NSNumber *)socketID)
|
2015-05-14 19:28:09 +03:00
|
|
|
{
|
|
|
|
[_sockets[socketID] send:message];
|
|
|
|
}
|
|
|
|
|
2017-07-26 18:12:12 +03:00
|
|
|
RCT_EXPORT_METHOD(sendBinary:(NSString *)base64String forSocketID:(nonnull NSNumber *)socketID)
|
2016-04-20 18:52:22 +03:00
|
|
|
{
|
2017-07-26 18:12:12 +03:00
|
|
|
[self sendData:[[NSData alloc] initWithBase64EncodedString:base64String options:0] forSocketID:socketID];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendData:(NSData *)data forSocketID:(nonnull NSNumber *)socketID
|
|
|
|
{
|
|
|
|
[_sockets[socketID] send:data];
|
2016-04-20 18:52:22 +03:00
|
|
|
}
|
|
|
|
|
2016-07-05 15:52:24 +03:00
|
|
|
RCT_EXPORT_METHOD(ping:(nonnull NSNumber *)socketID)
|
|
|
|
{
|
|
|
|
[_sockets[socketID] sendPing:NULL];
|
|
|
|
}
|
|
|
|
|
2019-05-20 11:06:33 +03:00
|
|
|
RCT_EXPORT_METHOD(close:(NSInteger)code reason:(NSString *)reason socketID:(nonnull NSNumber *)socketID)
|
2015-05-14 19:28:09 +03:00
|
|
|
{
|
2019-05-20 11:06:33 +03:00
|
|
|
[_sockets[socketID] closeWithCode:code reason:reason];
|
2015-11-14 21:25:00 +03:00
|
|
|
[_sockets removeObjectForKey:socketID];
|
2015-05-14 19:28:09 +03:00
|
|
|
}
|
|
|
|
|
2017-07-26 18:12:12 +03:00
|
|
|
- (void)setContentHandler:(id<RCTWebSocketContentHandler>)handler forSocketID:(NSString *)socketID
|
|
|
|
{
|
|
|
|
if (!_contentHandlers) {
|
|
|
|
_contentHandlers = [NSMutableDictionary new];
|
|
|
|
}
|
|
|
|
_contentHandlers[socketID] = handler;
|
|
|
|
}
|
|
|
|
|
2015-05-14 19:28:09 +03:00
|
|
|
#pragma mark - RCTSRWebSocketDelegate methods
|
|
|
|
|
|
|
|
- (void)webSocket:(RCTSRWebSocket *)webSocket didReceiveMessage:(id)message
|
|
|
|
{
|
2017-07-26 18:12:12 +03:00
|
|
|
NSString *type;
|
|
|
|
|
|
|
|
NSNumber *socketID = [webSocket reactTag];
|
|
|
|
id contentHandler = _contentHandlers[socketID];
|
|
|
|
if (contentHandler) {
|
2018-01-26 20:06:14 +03:00
|
|
|
message = [contentHandler processWebsocketMessage:message forSocketID:socketID withType:&type];
|
2017-07-26 18:12:12 +03:00
|
|
|
} else {
|
|
|
|
if ([message isKindOfClass:[NSData class]]) {
|
|
|
|
type = @"binary";
|
|
|
|
message = [message base64EncodedStringWithOptions:0];
|
|
|
|
} else {
|
|
|
|
type = @"text";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-12 18:29:39 +03:00
|
|
|
[self sendEventWithName:@"websocketMessage" body:@{
|
2017-07-26 18:12:12 +03:00
|
|
|
@"data": message,
|
|
|
|
@"type": type,
|
2015-05-14 19:28:09 +03:00
|
|
|
@"id": webSocket.reactTag
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)webSocketDidOpen:(RCTSRWebSocket *)webSocket
|
|
|
|
{
|
2016-05-12 18:29:39 +03:00
|
|
|
[self sendEventWithName:@"websocketOpen" body:@{
|
Protocol property of WebSocket object is undefined (#25273)
Summary:
Prior to this patch the websocket protocol was not being set when a connection
was opened, which could cause client libraries and apps to not work properly.
According to the [whatwg] spec the protocol must be set once the connection is
estabilished.
[whatwg]: https://html.spec.whatwg.org/multipage/web-sockets.html#feedback-from-the-protocol
## Changelog
[Javascript] [Fixed] - Properly set the this.protocol on WebSocket open
[Android] [Fixed] - Send the server chosen protocol to the WebSocket object
[iOS] [Fixed] - Send the server chosen protocol to the WebSocket object
Pull Request resolved: https://github.com/facebook/react-native/pull/25273
Test Plan:
In order to reproduce the issue you **need to install wampy@6.2.1**. Since **wampy@6.2.2** and newer contains a workaround for this react-native bug.
https://www.npmjs.com/package/wampy
```javascript
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* format
* flow
*/
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import Wampy from "wampy";
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
type Props = {};
export default class App extends Component<Props> {
state = {conState: 'Initializing...'};
componentDidMount() {
const url = "wss://demo.crossbar.io/ws";
const ws = new Wampy(url, {
realm: "crossbardemo",
ws: WebSocket,
debug: true,
onConnect: () => {
console.log("WAMP onConnect");
this.setState({conState: 'Connected'});
},
onClose: () => {
console.log("WAMP onClose");
this.setState({conState: 'Connection closed'});
},
onError: () => {
console.log("WAMP onError");
this.setState({conState: 'Connection Error'});
}
});
}
render() {
return (
<View style={styles.container}>
<Text style={styles.message}>{this.state.conState}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
message: {
fontSize: 20,
color: 'black'
},
});
```
Using the code above one must see the message **WAMP onConnect** on Console and **Connected** in the middle of the screen
Closes https://github.com/facebook/react-native/issues/24796
Differential Revision: D15938870
Pulled By: cpojer
fbshipit-source-id: 10a0a9b40c2a69e484ead37149abc2b1158a4ffc
2019-06-21 13:39:47 +03:00
|
|
|
@"id": webSocket.reactTag,
|
|
|
|
@"protocol": webSocket.protocol ? webSocket.protocol : @""
|
2015-05-14 19:28:09 +03:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error
|
|
|
|
{
|
2017-07-26 18:12:12 +03:00
|
|
|
NSNumber *socketID = [webSocket reactTag];
|
|
|
|
_contentHandlers[socketID] = nil;
|
2017-12-04 20:18:59 +03:00
|
|
|
_sockets[socketID] = nil;
|
2016-05-12 18:29:39 +03:00
|
|
|
[self sendEventWithName:@"websocketFailed" body:@{
|
2017-07-26 18:12:12 +03:00
|
|
|
@"message": error.localizedDescription,
|
|
|
|
@"id": socketID
|
2015-05-14 19:28:09 +03:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2017-07-26 18:12:12 +03:00
|
|
|
- (void)webSocket:(RCTSRWebSocket *)webSocket
|
|
|
|
didCloseWithCode:(NSInteger)code
|
|
|
|
reason:(NSString *)reason
|
|
|
|
wasClean:(BOOL)wasClean
|
2015-05-14 19:28:09 +03:00
|
|
|
{
|
2017-07-26 18:12:12 +03:00
|
|
|
NSNumber *socketID = [webSocket reactTag];
|
|
|
|
_contentHandlers[socketID] = nil;
|
2017-12-04 20:18:59 +03:00
|
|
|
_sockets[socketID] = nil;
|
2016-05-12 18:29:39 +03:00
|
|
|
[self sendEventWithName:@"websocketClosed" body:@{
|
2015-05-14 19:28:09 +03:00
|
|
|
@"code": @(code),
|
2015-06-12 21:05:01 +03:00
|
|
|
@"reason": RCTNullIfNil(reason),
|
2015-05-14 19:28:09 +03:00
|
|
|
@"clean": @(wasClean),
|
2017-07-26 18:12:12 +03:00
|
|
|
@"id": socketID
|
2015-05-14 19:28:09 +03:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2017-07-26 18:12:12 +03:00
|
|
|
|
|
|
|
@implementation RCTBridge (RCTWebSocketModule)
|
|
|
|
|
|
|
|
- (RCTWebSocketModule *)webSocketModule
|
|
|
|
{
|
|
|
|
return [self moduleForClass:[RCTWebSocketModule class]];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|