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

feat(ios): parse websocket url from bundle url #1474

Merged
merged 6 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ios/sdk/base/HippyBatchedBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,15 @@ - (void)setUpDevClientWithName:(NSString *)name {
devInfo.ipAddress = [url host];
devInfo.port = [NSString stringWithFormat:@"%@", [url port]];
devInfo.versionId = [HippyBundleURLProvider parseVersionId:[url path]];
[devInfo parseWsURLWithURLQuery:[url query]];
}
else {
HippyBundleURLProvider *bundleURLProvider = [HippyBundleURLProvider sharedInstance];
devInfo.scheme = bundleURLProvider.scheme;
devInfo.ipAddress = bundleURLProvider.localhostIP;
devInfo.port = bundleURLProvider.localhostPort;
devInfo.versionId = bundleURLProvider.versionId;
devInfo.wsURL = bundleURLProvider.wsURL;
}
_devManager = [[HippyDevManager alloc] initWithBridge:self.parentBridge devInfo:devInfo contextName:name];
}
Expand Down
1 change: 1 addition & 0 deletions ios/sdk/base/HippyBundleURLProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
@property (nonatomic, copy, readonly) NSString *debugPathUrl;
@property (nonatomic, copy, readonly) NSString *versionId;
@property (nonatomic, copy, readonly) NSString *scheme;
@property (nonatomic, copy, readonly) NSString *wsURL;

/**
* @return instancetype
Expand Down
9 changes: 8 additions & 1 deletion ios/sdk/base/HippyBundleURLProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ @interface HippyBundleURLProvider ()
@property (nonatomic, copy) NSString *debugPathUrl;
@property (nonatomic, copy) NSString *versionId;
@property (nonatomic, copy) NSString *scheme;
@property (nonatomic, copy) NSString *wsURL;

@end

Expand Down Expand Up @@ -69,6 +70,8 @@ - (instancetype)init {
_localhostIP = @"localhost";
_localhostPort = @"38989";
self.debugPathUrl = @"/index.bundle?platform=ios&dev=true&minify=false";
// websocket url after url encode
//_wsURL = @"debugURL=wss%3A%2F%2Fdevtools.hippy.myqcloud.com%3A443%2Fdebugger-proxy";
}
return self;
}
Expand Down Expand Up @@ -103,7 +106,11 @@ - (NSString *)localhost {

- (NSString *)bundleURLString {
NSString *scheme = _scheme.length > 0 ? _scheme : HippyBundleURLSchemeHttp;
return [NSString stringWithFormat:@"%@://%@%@", scheme, self.localhost, self.debugPathUrl];
NSString *debugPath = _debugPathUrl;
if (_wsURL.length > 0) {
debugPath = [NSString stringWithFormat:@"%@&%@", debugPath, _wsURL];
}
return [NSString stringWithFormat:@"%@://%@%@", scheme, self.localhost, debugPath];
}

@end
31 changes: 24 additions & 7 deletions ios/sdk/debug/devtools/HippyDevInfo.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
//
// HippyDevInfo.h
// HippyDemo
//
// Created by nolantang on 2022/1/12.
// Copyright © 2022 tencent. All rights reserved.
//
/*!
* iOS SDK
*
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* 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>

Expand All @@ -14,7 +28,10 @@
@property (nonatomic, copy) NSString *ipAddress;
@property (nonatomic, copy) NSString *port;
@property (nonatomic, copy) NSString *versionId;
@property (nonatomic, copy) NSString *wsURL;

- (void)setScheme:(NSString *)scheme;

- (void)parseWsURLWithURLQuery:(NSString *)query;

@end
55 changes: 48 additions & 7 deletions ios/sdk/debug/devtools/HippyDevInfo.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
//
// HippyDevInfo.m
// HippyDemo
//
// Created by nolantang on 2022/1/12.
// Copyright © 2022 tencent. All rights reserved.
//
/*!
* iOS SDK
*
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* 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 "HippyDevInfo.h"

NSString *const HippyDevWebSocketSchemeWs = @"ws";
NSString *const HippyDevWebSocketSchemeWss = @"wss";
NSString *const HippyDevWebSocketInfoDebugURL = @"debugURL=";

@implementation HippyDevInfo

Expand All @@ -20,4 +35,30 @@ - (void)setScheme:(NSString *)scheme {
}
}

- (void)parseWsURLWithURLQuery:(NSString *)query {
if (query.length <= 0) {
return;
}
NSArray<NSString *> *queryItems = [query componentsSeparatedByString:@"&"];
if (queryItems.count <= 0) {
return;
}
NSString *debugWsURL = @"";
for (NSString *item in queryItems) {
if ([item hasPrefix:HippyDevWebSocketInfoDebugURL]) {
debugWsURL = [item stringByRemovingPercentEncoding];
break;
}

}
if (debugWsURL.length <= 0) {
return;
}
NSRange range = [debugWsURL rangeOfString:HippyDevWebSocketInfoDebugURL];
if (range.location + range.length > debugWsURL.length) {
return;
}
_wsURL = [debugWsURL substringFromIndex:range.location + range.length];
}

@end
7 changes: 6 additions & 1 deletion ios/sdk/debug/devtools/HippyDevWebSocketClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ - (instancetype)initWithDevInfo:(HippyDevInfo *)devInfo contextName:(NSString *)
NSString *encodeName = [contextName stringByAddingPercentEncodingWithAllowedCharacters:allowedChar];
NSString *deviceName = [[UIDevice currentDevice] name];
NSString *encodedDeviceName = [deviceName stringByAddingPercentEncodingWithAllowedCharacters:allowedChar];
NSString *devAddress = [NSString stringWithFormat:@"%@://%@:%@/debugger-proxy?clientId=%@&platform=1&role=ios_client&contextName=%@&deviceName=%@", devInfo.scheme, devInfo.ipAddress, devInfo.port?:@"38989", uuid, encodeName, encodedDeviceName];
NSString *addressPrefix = [NSString stringWithFormat:@"%@://%@:%@/debugger-proxy", devInfo.scheme, devInfo.ipAddress, devInfo.port?:@"38989"];
if (devInfo.wsURL.length > 0) {
// wsURL has a high priority
addressPrefix = devInfo.wsURL;
}
NSString *devAddress = [NSString stringWithFormat:@"%@?clientId=%@&platform=1&role=ios_client&contextName=%@&deviceName=%@", addressPrefix, uuid, encodeName, encodedDeviceName];
if (devInfo.versionId.length > 0) {
devAddress = [NSString stringWithFormat:@"%@&hash=%@", devAddress, devInfo.versionId];
}
Expand Down
28 changes: 21 additions & 7 deletions ios/sdk/debug/devtools/inspector/model/HippyCSSPropsDefine.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
//
// HippyCSSPropsDefine.m
// HippyDemo
//
// Created by nolantang on 2021/10/27.
// Copyright © 2021 tencent. All rights reserved.
//
/*!
* iOS SDK
*
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* 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 "HippyCSSPropsDefine.h"

Expand Down