Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v11] [RTDB] Remove SocketRocket #13100

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[v11] [RTDB] Remove SocketRocket
  • Loading branch information
paulb777 committed Jun 8, 2024
commit 88e51da94558d47d5063058fc4d8ef1a8dd1ac10
58 changes: 0 additions & 58 deletions FirebaseDatabase/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -277,61 +277,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


--------------------------
SocketRocket
--------------------------
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.

$OpenBSD: base64.c,v 1.5 2006/10/21 09:55:03 otto Exp $

Copyright (c) 1996 by Internet Software Consortium.

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

Portions Copyright (c) 1995 by International Business Machines, Inc.

International Business Machines, Inc. (hereinafter called IBM) grants
permission under its copyrights to use, copy, modify, and distribute this
Software with or without fee, provided that the above copyright notice and
all paragraphs of this notice appear in all copies, and that the name of IBM
not be used in connection with the marketing of any product incorporating
the Software or modifications thereof, without specific, written prior
permission.

To the extent it has a right to do so, IBM grants an immunity from suit
under its patents, if any, for the use, sale or manufacture of products to
the extent that such products are used for performing Domain Name System
dynamic updates in TCP/IP networks by means of the Software. No immunity is
granted for any product per se or for any other function of any product.

THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
66 changes: 9 additions & 57 deletions FirebaseDatabase/Sources/Core/FPersistentConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -553,24 +553,6 @@ - (void)openNetworkConnectionWithContext:
[self.realtime open];
}

#if !TARGET_OS_WATCH
static void reachabilityCallback(SCNetworkReachabilityRef ref,
SCNetworkReachabilityFlags flags, void *info) {
if (flags & kSCNetworkReachabilityFlagsReachable) {
FFLog(@"I-RDB034014",
@"Network became reachable. Trigger a connection attempt");
FPersistentConnection *self = (__bridge FPersistentConnection *)info;
// Reset reconnect delay
[self.retryHelper signalSuccess];
if (self->connectionState == ConnectionStateDisconnected) {
[self tryScheduleReconnect];
}
} else {
FFLog(@"I-RDB034015", @"Network is not reachable");
}
}
#endif // !TARGET_OS_WATCH

- (void)enteringForeground {
dispatch_async(self.dispatchQueue, ^{
// Reset reconnect delay
Expand All @@ -583,45 +565,15 @@ - (void)enteringForeground {

- (void)setupNotifications {
#if TARGET_OS_WATCH
if (@available(watchOS 7.0, *)) {
__weak FPersistentConnection *weakSelf = self;
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserverForName:WKApplicationWillEnterForegroundNotification
object:nil
queue:nil
usingBlock:^(NSNotification *_Nonnull note) {
[weakSelf enteringForeground];
}];
}
#else
NSString *const *foregroundConstant = (NSString *const *)dlsym(
RTLD_DEFAULT, "UIApplicationWillEnterForegroundNotification");
if (foregroundConstant) {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(enteringForeground)
name:*foregroundConstant
object:nil];
}
// An empty address is interpreted a generic internet access
struct sockaddr_in zeroAddress;
bzero(&zeroAddress, sizeof(zeroAddress));
zeroAddress.sin_len = sizeof(zeroAddress);
zeroAddress.sin_family = AF_INET;
reachability = SCNetworkReachabilityCreateWithAddress(
kCFAllocatorDefault, (const struct sockaddr *)&zeroAddress);
SCNetworkReachabilityContext ctx = {0, (__bridge void *)(self), NULL, NULL,
NULL};
if (SCNetworkReachabilitySetCallback(reachability, reachabilityCallback,
&ctx)) {
SCNetworkReachabilitySetDispatchQueue(reachability, self.dispatchQueue);
} else {
FFLog(@"I-RDB034016",
@"Failed to set up network reachability monitoring");
CFRelease(reachability);
reachability = NULL;
}
#endif // !TARGET_OS_WATCH
__weak FPersistentConnection *weakSelf = self;
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserverForName:WKApplicationWillEnterForegroundNotification
object:nil
queue:nil
usingBlock:^(NSNotification *_Nonnull note) {
[weakSelf enteringForeground];
}];
#endif // TARGET_OS_WATCH
}

- (void)sendAuthAndRestoreStateAfterComplete:(BOOL)restoreStateAfterComplete {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ NS_ASSUME_NONNULL_BEGIN
* read or write data, use `FIRDatabase.reference()`.
*/
NS_SWIFT_NAME(Database) __attribute__((availability(
watchos, introduced = 6.0, deprecated = 9.0,
watchos, introduced = 7.0, deprecated = 9.0,
message = "Socket connections are not supported on watchOS 9.0 and higher. "
"Use the Firebase Database REST API instead. See "
"github.com/firebase/firebase-ios-sdk/issues/10195 "
"for more details.")))
@interface FIRDatabase : NSObject
API_AVAILABLE(ios(12.0), macos(10.15), macCatalyst(15), tvos(13.0),
watchos(7.0)) @interface FIRDatabase : NSObject

/**
* The NSObject initializer that has been marked as unavailable. Use the
Expand Down
22 changes: 0 additions & 22 deletions FirebaseDatabase/Sources/Realtime/FWebSocketConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,11 @@
*/

#import "FirebaseDatabase/Sources/Utilities/FUtilities.h"
#if !TARGET_OS_WATCH
#import "FirebaseDatabase/Sources/third_party/SocketRocket/FSRWebSocket.h"
#endif // !TARGET_OS_WATCH
#import <Foundation/Foundation.h>

@protocol FWebSocketDelegate;

#if !TARGET_OS_WATCH
@interface FWebSocketConnection
: NSObject <FSRWebSocketDelegate, NSURLSessionWebSocketDelegate>
#else
@interface FWebSocketConnection : NSObject <NSURLSessionWebSocketDelegate>
#endif // else !TARGET_OS_WATCH

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

Expand All @@ -42,20 +34,6 @@
- (void)start;
- (void)send:(NSDictionary *)dictionary;

// Ignore FSRWebSocketDelegate calls on watchOS.
#if !TARGET_OS_WATCH
- (void)webSocket:(FSRWebSocket *)webSocket didReceiveMessage:(id)message;

// Exclude the `webSocket` argument since it isn't used in this codebase and it
// allows for better code sharing with watchOS.
- (void)webSocketDidOpen;
- (void)webSocket:(FSRWebSocket *)webSocket didFailWithError:(NSError *)error;
- (void)webSocket:(FSRWebSocket *)webSocket
didCloseWithCode:(NSInteger)code
reason:(NSString *)reason
wasClean:(BOOL)wasClean;
#endif // !TARGET_OS_WATCH

@end

@protocol FWebSocketDelegate <NSObject>
Expand Down
92 changes: 11 additions & 81 deletions FirebaseDatabase/Sources/Realtime/FWebSocketConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ - (void)closeIfNeverConnected;
@property(nonatomic, strong)
NSURLSessionWebSocketTask *webSocketTask API_AVAILABLE(
macos(10.15), ios(13.0), watchos(6.0), tvos(13.0));
#if !TARGET_OS_WATCH
@property(nonatomic, strong) FSRWebSocket *webSocket;
#endif // TARGET_OS_WATCH
@property(nonatomic, strong) NSNumber *connectionId;
@property(nonatomic, readwrite) int totalFrames;
@property(nonatomic, readonly) BOOL buffering;
Expand All @@ -72,9 +69,6 @@ - (void)nop:(NSTimer *)timer;
@implementation FWebSocketConnection

@synthesize delegate;
#if !TARGET_OS_WATCH
@synthesize webSocket;
#endif // !TARGET_OS_WATCH
@synthesize connectionId;

- (instancetype)initWith:(FRepoInfo *)repoInfo
Expand Down Expand Up @@ -126,33 +120,18 @@ - (instancetype)initWith:(FRepoInfo *)repoInfo
#elif
#error("missing platform")
#endif
if (@available(watchOS 7.0, *)) {
[[NSNotificationCenter defaultCenter]
addObserverForName:resignName
object:nil
queue:opQueue
usingBlock:^(NSNotification *_Nonnull note) {
FFLog(@"I-RDB083015",
@"Received notification that application "
@"will resign, "
@"closing web socket.");
[self onClosed];
}];
}
[[NSNotificationCenter defaultCenter]
addObserverForName:resignName
object:nil
queue:opQueue
usingBlock:^(NSNotification *_Nonnull note) {
FFLog(@"I-RDB083015",
@"Received notification that application "
@"will resign, "
@"closing web socket.");
[self onClosed];
}];
}
#if !TARGET_OS_WATCH
else {
// TODO(mmaksym): Remove googleAppID and userAgent from FSRWebSocket
// as they are passed via NSURLRequest.
self.webSocket =
[[FSRWebSocket alloc] initWithURLRequest:req
queue:queue
googleAppID:googleAppID
andUserAgent:userAgent];
[self.webSocket setDelegateDispatchQueue:queue];
self.webSocket.delegate = self;
}
#endif // TARGET_OS_WATCH
}
return self;
}
Expand Down Expand Up @@ -219,11 +198,6 @@ - (void)open {
// sending data.
[self receiveWebSocketData];
}
#if !TARGET_OS_WATCH
else {
[self.webSocket open];
}
#endif // TARGET_OS_WATCH
dispatch_time_t when = dispatch_time(
DISPATCH_TIME_NOW, kWebsocketConnectTimeout * NSEC_PER_SEC);
dispatch_after(when, self.dispatchQueue, ^{
Expand All @@ -241,11 +215,6 @@ - (void)close {
cancelWithCloseCode:NSURLSessionWebSocketCloseCodeNormalClosure
reason:nil];
}
#if !TARGET_OS_WATCH
else {
[self.webSocket close];
}
#endif // TARGET_OS_WATCH
}

- (void)start {
Expand Down Expand Up @@ -391,31 +360,6 @@ - (void)receiveWebSocketData API_AVAILABLE(macos(10.15), ios(13.0),
}];
}

#if !TARGET_OS_WATCH

#pragma mark SRWebSocketDelegate implementation

- (void)webSocket:(FSRWebSocket *)webSocket didReceiveMessage:(id)message {
[self handleIncomingFrame:message];
}

- (void)webSocket:(FSRWebSocket *)webSocket didFailWithError:(NSError *)error {
FFLog(@"I-RDB083010", @"(wsc:%@) didFailWithError didFailWithError: %@",
self.connectionId, [error description]);
[self onClosed];
}

- (void)webSocket:(FSRWebSocket *)webSocket
didCloseWithCode:(NSInteger)code
reason:(NSString *)reason
wasClean:(BOOL)wasClean {
FFLog(@"I-RDB083011", @"(wsc:%@) didCloseWithCode: %ld %@",
self.connectionId, (long)code, reason);
[self onClosed];
}

#endif // !TARGET_OS_WATCH

// Common to both SRWebSocketDelegate and URLSessionWebSocketDelegate.

- (void)webSocketDidOpen {
Expand Down Expand Up @@ -454,12 +398,6 @@ - (void)sendStringToWebSocket:(NSString *)string {
}
}];
}
#if !TARGET_OS_WATCH
else {
// Use existing SocketRocket implementation.
[self.webSocket send:string];
}
#endif // !TARGET_OS_WATCH
}

/**
Expand All @@ -485,11 +423,6 @@ - (void)closeIfNeverConnected {
NSURLSessionWebSocketCloseCodeNoStatusReceived
reason:nil];
}
#if !TARGET_OS_WATCH
else {
[self.webSocket close];
}
#endif // TARGET_OS_WATCH
}
}

Expand All @@ -509,9 +442,6 @@ - (void)onClosed {
watchOS 6.0, *)) {
self.webSocketTask = nil;
}
#if !TARGET_OS_WATCH
self.webSocket = nil;
#endif // TARGET_OS_WATCH
if (keepAlive.isValid) {
[keepAlive invalidate];
}
Expand Down
3 changes: 1 addition & 2 deletions FirebaseDatabase/Sources/Utilities/FStringUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

#import "FirebaseDatabase/Sources/Utilities/FStringUtilities.h"
#import "FirebaseDatabase/Sources/third_party/SocketRocket/NSData+SRB64Additions.h"
#import <CommonCrypto/CommonDigest.h>

@implementation FStringUtilities
Expand All @@ -32,7 +31,7 @@ + (NSString *)base64EncodedSha1:(NSString *)str {
CC_SHA1(data.bytes, (unsigned int)data.length, digest);
NSData *output = [[NSData alloc] initWithBytes:digest
length:CC_SHA1_DIGEST_LENGTH];
return [FSRUtilities base64EncodedStringFromData:output];
return [output base64EncodedStringWithOptions:0];
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved
}

+ (NSString *)urlDecoded:(NSString *)url {
Expand Down
Loading
Loading