Skip to content
This repository was archived by the owner on Sep 4, 2021. It is now read-only.

Commit 17bd3ff

Browse files
author
devfd
committed
iOS web workers
1 parent 4a50a86 commit 17bd3ff

File tree

5 files changed

+404
-0
lines changed

5 files changed

+404
-0
lines changed
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
// !$*UTF8*$!
2+
{
3+
archiveVersion = 1;
4+
classes = {
5+
};
6+
objectVersion = 46;
7+
objects = {
8+
9+
/* Begin PBXBuildFile section */
10+
9F97657B1CDC88260091EE06 /* WorkerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F9765771CDC88260091EE06 /* WorkerManager.m */; };
11+
9F97657C1CDC88260091EE06 /* WorkerSelfManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F97657A1CDC88260091EE06 /* WorkerSelfManager.m */; };
12+
/* End PBXBuildFile section */
13+
14+
/* Begin PBXCopyFilesBuildPhase section */
15+
9F9765691CDC87F00091EE06 /* CopyFiles */ = {
16+
isa = PBXCopyFilesBuildPhase;
17+
buildActionMask = 2147483647;
18+
dstPath = "include/$(PRODUCT_NAME)";
19+
dstSubfolderSpec = 16;
20+
files = (
21+
);
22+
runOnlyForDeploymentPostprocessing = 0;
23+
};
24+
/* End PBXCopyFilesBuildPhase section */
25+
26+
/* Begin PBXFileReference section */
27+
9F97656B1CDC87F00091EE06 /* libWorkers.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libWorkers.a; sourceTree = BUILT_PRODUCTS_DIR; };
28+
9F9765771CDC88260091EE06 /* WorkerManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WorkerManager.m; sourceTree = "<group>"; };
29+
9F9765781CDC88260091EE06 /* WorkerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerManager.h; sourceTree = "<group>"; };
30+
9F9765791CDC88260091EE06 /* WorkerSelfManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerSelfManager.h; sourceTree = "<group>"; };
31+
9F97657A1CDC88260091EE06 /* WorkerSelfManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WorkerSelfManager.m; sourceTree = "<group>"; };
32+
/* End PBXFileReference section */
33+
34+
/* Begin PBXFrameworksBuildPhase section */
35+
9F9765681CDC87F00091EE06 /* Frameworks */ = {
36+
isa = PBXFrameworksBuildPhase;
37+
buildActionMask = 2147483647;
38+
files = (
39+
);
40+
runOnlyForDeploymentPostprocessing = 0;
41+
};
42+
/* End PBXFrameworksBuildPhase section */
43+
44+
/* Begin PBXGroup section */
45+
9F9765621CDC87EF0091EE06 = {
46+
isa = PBXGroup;
47+
children = (
48+
9F97656D1CDC87F00091EE06 /* Workers */,
49+
9F97656C1CDC87F00091EE06 /* Products */,
50+
);
51+
sourceTree = "<group>";
52+
};
53+
9F97656C1CDC87F00091EE06 /* Products */ = {
54+
isa = PBXGroup;
55+
children = (
56+
9F97656B1CDC87F00091EE06 /* libWorkers.a */,
57+
);
58+
name = Products;
59+
sourceTree = "<group>";
60+
};
61+
9F97656D1CDC87F00091EE06 /* Workers */ = {
62+
isa = PBXGroup;
63+
children = (
64+
9F9765771CDC88260091EE06 /* WorkerManager.m */,
65+
9F9765781CDC88260091EE06 /* WorkerManager.h */,
66+
9F9765791CDC88260091EE06 /* WorkerSelfManager.h */,
67+
9F97657A1CDC88260091EE06 /* WorkerSelfManager.m */,
68+
);
69+
path = Workers;
70+
sourceTree = "<group>";
71+
};
72+
/* End PBXGroup section */
73+
74+
/* Begin PBXNativeTarget section */
75+
9F97656A1CDC87F00091EE06 /* Workers */ = {
76+
isa = PBXNativeTarget;
77+
buildConfigurationList = 9F9765741CDC87F00091EE06 /* Build configuration list for PBXNativeTarget "Workers" */;
78+
buildPhases = (
79+
9F9765671CDC87F00091EE06 /* Sources */,
80+
9F9765681CDC87F00091EE06 /* Frameworks */,
81+
9F9765691CDC87F00091EE06 /* CopyFiles */,
82+
);
83+
buildRules = (
84+
);
85+
dependencies = (
86+
);
87+
name = Workers;
88+
productName = Workers;
89+
productReference = 9F97656B1CDC87F00091EE06 /* libWorkers.a */;
90+
productType = "com.apple.product-type.library.static";
91+
};
92+
/* End PBXNativeTarget section */
93+
94+
/* Begin PBXProject section */
95+
9F9765631CDC87EF0091EE06 /* Project object */ = {
96+
isa = PBXProject;
97+
attributes = {
98+
LastUpgradeCheck = 0730;
99+
ORGANIZATIONNAME = Apptailor;
100+
TargetAttributes = {
101+
9F97656A1CDC87F00091EE06 = {
102+
CreatedOnToolsVersion = 7.3;
103+
};
104+
};
105+
};
106+
buildConfigurationList = 9F9765661CDC87EF0091EE06 /* Build configuration list for PBXProject "Workers" */;
107+
compatibilityVersion = "Xcode 3.2";
108+
developmentRegion = English;
109+
hasScannedForEncodings = 0;
110+
knownRegions = (
111+
en,
112+
);
113+
mainGroup = 9F9765621CDC87EF0091EE06;
114+
productRefGroup = 9F97656C1CDC87F00091EE06 /* Products */;
115+
projectDirPath = "";
116+
projectRoot = "";
117+
targets = (
118+
9F97656A1CDC87F00091EE06 /* Workers */,
119+
);
120+
};
121+
/* End PBXProject section */
122+
123+
/* Begin PBXSourcesBuildPhase section */
124+
9F9765671CDC87F00091EE06 /* Sources */ = {
125+
isa = PBXSourcesBuildPhase;
126+
buildActionMask = 2147483647;
127+
files = (
128+
9F97657C1CDC88260091EE06 /* WorkerSelfManager.m in Sources */,
129+
9F97657B1CDC88260091EE06 /* WorkerManager.m in Sources */,
130+
);
131+
runOnlyForDeploymentPostprocessing = 0;
132+
};
133+
/* End PBXSourcesBuildPhase section */
134+
135+
/* Begin XCBuildConfiguration section */
136+
9F9765721CDC87F00091EE06 /* Debug */ = {
137+
isa = XCBuildConfiguration;
138+
buildSettings = {
139+
ALWAYS_SEARCH_USER_PATHS = NO;
140+
CLANG_ANALYZER_NONNULL = YES;
141+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
142+
CLANG_CXX_LIBRARY = "libc++";
143+
CLANG_ENABLE_MODULES = YES;
144+
CLANG_ENABLE_OBJC_ARC = YES;
145+
CLANG_WARN_BOOL_CONVERSION = YES;
146+
CLANG_WARN_CONSTANT_CONVERSION = YES;
147+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
148+
CLANG_WARN_EMPTY_BODY = YES;
149+
CLANG_WARN_ENUM_CONVERSION = YES;
150+
CLANG_WARN_INT_CONVERSION = YES;
151+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
152+
CLANG_WARN_UNREACHABLE_CODE = YES;
153+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
154+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
155+
COPY_PHASE_STRIP = NO;
156+
DEBUG_INFORMATION_FORMAT = dwarf;
157+
ENABLE_STRICT_OBJC_MSGSEND = YES;
158+
ENABLE_TESTABILITY = YES;
159+
GCC_C_LANGUAGE_STANDARD = gnu99;
160+
GCC_DYNAMIC_NO_PIC = NO;
161+
GCC_NO_COMMON_BLOCKS = YES;
162+
GCC_OPTIMIZATION_LEVEL = 0;
163+
GCC_PREPROCESSOR_DEFINITIONS = (
164+
"DEBUG=1",
165+
"$(inherited)",
166+
);
167+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
168+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
169+
GCC_WARN_UNDECLARED_SELECTOR = YES;
170+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
171+
GCC_WARN_UNUSED_FUNCTION = YES;
172+
GCC_WARN_UNUSED_VARIABLE = YES;
173+
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
174+
MTL_ENABLE_DEBUG_INFO = YES;
175+
ONLY_ACTIVE_ARCH = YES;
176+
SDKROOT = iphoneos;
177+
};
178+
name = Debug;
179+
};
180+
9F9765731CDC87F00091EE06 /* Release */ = {
181+
isa = XCBuildConfiguration;
182+
buildSettings = {
183+
ALWAYS_SEARCH_USER_PATHS = NO;
184+
CLANG_ANALYZER_NONNULL = YES;
185+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
186+
CLANG_CXX_LIBRARY = "libc++";
187+
CLANG_ENABLE_MODULES = YES;
188+
CLANG_ENABLE_OBJC_ARC = YES;
189+
CLANG_WARN_BOOL_CONVERSION = YES;
190+
CLANG_WARN_CONSTANT_CONVERSION = YES;
191+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
192+
CLANG_WARN_EMPTY_BODY = YES;
193+
CLANG_WARN_ENUM_CONVERSION = YES;
194+
CLANG_WARN_INT_CONVERSION = YES;
195+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
196+
CLANG_WARN_UNREACHABLE_CODE = YES;
197+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
198+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
199+
COPY_PHASE_STRIP = NO;
200+
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
201+
ENABLE_NS_ASSERTIONS = NO;
202+
ENABLE_STRICT_OBJC_MSGSEND = YES;
203+
GCC_C_LANGUAGE_STANDARD = gnu99;
204+
GCC_NO_COMMON_BLOCKS = YES;
205+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
206+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
207+
GCC_WARN_UNDECLARED_SELECTOR = YES;
208+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
209+
GCC_WARN_UNUSED_FUNCTION = YES;
210+
GCC_WARN_UNUSED_VARIABLE = YES;
211+
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
212+
MTL_ENABLE_DEBUG_INFO = NO;
213+
SDKROOT = iphoneos;
214+
VALIDATE_PRODUCT = YES;
215+
};
216+
name = Release;
217+
};
218+
9F9765751CDC87F00091EE06 /* Debug */ = {
219+
isa = XCBuildConfiguration;
220+
buildSettings = {
221+
HEADER_SEARCH_PATHS = "$(SRCROOT)/../../react-native/React/**";
222+
OTHER_LDFLAGS = "-ObjC";
223+
PRODUCT_NAME = "$(TARGET_NAME)";
224+
SKIP_INSTALL = YES;
225+
};
226+
name = Debug;
227+
};
228+
9F9765761CDC87F00091EE06 /* Release */ = {
229+
isa = XCBuildConfiguration;
230+
buildSettings = {
231+
HEADER_SEARCH_PATHS = "$(SRCROOT)/../../react-native/React/**";
232+
OTHER_LDFLAGS = "-ObjC";
233+
PRODUCT_NAME = "$(TARGET_NAME)";
234+
SKIP_INSTALL = YES;
235+
};
236+
name = Release;
237+
};
238+
/* End XCBuildConfiguration section */
239+
240+
/* Begin XCConfigurationList section */
241+
9F9765661CDC87EF0091EE06 /* Build configuration list for PBXProject "Workers" */ = {
242+
isa = XCConfigurationList;
243+
buildConfigurations = (
244+
9F9765721CDC87F00091EE06 /* Debug */,
245+
9F9765731CDC87F00091EE06 /* Release */,
246+
);
247+
defaultConfigurationIsVisible = 0;
248+
defaultConfigurationName = Release;
249+
};
250+
9F9765741CDC87F00091EE06 /* Build configuration list for PBXNativeTarget "Workers" */ = {
251+
isa = XCConfigurationList;
252+
buildConfigurations = (
253+
9F9765751CDC87F00091EE06 /* Debug */,
254+
9F9765761CDC87F00091EE06 /* Release */,
255+
);
256+
defaultConfigurationIsVisible = 0;
257+
defaultConfigurationName = Release;
258+
};
259+
/* End XCConfigurationList section */
260+
};
261+
rootObject = 9F9765631CDC87EF0091EE06 /* Project object */;
262+
}

ios/Workers/WorkerManager.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
#ifndef WorkerManager_h
3+
#define WorkerManager_h
4+
5+
#import "RCTBridgeModule.h"
6+
7+
@interface WorkerManager : NSObject <RCTBridgeModule>
8+
@end
9+
10+
#endif /* WorkerManager_h */

ios/Workers/WorkerManager.m

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#import "WorkerManager.h"
2+
#import "WorkerSelfManager.h"
3+
#include <stdlib.h>
4+
#import "RCTBridge.h"
5+
#import "RCTBridge+Private.h"
6+
#import "RCTEventDispatcher.h"
7+
8+
@implementation WorkerManager
9+
10+
@synthesize bridge = _bridge;
11+
12+
NSMutableDictionary *workers;
13+
14+
RCT_EXPORT_MODULE();
15+
16+
RCT_REMAP_METHOD(startWorker,
17+
name: (NSString *)name
18+
resolver:(RCTPromiseResolveBlock)resolve
19+
rejecter:(RCTPromiseRejectBlock)reject)
20+
{
21+
if (workers == nil) {
22+
workers = [[NSMutableDictionary alloc] init];
23+
}
24+
25+
int workerId = abs(arc4random());
26+
NSString *bundleURL = [NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=ios&dev=true", name];
27+
28+
NSLog(@"starting Worker %@", bundleURL);
29+
30+
31+
RCTBridge *workerBridge = [[RCTBridge alloc] initWithBundleURL:[NSURL URLWithString:bundleURL]
32+
moduleProvider:nil
33+
launchOptions:nil];
34+
35+
WorkerSelfManager *workerSelf = [workerBridge moduleForName:@"WorkerSelfManager"];
36+
[workerSelf setWorkerId:workerId];
37+
[workerSelf setParentBridge:self.bridge];
38+
39+
40+
[workers setObject:workerBridge forKey:[NSNumber numberWithInt:workerId]];
41+
resolve([NSNumber numberWithInt:workerId]);
42+
}
43+
44+
RCT_EXPORT_METHOD(stopWorker:(int)workerId)
45+
{
46+
if (workers == nil) {
47+
NSLog(@"Empty list of workers. abort stopping worker with id %i", workerId);
48+
return;
49+
}
50+
51+
RCTBridge *workerBridge = workers[[NSNumber numberWithInt:workerId]];
52+
if (workerBridge == nil) {
53+
NSLog(@"Worker is NIl. abort stopping worker with id %i", workerId);
54+
return;
55+
}
56+
57+
[workerBridge invalidate];
58+
[workers removeObjectForKey:[NSNumber numberWithInt:workerId]];
59+
}
60+
61+
RCT_EXPORT_METHOD(postWorkerMessage: (int)workerId message:(NSString *)message)
62+
{
63+
if (workers == nil) {
64+
NSLog(@"Empty list of workers. abort posting to worker with id %i", workerId);
65+
return;
66+
}
67+
68+
RCTBridge *workerBridge = workers[[NSNumber numberWithInt:workerId]];
69+
if (workerBridge == nil) {
70+
NSLog(@"Worker is NIl. abort posting to worker with id %i", workerId);
71+
return;
72+
}
73+
74+
[workerBridge.eventDispatcher sendAppEventWithName:@"WorkerMessage"
75+
body:message];
76+
}
77+
78+
- (void)invalidate {
79+
if (workers == nil) {
80+
return;
81+
}
82+
83+
for (NSNumber *workerId in workers) {
84+
RCTBridge *workerBridge = workers[workerId];
85+
[workerBridge invalidate];
86+
}
87+
88+
[workers removeAllObjects];
89+
workers = nil;
90+
}
91+
92+
@end

ios/Workers/WorkerSelfManager.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
#ifndef WorkerSelfManager_h
3+
#define WorkerSelfManager_h
4+
5+
#import "RCTBridgeModule.h"
6+
7+
@interface WorkerSelfManager : NSObject <RCTBridgeModule>
8+
@property int workerId;
9+
@property RCTBridge *parentBridge;
10+
@end
11+
12+
#endif /* WorkerSelfManager_h */

0 commit comments

Comments
 (0)