Skip to content

Commit 25d88b4

Browse files
committed
Support connections over HTTPS from HTTP web page.
1 parent 1fd085c commit 25d88b4

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ result.code()
112112
+---------------------------------+----------------------------------------------+---------------------------------------------------------------------------------------+
113113
| Type | Value | Description |
114114
+=================================+==============================================+=======================================================================================+
115-
| studio.protocol.AuthResultCode | Optional: One of the following: |
115+
| studio.protocol.AuthResultCode | Optional: One of the following: | |
116116
+ +----------------------------------------------+---------------------------------------------------------------------------------------+
117117
| | - eCredentialsRequired | |
118118
+ +----------------------------------------------+---------------------------------------------------------------------------------------+

index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ studio.internal = (function(proto) {
714714
var appConnection = this;
715715
var appName = "";
716716
var appId = undefined;
717-
var appUrl = (location.protocol=="https:" ? proto.WSS_PREFIX : proto.WS_PREFIX) + url;
717+
var appUrl = composeUrl(url);
718718
var socket = new WebSocket(appUrl);
719719
var handler = new proto.Handler(socket, notificationListener);
720720
var requests = [];
@@ -803,6 +803,22 @@ studio.internal = (function(proto) {
803803
socket.onmessage = onMessage;
804804
socket.onerror = onError;
805805

806+
function composeUrl(url) {
807+
var result = (location.protocol=="https:" ? proto.WSS_PREFIX : proto.WS_PREFIX) + url; //default
808+
if (URL.canParse(url)) {
809+
var u = new URL(url);
810+
if (u.protocol && u.host) {
811+
if (u.protocol=="https:")
812+
result = proto.WSS_PREFIX + u.host;
813+
else if (u.protocol=="http:")
814+
result = proto.WS_PREFIX + u.host;
815+
else
816+
result = u.origin;
817+
}
818+
}
819+
return result;
820+
}
821+
806822
function send(message) {
807823
if (socket.readyState == WebSocket.OPEN) {
808824
socket.send(message.toArrayBuffer());

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cdp-client",
3-
"version": "2.2.2",
3+
"version": "2.3.0",
44
"description": "A simple Javascript interface for the CDP Studio development platform that allows Javascript applications to interact with",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)