Skip to content

Commit 5894657

Browse files
authored
feat(websockets): visionOS and catalyst support (#18)
* feat(websockets): visionOS support * ci: select xcode 15.4 * chore: add pre-built versions * fix: visionos device and catalyst target
1 parent b8734fb commit 5894657

File tree

38 files changed

+1493
-7
lines changed

38 files changed

+1493
-7
lines changed

.github/workflows/lint-and-build.yml

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ env:
66

77
on:
88
push:
9-
branches: [ "master" ]
9+
branches: ['master']
1010
pull_request:
11-
branches: [ "master" ]
11+
branches: ['master']
1212

1313
jobs:
1414
lint:
@@ -47,6 +47,16 @@ jobs:
4747
- uses: nrwl/nx-set-shas@v2
4848
with:
4949
main-branch-name: 'master'
50+
- name: Xcode Select Version
51+
# see available xcode versions in https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md#xcode
52+
uses: mobiledevops/xcode-select-version-action@v1
53+
with:
54+
xcode-select-version: 15.4
55+
- name: Install visionOS platform
56+
run: |
57+
defaults write com.apple.dt.Xcode AllowUnsupportedVisionOSHost -bool YES
58+
defaults write com.apple.CoreSimulator AllowUnsupportedVisionOSHost -bool YES
59+
xcodebuild -downloadPlatform visionOS
5060
- name: yarn install
5161
run: yarn --immutable
5262
- name: Build.all affected

packages/nativescript-websockets/native-src/ios/NativeScriptWebSockets.xcodeproj/project.pbxproj

+8-2
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,12 @@
366366
MARKETING_VERSION = 1.0;
367367
PRODUCT_BUNDLE_IDENTIFIER = "com.valor-software.NativeScriptWebSockets";
368368
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
369+
SDKROOT = "";
369370
SKIP_INSTALL = YES;
371+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
372+
SUPPORTS_MACCATALYST = YES;
370373
SWIFT_EMIT_LOC_STRINGS = YES;
371-
TARGETED_DEVICE_FAMILY = "1,2";
374+
TARGETED_DEVICE_FAMILY = "1,2,7";
372375
};
373376
name = Debug;
374377
};
@@ -392,9 +395,12 @@
392395
MARKETING_VERSION = 1.0;
393396
PRODUCT_BUNDLE_IDENTIFIER = "com.valor-software.NativeScriptWebSockets";
394397
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
398+
SDKROOT = "";
395399
SKIP_INSTALL = YES;
400+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
401+
SUPPORTS_MACCATALYST = YES;
396402
SWIFT_EMIT_LOC_STRINGS = YES;
397-
TARGETED_DEVICE_FAMILY = "1,2";
403+
TARGETED_DEVICE_FAMILY = "1,2,7";
398404
};
399405
name = Release;
400406
};

packages/nativescript-websockets/native-src/ios/build.sh

+49-3
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,62 @@ xcodebuild \
3535
SKIP_INSTALL=NO \
3636
-quiet
3737

38+
echo "Build for Mac Catalyst"
39+
xcodebuild \
40+
-project $PACKAGENAME.xcodeproj \
41+
-scheme $PACKAGENAME \
42+
-configuration Release \
43+
-destination "platform=macOS,variant=Mac Catalyst" \
44+
clean build \
45+
BUILD_DIR=$OUTPUTPATH \
46+
CODE_SIGN_IDENTITY="" \
47+
CODE_SIGNING_REQUIRED=NO \
48+
SKIP_INSTALL=NO \
49+
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
50+
-quiet
51+
52+
echo "Build for visionos device"
53+
xcodebuild \
54+
-project $PACKAGENAME.xcodeproj \
55+
-scheme $PACKAGENAME \
56+
-configuration Release \
57+
-destination "generic/platform=visionOS" \
58+
clean build \
59+
BUILD_DIR=$OUTPUTPATH \
60+
SKIP_INSTALL=NO \
61+
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
62+
-quiet
63+
64+
echo "Build for visionos simulator"
65+
xcodebuild \
66+
-project $PACKAGENAME.xcodeproj \
67+
-scheme $PACKAGENAME \
68+
-sdk xrsimulator \
69+
-configuration Release \
70+
clean build \
71+
BUILD_DIR=$OUTPUTPATH \
72+
-destination "generic/platform=xrsimulator" \
73+
EXCLUDED_ARCHS="i386 x86_64" \
74+
CODE_SIGN_IDENTITY="" \
75+
CODE_SIGNING_REQUIRED=NO \
76+
SKIP_INSTALL=NO \
77+
-quiet
78+
3879
echo "Creating XCFramework"
3980
xcodebuild \
4081
-create-xcframework \
4182
-framework $OUTPUTPATH/Release-iphoneos/$PACKAGENAME.framework \
4283
-debug-symbols $OUTPUTPATH/Release-iphoneos/$PACKAGENAME.framework.dSYM \
4384
-framework $OUTPUTPATH/Release-iphonesimulator/$PACKAGENAME.framework \
4485
-debug-symbols $OUTPUTPATH/Release-iphonesimulator/$PACKAGENAME.framework.dSYM \
86+
-framework $OUTPUTPATH/Release-maccatalyst/$PACKAGENAME.framework \
87+
-debug-symbols $OUTPUTPATH/Release-maccatalyst/$PACKAGENAME.framework.dSYM \
88+
-framework $OUTPUTPATH/Release-xros/$PACKAGENAME.framework \
89+
-debug-symbols $OUTPUTPATH/Release-xros/$PACKAGENAME.framework.dSYM \
90+
-framework $OUTPUTPATH/Release-xrsimulator/$PACKAGENAME.framework \
91+
-debug-symbols $OUTPUTPATH/Release-xrsimulator/$PACKAGENAME.framework.dSYM \
4592
-output $OUTPUTPATH/$PACKAGENAME.xcframework
4693

47-
4894
mkdir -p $COPYPATH
49-
rm -rf $COPYPATH/$PACKAGENAME.xcframework
50-
cp -R $OUTPUTPATH/$PACKAGENAME.xcframework $COPYPATH/
95+
rm -rf $COPYPATH/$PACKAGENAME.xcframework
96+
cp -R $OUTPUTPATH/$PACKAGENAME.xcframework $COPYPATH/

packages/nativescript-websockets/platforms/ios/NativeScriptWebSockets.xcframework/Info.plist

+52
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@
2020
<key>SupportedPlatform</key>
2121
<string>ios</string>
2222
</dict>
23+
<dict>
24+
<key>BinaryPath</key>
25+
<string>NativeScriptWebSockets.framework/Versions/A/NativeScriptWebSockets</string>
26+
<key>DebugSymbolsPath</key>
27+
<string>dSYMs</string>
28+
<key>LibraryIdentifier</key>
29+
<string>ios-arm64-maccatalyst</string>
30+
<key>LibraryPath</key>
31+
<string>NativeScriptWebSockets.framework</string>
32+
<key>SupportedArchitectures</key>
33+
<array>
34+
<string>arm64</string>
35+
</array>
36+
<key>SupportedPlatform</key>
37+
<string>ios</string>
38+
<key>SupportedPlatformVariant</key>
39+
<string>maccatalyst</string>
40+
</dict>
2341
<dict>
2442
<key>BinaryPath</key>
2543
<string>NativeScriptWebSockets.framework/NativeScriptWebSockets</string>
@@ -39,6 +57,40 @@
3957
<key>SupportedPlatformVariant</key>
4058
<string>simulator</string>
4159
</dict>
60+
<dict>
61+
<key>BinaryPath</key>
62+
<string>NativeScriptWebSockets.framework/NativeScriptWebSockets</string>
63+
<key>DebugSymbolsPath</key>
64+
<string>dSYMs</string>
65+
<key>LibraryIdentifier</key>
66+
<string>xros-arm64</string>
67+
<key>LibraryPath</key>
68+
<string>NativeScriptWebSockets.framework</string>
69+
<key>SupportedArchitectures</key>
70+
<array>
71+
<string>arm64</string>
72+
</array>
73+
<key>SupportedPlatform</key>
74+
<string>xros</string>
75+
</dict>
76+
<dict>
77+
<key>BinaryPath</key>
78+
<string>NativeScriptWebSockets.framework/NativeScriptWebSockets</string>
79+
<key>DebugSymbolsPath</key>
80+
<string>dSYMs</string>
81+
<key>LibraryIdentifier</key>
82+
<string>xros-arm64-simulator</string>
83+
<key>LibraryPath</key>
84+
<string>NativeScriptWebSockets.framework</string>
85+
<key>SupportedArchitectures</key>
86+
<array>
87+
<string>arm64</string>
88+
</array>
89+
<key>SupportedPlatform</key>
90+
<string>xros</string>
91+
<key>SupportedPlatformVariant</key>
92+
<string>simulator</string>
93+
</dict>
4294
</array>
4395
<key>CFBundlePackageType</key>
4496
<string>XFWK</string>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/Headers
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/Modules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/NativeScriptWebSockets
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/PrivateHeaders
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/Resources
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// NativeScriptWebSockets.h
3+
// NativeScriptWebSockets
4+
//
5+
// Created by Eduardo Speroni on 2/25/22.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
10+
//! Project version number for NativeScriptWebSockets.
11+
FOUNDATION_EXPORT double NativeScriptWebSocketsVersionNumber;
12+
13+
//! Project version string for NativeScriptWebSockets.
14+
FOUNDATION_EXPORT const unsigned char NativeScriptWebSocketsVersionString[];
15+
16+
// In this header, you should import all the public headers of your framework using statements like #import <NativeScriptWebSockets/PublicHeader.h>
17+
18+
#import "RCTSRWebSocket.h"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
//
2+
// Copyright 2012 Square Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#import <Foundation/Foundation.h>
18+
#import <Security/SecCertificate.h>
19+
20+
typedef NS_ENUM(unsigned int, RCTSRReadyState) {
21+
RCTSR_CONNECTING = 0,
22+
RCTSR_OPEN = 1,
23+
RCTSR_CLOSING = 2,
24+
RCTSR_CLOSED = 3,
25+
};
26+
27+
typedef NS_ENUM(NSInteger, RCTSRStatusCode) {
28+
RCTSRStatusCodeNormal = 1000,
29+
RCTSRStatusCodeGoingAway = 1001,
30+
RCTSRStatusCodeProtocolError = 1002,
31+
RCTSRStatusCodeUnhandledType = 1003,
32+
// 1004 reserved.
33+
RCTSRStatusNoStatusReceived = 1005,
34+
// 1004-1006 reserved.
35+
RCTSRStatusCodeInvalidUTF8 = 1007,
36+
RCTSRStatusCodePolicyViolated = 1008,
37+
RCTSRStatusCodeMessageTooBig = 1009,
38+
};
39+
40+
@class RCTSRWebSocket;
41+
42+
extern NSString *const RCTSRWebSocketErrorDomain;
43+
extern NSString *const RCTSRHTTPResponseErrorKey;
44+
45+
#pragma mark - RCTSRWebSocketDelegate
46+
47+
@protocol RCTSRWebSocketDelegate;
48+
49+
#pragma mark - RCTSRWebSocket
50+
51+
@interface RCTSRWebSocket : NSObject <NSStreamDelegate>
52+
53+
@property (nonatomic, weak) id<RCTSRWebSocketDelegate> delegate;
54+
55+
@property (nonatomic, readonly) RCTSRReadyState readyState;
56+
@property (nonatomic, readonly, strong) NSURL *url;
57+
58+
// This returns the negotiated protocol.
59+
// It will be nil until after the handshake completes.
60+
@property (nonatomic, readonly, copy) NSString *protocol;
61+
62+
// Protocols should be an array of strings that turn into Sec-WebSocket-Protocol.
63+
- (instancetype)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray<NSString *> *)protocols NS_DESIGNATED_INITIALIZER;
64+
- (instancetype)initWithURLRequest:(NSURLRequest *)request;
65+
66+
// Some helper constructors.
67+
- (instancetype)initWithURL:(NSURL *)url protocols:(NSArray<NSString *> *)protocols;
68+
- (instancetype)initWithURL:(NSURL *)url;
69+
70+
// Delegate queue will be dispatch_main_queue by default.
71+
// You cannot set both OperationQueue and dispatch_queue.
72+
- (void)setDelegateOperationQueue:(NSOperationQueue *)queue;
73+
- (void)setDelegateDispatchQueue:(dispatch_queue_t)queue;
74+
75+
// By default, it will schedule itself on +[NSRunLoop RCTSR_networkRunLoop] using defaultModes.
76+
- (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
77+
- (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
78+
79+
// RCTSRWebSockets are intended for one-time-use only. Open should be called once and only once.
80+
- (void)open;
81+
82+
- (void)close;
83+
- (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;
84+
85+
// Send a UTF8 String or Data.
86+
- (void)send:(id)data;
87+
88+
// Send Data (can be nil) in a ping message.
89+
- (void)sendPing:(NSData *)data;
90+
91+
@end
92+
93+
#pragma mark - RCTSRWebSocketDelegate
94+
95+
@protocol RCTSRWebSocketDelegate <NSObject>
96+
97+
// message will either be an NSString if the server is using text
98+
// or NSData if the server is using binary.
99+
- (void)webSocket:(RCTSRWebSocket *)webSocket didReceiveMessage:(id)message;
100+
101+
@optional
102+
103+
- (void)webSocketDidOpen:(RCTSRWebSocket *)webSocket;
104+
- (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error;
105+
- (void)webSocket:(RCTSRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
106+
- (void)webSocket:(RCTSRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload;
107+
108+
@end
109+
110+
#pragma mark - NSURLRequest (CertificateAdditions)
111+
112+
@interface NSURLRequest (CertificateAdditions)
113+
114+
@property (nonatomic, readonly, copy) NSArray *RCTSR_SSLPinnedCertificates;
115+
116+
@end
117+
118+
#pragma mark - NSMutableURLRequest (CertificateAdditions)
119+
120+
@interface NSMutableURLRequest (CertificateAdditions)
121+
122+
@property (nonatomic, copy) NSArray *RCTSR_SSLPinnedCertificates;
123+
124+
@end
125+
126+
#pragma mark - NSRunLoop (RCTSRWebSocket)
127+
128+
@interface NSRunLoop (RCTSRWebSocket)
129+
130+
+ (NSRunLoop *)RCTSR_networkRunLoop;
131+
132+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
framework module NativeScriptWebSockets {
2+
umbrella header "NativeScriptWebSockets.h"
3+
export *
4+
5+
module * { export * }
6+
}

0 commit comments

Comments
 (0)