WebSocket polyfill

Summary:
- Added as a library in /Libraries/WebSocket
- Drag and drop to add to project (similar to adding Geolocation polyfill)
- Exposed as `window.WebSocket` which conforms with https://developer.mozilla.org/en-US/docs/Web/API/WebSocket specs
Closes https://github.com/facebook/react-native/pull/890
Github Author: Harrison Harnisch <hharnisc@gmail.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
This commit is contained in:
Harrison Harnisch 2015-05-14 09:28:09 -07:00
parent 55e280d200
commit babdc21614
18 changed files with 2265 additions and 2270 deletions

View File

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
1338BC281B04C72D0064A9C9 /* libRCTWebSocket.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1338BC261B04C7080064A9C9 /* libRCTWebSocket.a */; };
1341801E1AA91750003F314A /* libRCTNetwork.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1341801B1AA91740003F314A /* libRCTNetwork.a */; };
13442C061AA90EA00037E5B0 /* libRCTImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13442C051AA90E7D0037E5B0 /* libRCTImage.a */; };
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
@ -19,6 +20,13 @@
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
1338BC251B04C7080064A9C9 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 1338BC1D1B04C7070064A9C9 /* RCTWebSocket.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 3C86DF461ADF2C930047B81A;
remoteInfo = RCTWebSocket;
};
1341801A1AA91740003F314A /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 134180151AA91740003F314A /* RCTNetwork.xcodeproj */;
@ -57,6 +65,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
1338BC1D1B04C7070064A9C9 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = "/Users/nicklockwood/fbobjc-hg/Libraries/FBReactKit/js/react-native-github/Libraries/Text/../WebSocket/RCTWebSocket.xcodeproj"; sourceTree = "<absolute>"; };
134180151AA91740003F314A /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = ../../Libraries/Network/RCTNetwork.xcodeproj; sourceTree = "<group>"; };
13442C001AA90E7D0037E5B0 /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = ../../Libraries/Image/RCTImage.xcodeproj; sourceTree = "<group>"; };
13B07F961A680F5B00A75B9A /* Movies.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Movies.app; sourceTree = BUILT_PRODUCTS_DIR; };
@ -81,12 +90,21 @@
1341801E1AA91750003F314A /* libRCTNetwork.a in Frameworks */,
13442C061AA90EA00037E5B0 /* libRCTImage.a in Frameworks */,
58C5726B1AA6239E00CDF9C8 /* libRCTText.a in Frameworks */,
1338BC281B04C72D0064A9C9 /* libRCTWebSocket.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
1338BC1E1B04C7070064A9C9 /* Products */ = {
isa = PBXGroup;
children = (
1338BC261B04C7080064A9C9 /* libRCTWebSocket.a */,
);
name = Products;
sourceTree = "<group>";
};
134180161AA91740003F314A /* Products */ = {
isa = PBXGroup;
children = (
@ -140,6 +158,7 @@
134180151AA91740003F314A /* RCTNetwork.xcodeproj */,
13442C001AA90E7D0037E5B0 /* RCTImage.xcodeproj */,
587650F61A9EB120008B8F17 /* RCTText.xcodeproj */,
1338BC1D1B04C7070064A9C9 /* RCTWebSocket.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
@ -228,6 +247,10 @@
ProductGroup = 58C572571AA6236500CDF9C8 /* Products */;
ProjectRef = 587650F61A9EB120008B8F17 /* RCTText.xcodeproj */;
},
{
ProductGroup = 1338BC1E1B04C7070064A9C9 /* Products */;
ProjectRef = 1338BC1D1B04C7070064A9C9 /* RCTWebSocket.xcodeproj */;
},
{
ProductGroup = 14A2D43D1AC3E41A00CC738A /* Products */;
ProjectRef = 14A2D43C1AC3E41A00CC738A /* React.xcodeproj */;
@ -241,6 +264,13 @@
/* End PBXProject section */
/* Begin PBXReferenceProxy section */
1338BC261B04C7080064A9C9 /* libRCTWebSocket.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRCTWebSocket.a;
remoteRef = 1338BC251B04C7080064A9C9 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
1341801B1AA91740003F314A /* libRCTNetwork.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;

View File

@ -7,7 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
00481BE81AC0C86700671115 /* libRCTWebSocketDebugger.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00481BE61AC0C7FA00671115 /* libRCTWebSocketDebugger.a */; };
008F07F31AC5B25A0029DE68 /* main.jsbundle in Resources */ = {isa = PBXBuildFile; fileRef = 008F07F21AC5B25A0029DE68 /* main.jsbundle */; };
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; };
00C302E61ABCBA2D00DB3ED1 /* libRCTAdSupport.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302B41ABCB8E700DB3ED1 /* libRCTAdSupport.a */; };
@ -16,6 +15,7 @@
00C302E91ABCBA2D00DB3ED1 /* libRCTNetwork.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302DC1ABCB9D200DB3ED1 /* libRCTNetwork.a */; };
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302E41ABCB9EE00DB3ED1 /* libRCTVibration.a */; };
00E356F31AD99517003FC87E /* SampleAppTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* SampleAppTests.m */; };
1338BBC51B04AC310064A9C9 /* libRCTWebSocket.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1338BBB81B04A6AE0064A9C9 /* libRCTWebSocket.a */; };
133E29F31AD74F7200F7D852 /* libRCTLinking.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 78C398B91ACF4ADC00677621 /* libRCTLinking.a */; };
139105C61AF99C1200B5F7CC /* libRCTSettings.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 139105C11AF99BAD00B5F7CC /* libRCTSettings.a */; };
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
@ -27,13 +27,6 @@
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
00481BE51AC0C7FA00671115 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 00481BDB1AC0C7FA00671115 /* RCTWebSocketDebugger.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 832C81801AAF6DEF007FA2F7;
remoteInfo = RCTWebSocketDebugger;
};
00C302AB1ABCB8CE00DB3ED1 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */;
@ -83,6 +76,13 @@
remoteGlobalIDString = 13B07F861A680F5B00A75B9A;
remoteInfo = SampleApp;
};
1338BBB71B04A6AE0064A9C9 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 1338BBB31B04A6AE0064A9C9 /* RCTWebSocket.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 3C86DF461ADF2C930047B81A;
remoteInfo = RCTWebSocket;
};
139105C01AF99BAD00B5F7CC /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */;
@ -114,7 +114,6 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
00481BDB1AC0C7FA00671115 /* RCTWebSocketDebugger.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocketDebugger.xcodeproj; path = ../../Libraries/RCTWebSocketDebugger/RCTWebSocketDebugger.xcodeproj; sourceTree = "<group>"; };
008F07F21AC5B25A0029DE68 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.jsbundle; path = iOS/main.jsbundle; sourceTree = "<group>"; };
00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTActionSheet.xcodeproj; path = ../../Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj; sourceTree = "<group>"; };
00C302AF1ABCB8E700DB3ED1 /* RCTAdSupport.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAdSupport.xcodeproj; path = ../../Libraries/AdSupport/RCTAdSupport.xcodeproj; sourceTree = "<group>"; };
@ -125,6 +124,7 @@
00E356EE1AD99517003FC87E /* SampleAppTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SampleAppTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
00E356F21AD99517003FC87E /* SampleAppTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SampleAppTests.m; sourceTree = "<group>"; };
1338BBB31B04A6AE0064A9C9 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = ../../Libraries/WebSocket/RCTWebSocket.xcodeproj; sourceTree = "<group>"; };
139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = ../../Libraries/Settings/RCTSettings.xcodeproj; sourceTree = "<group>"; };
13B07F961A680F5B00A75B9A /* SampleApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SampleApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = iOS/AppDelegate.h; sourceTree = "<group>"; };
@ -151,30 +151,22 @@
buildActionMask = 2147483647;
files = (
146834051AC3E58100842450 /* libReact.a in Frameworks */,
139105C61AF99C1200B5F7CC /* libRCTSettings.a in Frameworks */,
00481BE81AC0C86700671115 /* libRCTWebSocketDebugger.a in Frameworks */,
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */,
00C302E61ABCBA2D00DB3ED1 /* libRCTAdSupport.a in Frameworks */,
00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */,
00C302E81ABCBA2D00DB3ED1 /* libRCTImage.a in Frameworks */,
133E29F31AD74F7200F7D852 /* libRCTLinking.a in Frameworks */,
00C302E91ABCBA2D00DB3ED1 /* libRCTNetwork.a in Frameworks */,
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */,
139105C61AF99C1200B5F7CC /* libRCTSettings.a in Frameworks */,
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */,
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */,
1338BBC51B04AC310064A9C9 /* libRCTWebSocket.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
00481BDC1AC0C7FA00671115 /* Products */ = {
isa = PBXGroup;
children = (
00481BE61AC0C7FA00671115 /* libRCTWebSocketDebugger.a */,
);
name = Products;
sourceTree = "<group>";
};
00C302A81ABCB8CE00DB3ED1 /* Products */ = {
isa = PBXGroup;
children = (
@ -240,6 +232,14 @@
name = "Supporting Files";
sourceTree = "<group>";
};
1338BBB41B04A6AE0064A9C9 /* Products */ = {
isa = PBXGroup;
children = (
1338BBB81B04A6AE0064A9C9 /* libRCTWebSocket.a */,
);
name = Products;
sourceTree = "<group>";
};
139105B71AF99BAD00B5F7CC /* Products */ = {
isa = PBXGroup;
children = (
@ -291,7 +291,7 @@
139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */,
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */,
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
00481BDB1AC0C7FA00671115 /* RCTWebSocketDebugger.xcodeproj */,
1338BBB31B04A6AE0064A9C9 /* RCTWebSocket.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
@ -427,8 +427,8 @@
ProjectRef = 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */;
},
{
ProductGroup = 00481BDC1AC0C7FA00671115 /* Products */;
ProjectRef = 00481BDB1AC0C7FA00671115 /* RCTWebSocketDebugger.xcodeproj */;
ProductGroup = 1338BBB41B04A6AE0064A9C9 /* Products */;
ProjectRef = 1338BBB31B04A6AE0064A9C9 /* RCTWebSocket.xcodeproj */;
},
{
ProductGroup = 146834001AC3E56700842450 /* Products */;
@ -444,13 +444,6 @@
/* End PBXProject section */
/* Begin PBXReferenceProxy section */
00481BE61AC0C7FA00671115 /* libRCTWebSocketDebugger.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRCTWebSocketDebugger.a;
remoteRef = 00481BE51AC0C7FA00671115 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
@ -493,6 +486,13 @@
remoteRef = 00C302E31ABCB9EE00DB3ED1 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
1338BBB81B04A6AE0064A9C9 /* libRCTWebSocket.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRCTWebSocket.a;
remoteRef = 1338BBB71B04A6AE0064A9C9 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
139105C11AF99BAD00B5F7CC /* libRCTSettings.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;

View File

@ -8,7 +8,7 @@
/* Begin PBXBuildFile section */
004D28A31AAF61C70097A701 /* UIExplorerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 004D28A21AAF61C70097A701 /* UIExplorerTests.m */; };
00D2771A1AB8C3E100DC1E48 /* libRCTWebSocketDebugger.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00D277131AB8C2C700DC1E48 /* libRCTWebSocketDebugger.a */; };
1338BBE31B04ACF90064A9C9 /* libRCTWebSocket.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1338BB9C1B04A6390064A9C9 /* libRCTWebSocket.a */; };
13417FE91AA91432003F314A /* libRCTImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13417FE81AA91428003F314A /* libRCTImage.a */; };
134180011AA9153C003F314A /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13417FEF1AA914B8003F314A /* libRCTText.a */; };
1341802C1AA9178B003F314A /* libRCTNetwork.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1341802B1AA91779003F314A /* libRCTNetwork.a */; };
@ -34,12 +34,12 @@
remoteGlobalIDString = 13B07F861A680F5B00A75B9A;
remoteInfo = UIExplorer;
};
00D277121AB8C2C700DC1E48 /* PBXContainerItemProxy */ = {
1338BB9B1B04A6390064A9C9 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 00D2770E1AB8C2C700DC1E48 /* RCTWebSocketDebugger.xcodeproj */;
containerPortal = 1338BB971B04A6390064A9C9 /* RCTWebSocket.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 832C81801AAF6DEF007FA2F7;
remoteInfo = RCTWebSocketDebugger;
remoteGlobalIDString = 3C86DF461ADF2C930047B81A;
remoteInfo = RCTWebSocket;
};
13417FE71AA91428003F314A /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
@ -124,7 +124,7 @@
004D289E1AAF61C70097A701 /* UIExplorerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UIExplorerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
004D28A11AAF61C70097A701 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
004D28A21AAF61C70097A701 /* UIExplorerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIExplorerTests.m; sourceTree = "<group>"; };
00D2770E1AB8C2C700DC1E48 /* RCTWebSocketDebugger.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocketDebugger.xcodeproj; path = ../../Libraries/RCTWebSocketDebugger/RCTWebSocketDebugger.xcodeproj; sourceTree = "<group>"; };
1338BB971B04A6390064A9C9 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = ../../Libraries/WebSocket/RCTWebSocket.xcodeproj; sourceTree = "<group>"; };
13417FE31AA91428003F314A /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = ../../Libraries/Image/RCTImage.xcodeproj; sourceTree = "<group>"; };
13417FEA1AA914B8003F314A /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = ../../Libraries/Text/RCTText.xcodeproj; sourceTree = "<group>"; };
134180261AA91779003F314A /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = ../../Libraries/Network/RCTNetwork.xcodeproj; sourceTree = "<group>"; };
@ -159,7 +159,6 @@
files = (
834C36EC1AF8DED70019C93C /* libRCTSettings.a in Frameworks */,
14AADF051AC3DBB1002390C9 /* libReact.a in Frameworks */,
00D2771A1AB8C3E100DC1E48 /* libRCTWebSocketDebugger.a in Frameworks */,
58005BF21ABA80A60062E044 /* libRCTTest.a in Frameworks */,
D85B829E1AB6D5D7003F4FE2 /* libRCTVibration.a in Frameworks */,
14DC67F41AB71881001358AB /* libRCTPushNotification.a in Frameworks */,
@ -169,6 +168,7 @@
1341802C1AA9178B003F314A /* libRCTNetwork.a in Frameworks */,
134180011AA9153C003F314A /* libRCTText.a in Frameworks */,
13417FE91AA91432003F314A /* libRCTImage.a in Frameworks */,
1338BBE31B04ACF90064A9C9 /* libRCTWebSocket.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -192,14 +192,6 @@
name = "Supporting Files";
sourceTree = "<group>";
};
00D2770F1AB8C2C700DC1E48 /* Products */ = {
isa = PBXGroup;
children = (
00D277131AB8C2C700DC1E48 /* libRCTWebSocketDebugger.a */,
);
name = Products;
sourceTree = "<group>";
};
1316A21D1AA397F400C0188E /* Libraries */ = {
isa = PBXGroup;
children = (
@ -213,12 +205,20 @@
13CC9D481AEED2B90020D1C2 /* RCTSettings.xcodeproj */,
58005BE41ABA80530062E044 /* RCTTest.xcodeproj */,
13417FEA1AA914B8003F314A /* RCTText.xcodeproj */,
00D2770E1AB8C2C700DC1E48 /* RCTWebSocketDebugger.xcodeproj */,
D85B82911AB6D5CE003F4FE2 /* RCTVibration.xcodeproj */,
1338BB971B04A6390064A9C9 /* RCTWebSocket.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
};
1338BB981B04A6390064A9C9 /* Products */ = {
isa = PBXGroup;
children = (
1338BB9C1B04A6390064A9C9 /* libRCTWebSocket.a */,
);
name = Products;
sourceTree = "<group>";
};
13417FE41AA91428003F314A /* Products */ = {
isa = PBXGroup;
children = (
@ -447,8 +447,8 @@
ProjectRef = D85B82911AB6D5CE003F4FE2 /* RCTVibration.xcodeproj */;
},
{
ProductGroup = 00D2770F1AB8C2C700DC1E48 /* Products */;
ProjectRef = 00D2770E1AB8C2C700DC1E48 /* RCTWebSocketDebugger.xcodeproj */;
ProductGroup = 1338BB981B04A6390064A9C9 /* Products */;
ProjectRef = 1338BB971B04A6390064A9C9 /* RCTWebSocket.xcodeproj */;
},
{
ProductGroup = 14AADF001AC3DB95002390C9 /* Products */;
@ -464,11 +464,11 @@
/* End PBXProject section */
/* Begin PBXReferenceProxy section */
00D277131AB8C2C700DC1E48 /* libRCTWebSocketDebugger.a */ = {
1338BB9C1B04A6390064A9C9 /* libRCTWebSocket.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRCTWebSocketDebugger.a;
remoteRef = 00D277121AB8C2C700DC1E48 /* PBXContainerItemProxy */;
path = libRCTWebSocket.a;
remoteRef = 1338BB9B1B04A6390064A9C9 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
13417FE81AA91428003F314A /* libRCTImage.a */ = {

View File

@ -41,12 +41,12 @@ function handleErrorWithRedBox(e, isFatal) {
}
}
function setupRedBoxErrorHandler() {
function setUpRedBoxErrorHandler() {
var ErrorUtils = require('ErrorUtils');
ErrorUtils.setGlobalHandler(handleErrorWithRedBox);
}
function setupRedBoxConsoleErrorHandler() {
function setUpRedBoxConsoleErrorHandler() {
// ExceptionsManager transitively requires Promise so we install it after
var ExceptionsManager = require('ExceptionsManager');
var Platform = require('Platform');
@ -63,7 +63,7 @@ function setupRedBoxConsoleErrorHandler() {
* implement our own custom timing bridge that should be immune to
* unexplainably dropped timing signals.
*/
function setupTimers() {
function setUpTimers() {
var JSTimers = require('JSTimers');
GLOBAL.setTimeout = JSTimers.setTimeout;
GLOBAL.setInterval = JSTimers.setInterval;
@ -78,7 +78,7 @@ function setupTimers() {
};
}
function setupAlert() {
function setUpAlert() {
var RCTAlertManager = require('NativeModules').AlertManager;
if (!GLOBAL.alert) {
GLOBAL.alert = function(text) {
@ -92,13 +92,13 @@ function setupAlert() {
}
}
function setupPromise() {
function setUpPromise() {
// The native Promise implementation throws the following error:
// ERROR: Event loop not supported.
GLOBAL.Promise = require('Promise');
}
function setupXHR() {
function setUpXHR() {
// The native XMLHttpRequest in Chrome dev tools is CORS aware and won't
// let you fetch anything from the internet
GLOBAL.XMLHttpRequest = require('XMLHttpRequest');
@ -110,15 +110,20 @@ function setupXHR() {
GLOBAL.Response = fetchPolyfill.Response;
}
function setupGeolocation() {
function setUpGeolocation() {
GLOBAL.navigator = GLOBAL.navigator || {};
GLOBAL.navigator.geolocation = require('Geolocation');
}
setupRedBoxErrorHandler();
setupTimers();
setupAlert();
setupPromise();
setupXHR();
setupRedBoxConsoleErrorHandler();
setupGeolocation();
function setUpWebSockets() {
GLOBAL.WebSocket = require('WebSocket');
}
setUpRedBoxErrorHandler();
setUpTimers();
setUpAlert();
setUpPromise();
setUpXHR();
setUpRedBoxConsoleErrorHandler();
setUpGeolocation();
setUpWebSockets();

View File

@ -1,275 +0,0 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
00D277161AB8C32C00DC1E48 /* RCTWebSocketExecutor.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D277151AB8C32C00DC1E48 /* RCTWebSocketExecutor.m */; };
13AF20421AE707C5005F5298 /* SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 13AF20411AE707C5005F5298 /* SRWebSocket.m */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
832C817E1AAF6DEF007FA2F7 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "include/$(PRODUCT_NAME)";
dstSubfolderSpec = 16;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
00D277141AB8C32C00DC1E48 /* RCTWebSocketExecutor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTWebSocketExecutor.h; sourceTree = "<group>"; };
00D277151AB8C32C00DC1E48 /* RCTWebSocketExecutor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTWebSocketExecutor.m; sourceTree = "<group>"; };
13AF20401AE707C5005F5298 /* SRWebSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRWebSocket.h; sourceTree = "<group>"; };
13AF20411AE707C5005F5298 /* SRWebSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRWebSocket.m; sourceTree = "<group>"; };
832C81801AAF6DEF007FA2F7 /* libRCTWebSocketDebugger.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTWebSocketDebugger.a; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
832C817D1AAF6DEF007FA2F7 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
832C81771AAF6DEF007FA2F7 = {
isa = PBXGroup;
children = (
13AF20401AE707C5005F5298 /* SRWebSocket.h */,
13AF20411AE707C5005F5298 /* SRWebSocket.m */,
00D277141AB8C32C00DC1E48 /* RCTWebSocketExecutor.h */,
00D277151AB8C32C00DC1E48 /* RCTWebSocketExecutor.m */,
832C81811AAF6DEF007FA2F7 /* Products */,
);
indentWidth = 2;
sourceTree = "<group>";
tabWidth = 2;
};
832C81811AAF6DEF007FA2F7 /* Products */ = {
isa = PBXGroup;
children = (
832C81801AAF6DEF007FA2F7 /* libRCTWebSocketDebugger.a */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
832C817F1AAF6DEF007FA2F7 /* RCTWebSocketDebugger */ = {
isa = PBXNativeTarget;
buildConfigurationList = 832C81941AAF6DF0007FA2F7 /* Build configuration list for PBXNativeTarget "RCTWebSocketDebugger" */;
buildPhases = (
832C817C1AAF6DEF007FA2F7 /* Sources */,
832C817D1AAF6DEF007FA2F7 /* Frameworks */,
832C817E1AAF6DEF007FA2F7 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = RCTWebSocketDebugger;
productName = RCTWebSocketDebugger;
productReference = 832C81801AAF6DEF007FA2F7 /* libRCTWebSocketDebugger.a */;
productType = "com.apple.product-type.library.static";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
832C81781AAF6DEF007FA2F7 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0620;
ORGANIZATIONNAME = Facebook;
TargetAttributes = {
832C817F1AAF6DEF007FA2F7 = {
CreatedOnToolsVersion = 6.2;
};
};
};
buildConfigurationList = 832C817B1AAF6DEF007FA2F7 /* Build configuration list for PBXProject "RCTWebSocketDebugger" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = 832C81771AAF6DEF007FA2F7;
productRefGroup = 832C81811AAF6DEF007FA2F7 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
832C817F1AAF6DEF007FA2F7 /* RCTWebSocketDebugger */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
832C817C1AAF6DEF007FA2F7 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
13AF20421AE707C5005F5298 /* SRWebSocket.m in Sources */,
00D277161AB8C32C00DC1E48 /* RCTWebSocketExecutor.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
832C81921AAF6DF0007FA2F7 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../React/**",
);
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
};
832C81931AAF6DF0007FA2F7 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../React/**",
);
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
832C81951AAF6DF0007FA2F7 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_STATIC_ANALYZER_MODE = deep;
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../React/**",
);
OTHER_LDFLAGS = (
"-ObjC",
"-llibicucore",
);
PRODUCT_NAME = "$(TARGET_NAME)";
RUN_CLANG_STATIC_ANALYZER = YES;
SKIP_INSTALL = YES;
};
name = Debug;
};
832C81961AAF6DF0007FA2F7 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_STATIC_ANALYZER_MODE = deep;
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../React/**",
);
OTHER_LDFLAGS = (
"-ObjC",
"-llibicucore",
);
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
832C817B1AAF6DEF007FA2F7 /* Build configuration list for PBXProject "RCTWebSocketDebugger" */ = {
isa = XCConfigurationList;
buildConfigurations = (
832C81921AAF6DF0007FA2F7 /* Debug */,
832C81931AAF6DF0007FA2F7 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
832C81941AAF6DF0007FA2F7 /* Build configuration list for PBXNativeTarget "RCTWebSocketDebugger" */ = {
isa = XCConfigurationList;
buildConfigurations = (
832C81951AAF6DF0007FA2F7 /* Debug */,
832C81961AAF6DF0007FA2F7 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 832C81781AAF6DEF007FA2F7 /* Project object */;
}

View File

@ -1,132 +0,0 @@
//
// Copyright 2012 Square Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
#import <Security/SecCertificate.h>
typedef enum {
SR_CONNECTING = 0,
SR_OPEN = 1,
SR_CLOSING = 2,
SR_CLOSED = 3,
} SRReadyState;
typedef enum SRStatusCode : NSInteger {
SRStatusCodeNormal = 1000,
SRStatusCodeGoingAway = 1001,
SRStatusCodeProtocolError = 1002,
SRStatusCodeUnhandledType = 1003,
// 1004 reserved.
SRStatusNoStatusReceived = 1005,
// 1004-1006 reserved.
SRStatusCodeInvalidUTF8 = 1007,
SRStatusCodePolicyViolated = 1008,
SRStatusCodeMessageTooBig = 1009,
} SRStatusCode;
@class SRWebSocket;
extern NSString *const SRWebSocketErrorDomain;
extern NSString *const SRHTTPResponseErrorKey;
#pragma mark - SRWebSocketDelegate
@protocol SRWebSocketDelegate;
#pragma mark - SRWebSocket
@interface SRWebSocket : NSObject <NSStreamDelegate>
@property (nonatomic, weak) id <SRWebSocketDelegate> delegate;
@property (nonatomic, readonly) SRReadyState readyState;
@property (nonatomic, readonly, retain) NSURL *url;
// This returns the negotiated protocol.
// It will be nil until after the handshake completes.
@property (nonatomic, readonly, copy) NSString *protocol;
// Protocols should be an array of strings that turn into Sec-WebSocket-Protocol.
- (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols;
- (id)initWithURLRequest:(NSURLRequest *)request;
// Some helper constructors.
- (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols;
- (id)initWithURL:(NSURL *)url;
// Delegate queue will be dispatch_main_queue by default.
// You cannot set both OperationQueue and dispatch_queue.
- (void)setDelegateOperationQueue:(NSOperationQueue*) queue;
- (void)setDelegateDispatchQueue:(dispatch_queue_t) queue;
// By default, it will schedule itself on +[NSRunLoop SR_networkRunLoop] using defaultModes.
- (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
- (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
// SRWebSockets are intended for one-time-use only. Open should be called once and only once.
- (void)open;
- (void)close;
- (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;
// Send a UTF8 String or Data.
- (void)send:(id)data;
// Send Data (can be nil) in a ping message.
- (void)sendPing:(NSData *)data;
@end
#pragma mark - SRWebSocketDelegate
@protocol SRWebSocketDelegate <NSObject>
// message will either be an NSString if the server is using text
// or NSData if the server is using binary.
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;
@optional
- (void)webSocketDidOpen:(SRWebSocket *)webSocket;
- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
- (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload;
@end
#pragma mark - NSURLRequest (CertificateAdditions)
@interface NSURLRequest (CertificateAdditions)
@property (nonatomic, retain, readonly) NSArray *SR_SSLPinnedCertificates;
@end
#pragma mark - NSMutableURLRequest (CertificateAdditions)
@interface NSMutableURLRequest (CertificateAdditions)
@property (nonatomic, retain) NSArray *SR_SSLPinnedCertificates;
@end
#pragma mark - NSRunLoop (SRWebSocket)
@interface NSRunLoop (SRWebSocket)
+ (NSRunLoop *)SR_networkRunLoop;
@end

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,132 @@
//
// Copyright 2012 Square Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
#import <Security/SecCertificate.h>
typedef enum {
RCTSR_CONNECTING = 0,
RCTSR_OPEN = 1,
RCTSR_CLOSING = 2,
RCTSR_CLOSED = 3,
} RCTSRReadyState;
typedef enum RCTSRStatusCode : NSInteger {
RCTSRStatusCodeNormal = 1000,
RCTSRStatusCodeGoingAway = 1001,
RCTSRStatusCodeProtocolError = 1002,
RCTSRStatusCodeUnhandledType = 1003,
// 1004 reserved.
RCTSRStatusNoStatusReceived = 1005,
// 1004-1006 reserved.
RCTSRStatusCodeInvalidUTF8 = 1007,
RCTSRStatusCodePolicyViolated = 1008,
RCTSRStatusCodeMessageTooBig = 1009,
} RCTSRStatusCode;
@class RCTSRWebSocket;
extern NSString *const RCTSRWebSocketErrorDomain;
extern NSString *const RCTSRHTTPResponseErrorKey;
#pragma mark - RCTSRWebSocketDelegate
@protocol RCTSRWebSocketDelegate;
#pragma mark - RCTSRWebSocket
@interface RCTSRWebSocket : NSObject <NSStreamDelegate>
@property (nonatomic, weak) id<RCTSRWebSocketDelegate> delegate;
@property (nonatomic, readonly) RCTSRReadyState readyState;
@property (nonatomic, readonly, strong) NSURL *url;
// This returns the negotiated protocol.
// It will be nil until after the handshake completes.
@property (nonatomic, readonly, copy) NSString *protocol;
// Protocols should be an array of strings that turn into Sec-WebSocket-Protocol.
- (instancetype)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithURLRequest:(NSURLRequest *)request;
// Some helper constructors.
- (instancetype)initWithURL:(NSURL *)url protocols:(NSArray *)protocols;
- (instancetype)initWithURL:(NSURL *)url;
// Delegate queue will be dispatch_main_queue by default.
// You cannot set both OperationQueue and dispatch_queue.
- (void)setDelegateOperationQueue:(NSOperationQueue*) queue;
- (void)setDelegateDispatchQueue:(dispatch_queue_t) queue;
// By default, it will schedule itself on +[NSRunLoop RCTSR_networkRunLoop] using defaultModes.
- (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
- (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
// RCTSRWebSockets are intended for one-time-use only. Open should be called once and only once.
- (void)open;
- (void)close;
- (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;
// Send a UTF8 String or Data.
- (void)send:(id)data;
// Send Data (can be nil) in a ping message.
- (void)sendPing:(NSData *)data;
@end
#pragma mark - RCTSRWebSocketDelegate
@protocol RCTSRWebSocketDelegate <NSObject>
// message will either be an NSString if the server is using text
// or NSData if the server is using binary.
- (void)webSocket:(RCTSRWebSocket *)webSocket didReceiveMessage:(id)message;
@optional
- (void)webSocketDidOpen:(RCTSRWebSocket *)webSocket;
- (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error;
- (void)webSocket:(RCTSRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
- (void)webSocket:(RCTSRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload;
@end
#pragma mark - NSURLRequest (CertificateAdditions)
@interface NSURLRequest (CertificateAdditions)
@property (nonatomic, readonly, copy) NSArray *RCTSR_SSLPinnedCertificates;
@end
#pragma mark - NSMutableURLRequest (CertificateAdditions)
@interface NSMutableURLRequest (CertificateAdditions)
@property (nonatomic, copy) NSArray *RCTSR_SSLPinnedCertificates;
@end
#pragma mark - NSRunLoop (RCTSRWebSocket)
@interface NSRunLoop (RCTSRWebSocket)
+ (NSRunLoop *)RCTSR_networkRunLoop;
@end

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@
@interface RCTWebSocketExecutor : NSObject <RCTJavaScriptExecutor>
- (instancetype)initWithURL:(NSURL *)URL;
- (instancetype)initWithURL:(NSURL *)URL NS_DESIGNATED_INITIALIZER;
@end

View File

@ -16,16 +16,17 @@
#import "RCTLog.h"
#import "RCTSparseArray.h"
#import "RCTUtils.h"
#import "SRWebSocket.h"
#import "RCTSRWebSocket.h"
typedef void (^WSMessageCallback)(NSError *error, NSDictionary *reply);
typedef void (^RCTWSMessageCallback)(NSError *error, NSDictionary *reply);
@interface RCTWebSocketExecutor () <RCTSRWebSocketDelegate>
@interface RCTWebSocketExecutor () <SRWebSocketDelegate>
@end
@implementation RCTWebSocketExecutor
{
SRWebSocket *_socket;
RCTSRWebSocket *_socket;
dispatch_queue_t _jsQueue;
RCTSparseArray *_callbacks;
dispatch_semaphore_t _socketOpenSemaphore;
@ -42,7 +43,7 @@ typedef void (^WSMessageCallback)(NSError *error, NSDictionary *reply);
if (self = [super init]) {
_jsQueue = dispatch_queue_create("com.facebook.React.WebSocketExecutor", DISPATCH_QUEUE_SERIAL);
_socket = [[SRWebSocket alloc] initWithURL:URL];
_socket = [[RCTSRWebSocket alloc] initWithURL:URL];
_socket.delegate = self;
_callbacks = [[RCTSparseArray alloc] init];
_injectedObjects = [[NSMutableDictionary alloc] init];
@ -95,28 +96,28 @@ typedef void (^WSMessageCallback)(NSError *error, NSDictionary *reply);
return runtimeIsReady == 0 && initError == nil;
}
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message
- (void)webSocket:(RCTSRWebSocket *)webSocket didReceiveMessage:(id)message
{
NSError *error = nil;
NSDictionary *reply = RCTJSONParse(message, &error);
NSNumber *messageID = reply[@"replyID"];
WSMessageCallback callback = _callbacks[messageID];
RCTWSMessageCallback callback = _callbacks[messageID];
if (callback) {
callback(error, reply);
}
}
- (void)webSocketDidOpen:(SRWebSocket *)webSocket
- (void)webSocketDidOpen:(RCTSRWebSocket *)webSocket
{
dispatch_semaphore_signal(_socketOpenSemaphore);
}
- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error
- (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error
{
RCTLogError(@"WebSocket connection failed with error %@", error);
}
- (void)sendMessage:(NSDictionary *)message context:(NSNumber *)executorID waitForReply:(WSMessageCallback)callback
- (void)sendMessage:(NSDictionary *)message context:(NSNumber *)executorID waitForReply:(RCTWSMessageCallback)callback
{
static NSUInteger lastID = 10000;
@ -190,7 +191,7 @@ typedef void (^WSMessageCallback)(NSError *error, NSDictionary *reply);
- (BOOL)isValid
{
return _socket != nil && _socket.readyState == SR_OPEN;
return _socket != nil && _socket.readyState == RCTSR_OPEN;
}
- (void)dealloc

View File

@ -0,0 +1,14 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "RCTBridgeModule.h"
@interface RCTWebSocketManager : NSObject <RCTBridgeModule>
@end

View File

@ -0,0 +1,116 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "RCTWebSocketManager.h"
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
#import "RCTSRWebSocket.h"
#import "RCTSparseArray.h"
@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
@interface RCTWebSocketManager () <RCTSRWebSocketDelegate>
@end
@implementation RCTWebSocketManager
{
RCTSparseArray *_sockets;
}
RCT_EXPORT_MODULE()
@synthesize bridge = _bridge;
- (instancetype)init
{
if ((self = [super init])) {
_sockets = [[RCTSparseArray alloc] init];
}
return self;
}
- (void)dealloc
{
for (RCTSRWebSocket *socket in _sockets.allObjects) {
socket.delegate = nil;
[socket close];
}
}
RCT_EXPORT_METHOD(connect:(NSURL *)URL socketID:(NSNumber *)socketID)
{
RCTSRWebSocket *webSocket = [[RCTSRWebSocket alloc] initWithURL:URL];
webSocket.delegate = self;
webSocket.reactTag = socketID;
_sockets[socketID] = webSocket;
[webSocket open];
}
RCT_EXPORT_METHOD(send:(NSString *)message socketID:(NSNumber *)socketID)
{
[_sockets[socketID] send:message];
}
RCT_EXPORT_METHOD(close:(NSNumber *)socketID)
{
[_sockets[socketID] close];
_sockets[socketID] = nil;
}
#pragma mark - RCTSRWebSocketDelegate methods
- (void)webSocket:(RCTSRWebSocket *)webSocket didReceiveMessage:(id)message
{
[_bridge.eventDispatcher sendDeviceEventWithName:@"websocketMessage" body:@{
@"data": message,
@"id": webSocket.reactTag
}];
}
- (void)webSocketDidOpen:(RCTSRWebSocket *)webSocket
{
[_bridge.eventDispatcher sendDeviceEventWithName:@"websocketOpen" body:@{
@"id": webSocket.reactTag
}];
}
- (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error
{
[_bridge.eventDispatcher sendDeviceEventWithName:@"websocketFailed" body:@{
@"message":[error localizedDescription],
@"id": webSocket.reactTag
}];
}
- (void)webSocket:(RCTSRWebSocket *)webSocket didCloseWithCode:(NSInteger)code
reason:(NSString *)reason wasClean:(BOOL)wasClean
{
[_bridge.eventDispatcher sendDeviceEventWithName:@"websocketClosed" body:@{
@"code": @(code),
@"reason": reason,
@"clean": @(wasClean),
@"id": webSocket.reactTag
}];
}
@end

View File

@ -0,0 +1,39 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule WebSocket
*
*/
'use strict';
var WebSocketBase = require('WebSocketBase');
class WebSocket extends WebSocketBase {
connectToSocketImpl(url: string): void {
console.warn('WebSocket is not yet supported on Android');
}
closeConnectionImpl(): void{
console.warn('WebSocket is not yet supported on Android');
}
cancelConnectionImpl(): void {
console.warn('WebSocket is not yet supported on Android');
}
sendStringImpl(message: string): void {
console.warn('WebSocket is not yet supported on Android');
}
sendArrayBufferImpl(): void {
console.warn('WebSocket is not yet supported on Android');
}
}
module.exports = WebSocket;

View File

@ -0,0 +1,104 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule WebSocket
*
*/
'use strict';
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
var RCTWebSocketManager = require('NativeModules').WebSocketManager;
var WebSocketBase = require('WebSocketBase');
var WebSocketId = 0;
class WebSocket extends WebSocketBase {
_socketId: number;
_subs: any;
connectToSocketImpl(url: string): void {
this._socketId = WebSocketId++;
RCTWebSocketManager.connect(url, this._socketId);
this._registerEvents(this._socketId);
}
closeConnectionImpl(): void {
RCTWebSocketManager.close(this._socketId);
}
cancelConnectionImpl(): void {
RCTWebSocketManager.close(this._socketId);
}
sendStringImpl(message: string): void {
RCTWebSocketManager.send(message, this._socketId);
}
sendArrayBufferImpl(): void {
// TODO
console.warn('Sending ArrayBuffers is not yet supported');
}
_unregisterEvents(): void {
this._subs.forEach(e => e.remove());
this._subs = [];
}
_registerEvents(id: number): void {
this._subs = [
RCTDeviceEventEmitter.addListener(
'websocketMessage',
function(ev) {
if (ev.id !== id) {
return;
}
this.onmessage && this.onmessage({
data: ev.data
});
}.bind(this)
),
RCTDeviceEventEmitter.addListener(
'websocketOpen',
function(ev) {
if (ev.id !== id) {
return;
}
this.readyState = this.OPEN;
this.onopen && this.onopen();
}.bind(this)
),
RCTDeviceEventEmitter.addListener(
'websocketClosed',
function(ev) {
if (ev.id !== id) {
return;
}
this.readyState = this.CLOSED;
this.onclose && this.onclose(ev);
this._unregisterEvents();
RCTWebSocketManager.close(id);
}.bind(this)
),
RCTDeviceEventEmitter.addListener(
'websocketFailed',
function(ev) {
if (ev.id !== id) {
return;
}
this.onerror && this.onerror(new Error(ev.message));
this._unregisterEvents();
RCTWebSocketManager.close(id);
}.bind(this)
)
];
}
}
module.exports = WebSocket;

View File

@ -0,0 +1,97 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule WebSocketBase
*
*/
'use strict';
/**
* Shared base for platform-specific WebSocket implementations.
*/
class WebSocketBase {
CONNECTING: number;
OPEN: number;
CLOSING: number;
CLOSED: number;
onclose: ?Function;
onerror: ?Function;
onmessage: ?Function;
onopen: ?Function;
binaryType: ?string;
bufferedAmount: number;
extension: ?string;
protocol: ?string;
readyState: number;
url: ?string;
constructor(url: string, protocols: ?any) {
this.CONNECTING = 0;
this.OPEN = 1;
this.CLOSING = 2;
this.CLOSED = 3;
if (!protocols) {
protocols = [];
}
this.connectToSocketImpl(url);
}
close(): void {
if (this.readyState === WebSocketBase.CLOSING ||
this.readyState === WebSocketBase.CLOSED) {
return;
}
if (this.readyState === WebSocketBase.CONNECTING) {
this.cancelConnectionImpl();
}
this.closeConnectionImpl();
}
send(data: any): void {
if (this.readyState === WebSocketBase.CONNECTING) {
throw new Error('INVALID_STATE_ERR');
}
if (typeof data === 'string') {
this.sendStringImpl(data);
} else if (data instanceof ArrayBuffer) {
this.sendArrayBufferImpl(data);
} else {
throw new Error('Not supported data type');
}
}
closeConnectionImpl(): void {
throw new Error('Subclass must define closeConnectionImpl method');
}
connectToSocketImpl(): void {
throw new Error('Subclass must define connectToSocketImpl method');
}
cancelConnectionImpl(): void {
throw new Error('Subclass must define cancelConnectionImpl method');
}
sendStringImpl(): void {
throw new Error('Subclass must define sendStringImpl method');
}
sendArrayBufferImpl(): void {
throw new Error('Subclass must define sendArrayBufferImpl method');
}
}
module.exports = WebSocketBase;

View File

@ -98,8 +98,9 @@ Pod::Spec.new do |s|
ss.preserve_paths = "Libraries/Vibration/*.js"
end
s.subspec 'RCTWebSocketDebugger' do |ss|
s.subspec 'RCTWebSocket' do |ss|
ss.dependency 'React/Core'
ss.source_files = "Libraries/RCTWebSocketDebugger/*.{h,m}"
ss.source_files = "Libraries/WebSocket/*.{h,m}"
ss.preserve_paths = "Libraries/WebSocket/*.js"
end
end

View File

@ -81,7 +81,7 @@ RCT_EXPORT_MODULE()
object:nil];
[notificationCenter addObserver:self
selector:@selector(updateSettings)
selector:@selector(settingsDidChange)
name:NSUserDefaultsDidChangeNotification
object:nil];
@ -94,13 +94,11 @@ RCT_EXPORT_MODULE()
_settings = [[NSMutableDictionary alloc] init];
// Delay setup until after Bridge init
__weak RCTDevMenu *weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf updateSettings];
});
[self settingsDidChange];
#if TARGET_IPHONE_SIMULATOR
__weak RCTDevMenu *weakSelf = self;
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
// Toggle debug menu
@ -127,6 +125,15 @@ RCT_EXPORT_MODULE()
return dispatch_get_main_queue();
}
- (void)settingsDidChange
{
// Needed to prevent a race condition when reloading
__weak RCTDevMenu *weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf updateSettings];
});
}
- (void)updateSettings
{
NSDictionary *settings = [_defaults objectForKey:RCTDevMenuSettingsKey];
@ -269,6 +276,14 @@ RCT_EXPORT_METHOD(reload)
}
case 1: {
Class cls = NSClassFromString(@"RCTWebSocketExecutor");
if (!cls) {
[[[UIAlertView alloc] initWithTitle:@"Chrome Debugger Unavailable"
message:@"You need to include the RCTWebSocket library to enable Chrome debugging"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
return;
}
self.executorClass = (_executorClass == cls) ? Nil : cls;
break;
}