Adjust to handle SSL

This commit is contained in:
Herbert Wolverson 2023-08-12 15:17:20 +00:00
parent ff66424677
commit 63152e9c18
9 changed files with 176 additions and 165 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -7,8 +7,13 @@ export class Bus {
constructor() {
const currentUrlWithoutAnchors = window.location.href.split('#')[0].replace("https://", "").replace("http://", "");
const url = "ws://" + currentUrlWithoutAnchors + "ws";
initialize_wss(url);
if (window.location.href.startsWith("https://")) {
const url = "wss://" + currentUrlWithoutAnchors + "ws";
initialize_wss(url);
} else {
const url = "ws://" + currentUrlWithoutAnchors + "ws";
initialize_wss(url);
}
}
updateConnected() {

View File

@ -187,11 +187,11 @@ export interface InitOutput {
readonly request_ext_capacity_graph: (a: number, b: number, c: number, d: number) => void;
readonly request_ext_capacity_ap: (a: number, b: number, c: number, d: number) => void;
readonly request_ext_signal_ap: (a: number, b: number, c: number, d: number) => void;
readonly __wbindgen_export_0: (a: number) => number;
readonly __wbindgen_export_1: (a: number, b: number, c: number) => number;
readonly __wbindgen_export_0: (a: number, b: number) => number;
readonly __wbindgen_export_1: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_export_2: WebAssembly.Table;
readonly __wbindgen_export_3: (a: number, b: number, c: number) => void;
readonly __wbindgen_export_4: (a: number, b: number) => void;
readonly __wbindgen_export_4: (a: number, b: number, c: number) => void;
readonly __wbindgen_export_5: (a: number) => void;
}

View File

@ -1,25 +1,5 @@
let wasm;
const heap = new Array(128).fill(undefined);
heap.push(undefined, null, true, false);
function getObject(idx) { return heap[idx]; }
let heap_next = heap.length;
function dropObject(idx) {
if (idx < 132) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
@ -38,6 +18,12 @@ function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}
const heap = new Array(128).fill(undefined);
heap.push(undefined, null, true, false);
let heap_next = heap.length;
function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
@ -47,6 +33,8 @@ function addHeapObject(obj) {
return idx;
}
function getObject(idx) { return heap[idx]; }
function debugString(val) {
// primitive types
const type = typeof val;
@ -133,14 +121,14 @@ function passStringToWasm0(arg, malloc, realloc) {
if (realloc === undefined) {
const buf = cachedTextEncoder.encode(arg);
const ptr = malloc(buf.length) >>> 0;
const ptr = malloc(buf.length, 1) >>> 0;
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
WASM_VECTOR_LEN = buf.length;
return ptr;
}
let len = arg.length;
let ptr = malloc(len) >>> 0;
let ptr = malloc(len, 1) >>> 0;
const mem = getUint8Memory0();
@ -156,7 +144,7 @@ function passStringToWasm0(arg, malloc, realloc) {
if (offset !== 0) {
arg = arg.slice(offset);
}
ptr = realloc(ptr, len, len = offset + arg.length * 3) >>> 0;
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
const ret = encodeString(arg, view);
@ -176,6 +164,18 @@ function getInt32Memory0() {
return cachedInt32Memory0;
}
function dropObject(idx) {
if (idx < 132) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
function makeMutClosure(arg0, arg1, dtor, f) {
const state = { a: arg0, b: arg1, cnt: 1, dtor };
const real = (...args) => {
@ -599,10 +599,10 @@ async function __wbg_load(module, imports) {
function __wbg_get_imports() {
const imports = {};
imports.wbg = {};
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
imports.wbg.__wbg_log_cd48b3599daf93ee = function(arg0, arg1) {
console.log(getStringFromWasm0(arg0, arg1));
};
imports.wbg.__wbg_new_39e958ac9d5cae7d = function() { return handleError(function (arg0, arg1) {
imports.wbg.__wbg_new_b66404b6322c59bf = function() { return handleError(function (arg0, arg1) {
const ret = new WebSocket(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
}, arguments) };
@ -610,24 +610,21 @@ function __wbg_get_imports() {
const ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};
imports.wbg.__wbg_setbinaryType_2e2320b177c86b17 = function(arg0, arg1) {
imports.wbg.__wbg_setbinaryType_096c70c4a9d97499 = function(arg0, arg1) {
getObject(arg0).binaryType = takeObject(arg1);
};
imports.wbg.__wbg_setonclose_6b22bc5d93628786 = function(arg0, arg1) {
imports.wbg.__wbg_setonclose_4210cf3908b79b31 = function(arg0, arg1) {
getObject(arg0).onclose = getObject(arg1);
};
imports.wbg.__wbg_setonerror_9f7532626d7a9ce2 = function(arg0, arg1) {
imports.wbg.__wbg_setonerror_2fa7120354e9ec15 = function(arg0, arg1) {
getObject(arg0).onerror = getObject(arg1);
};
imports.wbg.__wbg_setonopen_6fd8b28538150568 = function(arg0, arg1) {
imports.wbg.__wbg_setonopen_419ca0e52d8f19e8 = function(arg0, arg1) {
getObject(arg0).onopen = getObject(arg1);
};
imports.wbg.__wbg_setonmessage_493b82147081ec7e = function(arg0, arg1) {
imports.wbg.__wbg_setonmessage_809f60b68c2a6938 = function(arg0, arg1) {
getObject(arg0).onmessage = getObject(arg1);
};
imports.wbg.__wbg_log_cd48b3599daf93ee = function(arg0, arg1) {
console.log(getStringFromWasm0(arg0, arg1));
};
imports.wbg.__wbg_windowbusgetToken_eab6ac8f06d69af2 = function(arg0) {
const ret = window.bus.getToken();
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
@ -635,11 +632,11 @@ function __wbg_get_imports() {
getInt32Memory0()[arg0 / 4 + 1] = len1;
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
};
imports.wbg.__wbg_data_ef47af9c565d228b = function(arg0) {
imports.wbg.__wbg_data_ab99ae4a2e1e8bc9 = function(arg0) {
const ret = getObject(arg0).data;
return addHeapObject(ret);
};
imports.wbg.__wbg_instanceof_ArrayBuffer_de688b806c28ff28 = function(arg0) {
imports.wbg.__wbg_instanceof_ArrayBuffer_39ac22089b74fddb = function(arg0) {
let result;
try {
result = getObject(arg0) instanceof ArrayBuffer;
@ -649,11 +646,11 @@ function __wbg_get_imports() {
const ret = result;
return ret;
};
imports.wbg.__wbg_new_bc5d9aad3f9ac80e = function(arg0) {
imports.wbg.__wbg_new_8125e318e6245eed = function(arg0) {
const ret = new Uint8Array(getObject(arg0));
return addHeapObject(ret);
};
imports.wbg.__wbg_length_d9c4ded7e708c6a1 = function(arg0) {
imports.wbg.__wbg_length_72e2208bbc0efc61 = function(arg0) {
const ret = getObject(arg0).length;
return ret;
};
@ -661,11 +658,11 @@ function __wbg_get_imports() {
const ret = wasm.memory;
return addHeapObject(ret);
};
imports.wbg.__wbg_buffer_fcbfb6d88b2732e9 = function(arg0) {
imports.wbg.__wbg_buffer_085ec1f694018c4f = function(arg0) {
const ret = getObject(arg0).buffer;
return addHeapObject(ret);
};
imports.wbg.__wbg_set_4b3aa8445ac1e91c = function(arg0, arg1, arg2) {
imports.wbg.__wbg_set_5cf90238115182c3 = function(arg0, arg1, arg2) {
getObject(arg0).set(getObject(arg1), arg2 >>> 0);
};
imports.wbg.__wbg_windowonMessage_5c5b80d5376153dc = function(arg0, arg1) {
@ -676,7 +673,7 @@ function __wbg_get_imports() {
deferred0_1 = arg1;
window.onMessage(getStringFromWasm0(arg0, arg1));
} finally {
wasm.__wbindgen_export_4(deferred0_0, deferred0_1);
wasm.__wbindgen_export_4(deferred0_0, deferred0_1, 1);
}
};
imports.wbg.__wbg_windowonAuthOk_9cd9fb8f74884ca4 = function(arg0, arg1, arg2, arg3, arg4, arg5) {
@ -695,28 +692,28 @@ function __wbg_get_imports() {
deferred2_1 = arg5;
window.onAuthOk(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5));
} finally {
wasm.__wbindgen_export_4(deferred0_0, deferred0_1);
wasm.__wbindgen_export_4(deferred1_0, deferred1_1);
wasm.__wbindgen_export_4(deferred2_0, deferred2_1);
wasm.__wbindgen_export_4(deferred0_0, deferred0_1, 1);
wasm.__wbindgen_export_4(deferred1_0, deferred1_1, 1);
wasm.__wbindgen_export_4(deferred2_0, deferred2_1, 1);
}
};
imports.wbg.__wbg_windowonAuthFail_ddfdfcd594ff15b8 = typeof window.onAuthFail == 'function' ? window.onAuthFail : notDefined('window.onAuthFail');
imports.wbg.__wbg_send_737fddb36434277e = function() { return handleError(function (arg0, arg1, arg2) {
imports.wbg.__wbg_send_1a008ea2eb3a1951 = function() { return handleError(function (arg0, arg1, arg2) {
getObject(arg0).send(getArrayU8FromWasm0(arg1, arg2));
}, arguments) };
imports.wbg.__wbg_self_b9aad7f1c618bfaf = function() { return handleError(function () {
imports.wbg.__wbg_self_1ff1d729e9aae938 = function() { return handleError(function () {
const ret = self.self;
return addHeapObject(ret);
}, arguments) };
imports.wbg.__wbg_window_55e469842c98b086 = function() { return handleError(function () {
imports.wbg.__wbg_window_5f4faef6c12b79ec = function() { return handleError(function () {
const ret = window.window;
return addHeapObject(ret);
}, arguments) };
imports.wbg.__wbg_globalThis_d0957e302752547e = function() { return handleError(function () {
imports.wbg.__wbg_globalThis_1d39714405582d3c = function() { return handleError(function () {
const ret = globalThis.globalThis;
return addHeapObject(ret);
}, arguments) };
imports.wbg.__wbg_global_ae2f87312b8987fb = function() { return handleError(function () {
imports.wbg.__wbg_global_651f05c6a0944d1c = function() { return handleError(function () {
const ret = global.global;
return addHeapObject(ret);
}, arguments) };
@ -724,11 +721,11 @@ function __wbg_get_imports() {
const ret = getObject(arg0) === undefined;
return ret;
};
imports.wbg.__wbg_newnoargs_e643855c6572a4a8 = function(arg0, arg1) {
imports.wbg.__wbg_newnoargs_581967eacc0e2604 = function(arg0, arg1) {
const ret = new Function(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
};
imports.wbg.__wbg_call_f96b398515635514 = function() { return handleError(function (arg0, arg1) {
imports.wbg.__wbg_call_cb65541d95d71282 = function() { return handleError(function (arg0, arg1) {
const ret = getObject(arg0).call(getObject(arg1));
return addHeapObject(ret);
}, arguments) };
@ -742,6 +739,9 @@ function __wbg_get_imports() {
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
const ret = getObject(arg0);
return addHeapObject(ret);
@ -754,11 +754,11 @@ function __wbg_get_imports() {
const ret = getObject(arg0).now();
return ret;
};
imports.wbg.__wbindgen_closure_wrapper1516 = function(arg0, arg1, arg2) {
imports.wbg.__wbindgen_closure_wrapper1515 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 8, __wbg_adapter_16);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper1518 = function(arg0, arg1, arg2) {
imports.wbg.__wbindgen_closure_wrapper1517 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 8, __wbg_adapter_16);
return addHeapObject(ret);
};

View File

@ -34,9 +34,9 @@ export function request_ext_snr_graph(a: number, b: number, c: number, d: number
export function request_ext_capacity_graph(a: number, b: number, c: number, d: number): void;
export function request_ext_capacity_ap(a: number, b: number, c: number, d: number): void;
export function request_ext_signal_ap(a: number, b: number, c: number, d: number): void;
export function __wbindgen_export_0(a: number): number;
export function __wbindgen_export_1(a: number, b: number, c: number): number;
export function __wbindgen_export_0(a: number, b: number): number;
export function __wbindgen_export_1(a: number, b: number, c: number, d: number): number;
export const __wbindgen_export_2: WebAssembly.Table;
export function __wbindgen_export_3(a: number, b: number, c: number): void;
export function __wbindgen_export_4(a: number, b: number): void;
export function __wbindgen_export_4(a: number, b: number, c: number): void;
export function __wbindgen_export_5(a: number): void;

View File

@ -101,7 +101,13 @@ impl Conduit {
if self.url.is_empty() { return Err(WebSocketError::NoURL); }
if self.status != ConnectionStatus::New { return Err(WebSocketError::AlreadyConnected); }
if self.socket.is_some() { return Err(WebSocketError::AlreadyExists); }
self.socket = Some(WebSocket::new(&self.url).map_err(|_| WebSocketError::CreationError)?);
log(&format!("Connecting to: {}", self.url));
let conn_result = WebSocket::new(&self.url);
if conn_result.is_err() {
log(&format!("Error connecting: {:?}", conn_result));
return Err(WebSocketError::CreationError);
}
self.socket = Some(conn_result.unwrap());
if let Some(socket) = &mut self.socket {
socket.set_binary_type(BinaryType::Arraybuffer);