Skip to content

Commit 4453f72

Browse files
paulb777pragatimodi
authored andcommitted
[v11] [RTDB] Remove SocketRocket (#13100)
1 parent 8080089 commit 4453f72

File tree

16 files changed

+32
-2690
lines changed

16 files changed

+32
-2690
lines changed

FirebaseDatabase/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
been removed. See
44
https://firebase.google.com/docs/ios/swift-migration for migration
55
instructions.
6+
- [removed] Socket Rocket has been removed from the implementation. There should
7+
be no impact on functionality. (#13100)
68

79
# 10.27.0
810
- [changed] Update internal socket implementation to use `NSURLSessionWebSocket` where

FirebaseDatabase/LICENSE

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -277,61 +277,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
277277
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
278278
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
279279
THE SOFTWARE.
280-
281-
282-
--------------------------
283-
SocketRocket
284-
--------------------------
285-
Copyright 2012 Square Inc.
286-
287-
Licensed under the Apache License, Version 2.0 (the "License");
288-
you may not use this file except in compliance with the License.
289-
You may obtain a copy of the License at
290-
291-
http://www.apache.org/licenses/LICENSE-2.0
292-
293-
Unless required by applicable law or agreed to in writing, software
294-
distributed under the License is distributed on an "AS IS" BASIS,
295-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
296-
See the License for the specific language governing permissions and
297-
limitations under the License.
298-
299-
$OpenBSD: base64.c,v 1.5 2006/10/21 09:55:03 otto Exp $
300-
301-
Copyright (c) 1996 by Internet Software Consortium.
302-
303-
Permission to use, copy, modify, and distribute this software for any
304-
purpose with or without fee is hereby granted, provided that the above
305-
copyright notice and this permission notice appear in all copies.
306-
307-
THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
308-
ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
309-
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
310-
CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
311-
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
312-
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
313-
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
314-
SOFTWARE.
315-
316-
Portions Copyright (c) 1995 by International Business Machines, Inc.
317-
318-
International Business Machines, Inc. (hereinafter called IBM) grants
319-
permission under its copyrights to use, copy, modify, and distribute this
320-
Software with or without fee, provided that the above copyright notice and
321-
all paragraphs of this notice appear in all copies, and that the name of IBM
322-
not be used in connection with the marketing of any product incorporating
323-
the Software or modifications thereof, without specific, written prior
324-
permission.
325-
326-
To the extent it has a right to do so, IBM grants an immunity from suit
327-
under its patents, if any, for the use, sale or manufacture of products to
328-
the extent that such products are used for performing Domain Name System
329-
dynamic updates in TCP/IP networks by means of the Software. No immunity is
330-
granted for any product per se or for any other function of any product.
331-
332-
THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
333-
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
334-
PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
335-
DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
336-
OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
337-
IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.

FirebaseDatabase/Sources/Core/FPersistentConnection.m

Lines changed: 9 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -553,24 +553,6 @@ - (void)openNetworkConnectionWithContext:
553553
[self.realtime open];
554554
}
555555

556-
#if !TARGET_OS_WATCH
557-
static void reachabilityCallback(SCNetworkReachabilityRef ref,
558-
SCNetworkReachabilityFlags flags, void *info) {
559-
if (flags & kSCNetworkReachabilityFlagsReachable) {
560-
FFLog(@"I-RDB034014",
561-
@"Network became reachable. Trigger a connection attempt");
562-
FPersistentConnection *self = (__bridge FPersistentConnection *)info;
563-
// Reset reconnect delay
564-
[self.retryHelper signalSuccess];
565-
if (self->connectionState == ConnectionStateDisconnected) {
566-
[self tryScheduleReconnect];
567-
}
568-
} else {
569-
FFLog(@"I-RDB034015", @"Network is not reachable");
570-
}
571-
}
572-
#endif // !TARGET_OS_WATCH
573-
574556
- (void)enteringForeground {
575557
dispatch_async(self.dispatchQueue, ^{
576558
// Reset reconnect delay
@@ -583,45 +565,15 @@ - (void)enteringForeground {
583565

584566
- (void)setupNotifications {
585567
#if TARGET_OS_WATCH
586-
if (@available(watchOS 7.0, *)) {
587-
__weak FPersistentConnection *weakSelf = self;
588-
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
589-
[center addObserverForName:WKApplicationWillEnterForegroundNotification
590-
object:nil
591-
queue:nil
592-
usingBlock:^(NSNotification *_Nonnull note) {
593-
[weakSelf enteringForeground];
594-
}];
595-
}
596-
#else
597-
NSString *const *foregroundConstant = (NSString *const *)dlsym(
598-
RTLD_DEFAULT, "UIApplicationWillEnterForegroundNotification");
599-
if (foregroundConstant) {
600-
[[NSNotificationCenter defaultCenter]
601-
addObserver:self
602-
selector:@selector(enteringForeground)
603-
name:*foregroundConstant
604-
object:nil];
605-
}
606-
// An empty address is interpreted a generic internet access
607-
struct sockaddr_in zeroAddress;
608-
bzero(&zeroAddress, sizeof(zeroAddress));
609-
zeroAddress.sin_len = sizeof(zeroAddress);
610-
zeroAddress.sin_family = AF_INET;
611-
reachability = SCNetworkReachabilityCreateWithAddress(
612-
kCFAllocatorDefault, (const struct sockaddr *)&zeroAddress);
613-
SCNetworkReachabilityContext ctx = {0, (__bridge void *)(self), NULL, NULL,
614-
NULL};
615-
if (SCNetworkReachabilitySetCallback(reachability, reachabilityCallback,
616-
&ctx)) {
617-
SCNetworkReachabilitySetDispatchQueue(reachability, self.dispatchQueue);
618-
} else {
619-
FFLog(@"I-RDB034016",
620-
@"Failed to set up network reachability monitoring");
621-
CFRelease(reachability);
622-
reachability = NULL;
623-
}
624-
#endif // !TARGET_OS_WATCH
568+
__weak FPersistentConnection *weakSelf = self;
569+
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
570+
[center addObserverForName:WKApplicationWillEnterForegroundNotification
571+
object:nil
572+
queue:nil
573+
usingBlock:^(NSNotification *_Nonnull note) {
574+
[weakSelf enteringForeground];
575+
}];
576+
#endif // TARGET_OS_WATCH
625577
}
626578

627579
- (void)sendAuthAndRestoreStateAfterComplete:(BOOL)restoreStateAfterComplete {

FirebaseDatabase/Sources/Public/FirebaseDatabase/FIRDatabase.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ NS_ASSUME_NONNULL_BEGIN
2727
* read or write data, use `FIRDatabase.reference()`.
2828
*/
2929
NS_SWIFT_NAME(Database) __attribute__((availability(
30-
watchos, introduced = 6.0, deprecated = 9.0,
30+
watchos, introduced = 7.0, deprecated = 9.0,
3131
message = "Socket connections are not supported on watchOS 9.0 and higher. "
3232
"Use the Firebase Database REST API instead. See "
3333
"github.com/firebase/firebase-ios-sdk/issues/10195 "
3434
"for more details.")))
35-
@interface FIRDatabase : NSObject
35+
API_AVAILABLE(ios(12.0), macos(10.15), macCatalyst(13), tvos(13.0),
36+
watchos(7.0)) @interface FIRDatabase : NSObject
3637

3738
/**
3839
* The NSObject initializer that has been marked as unavailable. Use the

FirebaseDatabase/Sources/Realtime/FWebSocketConnection.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,11 @@
1515
*/
1616

1717
#import "FirebaseDatabase/Sources/Utilities/FUtilities.h"
18-
#if !TARGET_OS_WATCH
19-
#import "FirebaseDatabase/Sources/third_party/SocketRocket/FSRWebSocket.h"
20-
#endif // !TARGET_OS_WATCH
2118
#import <Foundation/Foundation.h>
2219

2320
@protocol FWebSocketDelegate;
2421

25-
#if !TARGET_OS_WATCH
26-
@interface FWebSocketConnection
27-
: NSObject <FSRWebSocketDelegate, NSURLSessionWebSocketDelegate>
28-
#else
2922
@interface FWebSocketConnection : NSObject <NSURLSessionWebSocketDelegate>
30-
#endif // else !TARGET_OS_WATCH
3123

3224
@property(nonatomic, weak) id<FWebSocketDelegate> delegate;
3325

@@ -42,20 +34,6 @@
4234
- (void)start;
4335
- (void)send:(NSDictionary *)dictionary;
4436

45-
// Ignore FSRWebSocketDelegate calls on watchOS.
46-
#if !TARGET_OS_WATCH
47-
- (void)webSocket:(FSRWebSocket *)webSocket didReceiveMessage:(id)message;
48-
49-
// Exclude the `webSocket` argument since it isn't used in this codebase and it
50-
// allows for better code sharing with watchOS.
51-
- (void)webSocketDidOpen;
52-
- (void)webSocket:(FSRWebSocket *)webSocket didFailWithError:(NSError *)error;
53-
- (void)webSocket:(FSRWebSocket *)webSocket
54-
didCloseWithCode:(NSInteger)code
55-
reason:(NSString *)reason
56-
wasClean:(BOOL)wasClean;
57-
#endif // !TARGET_OS_WATCH
58-
5937
@end
6038

6139
@protocol FWebSocketDelegate <NSObject>

FirebaseDatabase/Sources/Realtime/FWebSocketConnection.m

Lines changed: 11 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ - (void)closeIfNeverConnected;
5656
@property(nonatomic, strong)
5757
NSURLSessionWebSocketTask *webSocketTask API_AVAILABLE(
5858
macos(10.15), ios(13.0), watchos(6.0), tvos(13.0));
59-
#if !TARGET_OS_WATCH
60-
@property(nonatomic, strong) FSRWebSocket *webSocket;
61-
#endif // TARGET_OS_WATCH
6259
@property(nonatomic, strong) NSNumber *connectionId;
6360
@property(nonatomic, readwrite) int totalFrames;
6461
@property(nonatomic, readonly) BOOL buffering;
@@ -72,9 +69,6 @@ - (void)nop:(NSTimer *)timer;
7269
@implementation FWebSocketConnection
7370

7471
@synthesize delegate;
75-
#if !TARGET_OS_WATCH
76-
@synthesize webSocket;
77-
#endif // !TARGET_OS_WATCH
7872
@synthesize connectionId;
7973

8074
- (instancetype)initWith:(FRepoInfo *)repoInfo
@@ -126,33 +120,18 @@ - (instancetype)initWith:(FRepoInfo *)repoInfo
126120
#elif
127121
#error("missing platform")
128122
#endif
129-
if (@available(watchOS 7.0, *)) {
130-
[[NSNotificationCenter defaultCenter]
131-
addObserverForName:resignName
132-
object:nil
133-
queue:opQueue
134-
usingBlock:^(NSNotification *_Nonnull note) {
135-
FFLog(@"I-RDB083015",
136-
@"Received notification that application "
137-
@"will resign, "
138-
@"closing web socket.");
139-
[self onClosed];
140-
}];
141-
}
123+
[[NSNotificationCenter defaultCenter]
124+
addObserverForName:resignName
125+
object:nil
126+
queue:opQueue
127+
usingBlock:^(NSNotification *_Nonnull note) {
128+
FFLog(@"I-RDB083015",
129+
@"Received notification that application "
130+
@"will resign, "
131+
@"closing web socket.");
132+
[self onClosed];
133+
}];
142134
}
143-
#if !TARGET_OS_WATCH
144-
else {
145-
// TODO(mmaksym): Remove googleAppID and userAgent from FSRWebSocket
146-
// as they are passed via NSURLRequest.
147-
self.webSocket =
148-
[[FSRWebSocket alloc] initWithURLRequest:req
149-
queue:queue
150-
googleAppID:googleAppID
151-
andUserAgent:userAgent];
152-
[self.webSocket setDelegateDispatchQueue:queue];
153-
self.webSocket.delegate = self;
154-
}
155-
#endif // TARGET_OS_WATCH
156135
}
157136
return self;
158137
}
@@ -219,11 +198,6 @@ - (void)open {
219198
// sending data.
220199
[self receiveWebSocketData];
221200
}
222-
#if !TARGET_OS_WATCH
223-
else {
224-
[self.webSocket open];
225-
}
226-
#endif // TARGET_OS_WATCH
227201
dispatch_time_t when = dispatch_time(
228202
DISPATCH_TIME_NOW, kWebsocketConnectTimeout * NSEC_PER_SEC);
229203
dispatch_after(when, self.dispatchQueue, ^{
@@ -241,11 +215,6 @@ - (void)close {
241215
cancelWithCloseCode:NSURLSessionWebSocketCloseCodeNormalClosure
242216
reason:nil];
243217
}
244-
#if !TARGET_OS_WATCH
245-
else {
246-
[self.webSocket close];
247-
}
248-
#endif // TARGET_OS_WATCH
249218
}
250219

251220
- (void)start {
@@ -391,31 +360,6 @@ - (void)receiveWebSocketData API_AVAILABLE(macos(10.15), ios(13.0),
391360
}];
392361
}
393362

394-
#if !TARGET_OS_WATCH
395-
396-
#pragma mark SRWebSocketDelegate implementation
397-
398-
- (void)webSocket:(FSRWebSocket *)webSocket didReceiveMessage:(id)message {
399-
[self handleIncomingFrame:message];
400-
}
401-
402-
- (void)webSocket:(FSRWebSocket *)webSocket didFailWithError:(NSError *)error {
403-
FFLog(@"I-RDB083010", @"(wsc:%@) didFailWithError didFailWithError: %@",
404-
self.connectionId, [error description]);
405-
[self onClosed];
406-
}
407-
408-
- (void)webSocket:(FSRWebSocket *)webSocket
409-
didCloseWithCode:(NSInteger)code
410-
reason:(NSString *)reason
411-
wasClean:(BOOL)wasClean {
412-
FFLog(@"I-RDB083011", @"(wsc:%@) didCloseWithCode: %ld %@",
413-
self.connectionId, (long)code, reason);
414-
[self onClosed];
415-
}
416-
417-
#endif // !TARGET_OS_WATCH
418-
419363
// Common to both SRWebSocketDelegate and URLSessionWebSocketDelegate.
420364

421365
- (void)webSocketDidOpen {
@@ -454,12 +398,6 @@ - (void)sendStringToWebSocket:(NSString *)string {
454398
}
455399
}];
456400
}
457-
#if !TARGET_OS_WATCH
458-
else {
459-
// Use existing SocketRocket implementation.
460-
[self.webSocket send:string];
461-
}
462-
#endif // !TARGET_OS_WATCH
463401
}
464402

465403
/**
@@ -485,11 +423,6 @@ - (void)closeIfNeverConnected {
485423
NSURLSessionWebSocketCloseCodeNoStatusReceived
486424
reason:nil];
487425
}
488-
#if !TARGET_OS_WATCH
489-
else {
490-
[self.webSocket close];
491-
}
492-
#endif // TARGET_OS_WATCH
493426
}
494427
}
495428

@@ -509,9 +442,6 @@ - (void)onClosed {
509442
watchOS 6.0, *)) {
510443
self.webSocketTask = nil;
511444
}
512-
#if !TARGET_OS_WATCH
513-
self.webSocket = nil;
514-
#endif // TARGET_OS_WATCH
515445
if (keepAlive.isValid) {
516446
[keepAlive invalidate];
517447
}

FirebaseDatabase/Sources/Utilities/FStringUtilities.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
#import "FirebaseDatabase/Sources/Utilities/FStringUtilities.h"
18-
#import "FirebaseDatabase/Sources/third_party/SocketRocket/NSData+SRB64Additions.h"
1918
#import <CommonCrypto/CommonDigest.h>
2019

2120
@implementation FStringUtilities
@@ -32,7 +31,7 @@ + (NSString *)base64EncodedSha1:(NSString *)str {
3231
CC_SHA1(data.bytes, (unsigned int)data.length, digest);
3332
NSData *output = [[NSData alloc] initWithBytes:digest
3433
length:CC_SHA1_DIGEST_LENGTH];
35-
return [FSRUtilities base64EncodedStringFromData:output];
34+
return [output base64EncodedStringWithOptions:0];
3635
}
3736

3837
+ (NSString *)urlDecoded:(NSString *)url {

0 commit comments

Comments
 (0)