more const crusade

This commit is contained in:
Evan Simkowitz 2024-07-23 12:46:29 -07:00
parent ed43d7e0a8
commit e6f60ff210
No known key found for this signature in database
4 changed files with 11 additions and 11 deletions

View File

@ -295,7 +295,7 @@ function handleWSMessage(msg: any) {
} }
function initWS() { function initWS() {
let windowId = globalStore.get(atoms.windowId); const windowId = globalStore.get(atoms.windowId);
globalWS = new WSControl(getWSServerEndpoint(), globalStore, windowId, "", (msg) => { globalWS = new WSControl(getWSServerEndpoint(), globalStore, windowId, "", (msg) => {
handleWSMessage(msg); handleWSMessage(msg);
}); });
@ -344,7 +344,7 @@ async function fetchWaveFile(
fileName: string, fileName: string,
offset?: number offset?: number
): Promise<{ data: Uint8Array; fileInfo: WaveFile }> { ): Promise<{ data: Uint8Array; fileInfo: WaveFile }> {
let usp = new URLSearchParams(); const usp = new URLSearchParams();
usp.set("zoneid", zoneId); usp.set("zoneid", zoneId);
usp.set("name", fileName); usp.set("name", fileName);
if (offset != null) { if (offset != null) {
@ -360,11 +360,11 @@ async function fetchWaveFile(
if (resp.status == 204) { if (resp.status == 204) {
return { data: null, fileInfo: null }; return { data: null, fileInfo: null };
} }
let fileInfo64 = resp.headers.get("X-ZoneFileInfo"); const fileInfo64 = resp.headers.get("X-ZoneFileInfo");
if (fileInfo64 == null) { if (fileInfo64 == null) {
throw new Error(`missing zone file info for ${zoneId}:${fileName}`); throw new Error(`missing zone file info for ${zoneId}:${fileName}`);
} }
let fileInfo = JSON.parse(atob(fileInfo64)); const fileInfo = JSON.parse(atob(fileInfo64));
const data = await resp.arrayBuffer(); const data = await resp.arrayBuffer();
return { data: new Uint8Array(data), fileInfo }; return { data: new Uint8Array(data), fileInfo };
} }

View File

@ -115,7 +115,7 @@ function wshServerRpcHelper_responsestream(
if (opts?.noresponse) { if (opts?.noresponse) {
throw new Error("noresponse not supported for responsestream calls"); throw new Error("noresponse not supported for responsestream calls");
} }
let msg: RpcMessage = { const msg: RpcMessage = {
command: command, command: command,
data: data, data: data,
reqid: uuidv4(), reqid: uuidv4(),
@ -128,7 +128,7 @@ function wshServerRpcHelper_responsestream(
} }
function wshServerRpcHelper_call(command: string, data: any, opts: WshRpcCommandOpts): Promise<any> { function wshServerRpcHelper_call(command: string, data: any, opts: WshRpcCommandOpts): Promise<any> {
let msg: RpcMessage = { const msg: RpcMessage = {
command: command, command: command,
data: data, data: data,
}; };

View File

@ -44,7 +44,7 @@ class WSControl {
} }
log(str: string) { log(str: string) {
let ts = Date.now(); const ts = Date.now();
this.wsLog.push("[" + ts + "] " + str); this.wsLog.push("[" + ts + "] " + str);
if (this.wsLog.length > 50) { if (this.wsLog.length > 50) {
this.wsLog.splice(0, this.wsLog.length - 50); this.wsLog.splice(0, this.wsLog.length - 50);
@ -86,7 +86,7 @@ class WSControl {
this.log("cannot connect, giving up"); this.log("cannot connect, giving up");
return; return;
} }
let timeoutArr = [0, 0, 2, 5, 10, 10, 30, 60]; const timeoutArr = [0, 0, 2, 5, 10, 10, 30, 60];
let timeout = 60; let timeout = 60;
if (this.reconnectTimes < timeoutArr.length) { if (this.reconnectTimes < timeoutArr.length) {
timeout = timeoutArr[this.reconnectTimes]; timeout = timeoutArr[this.reconnectTimes];
@ -131,7 +131,7 @@ class WSControl {
if (this.msgQueue.length == 0) { if (this.msgQueue.length == 0) {
return; return;
} }
let msg = this.msgQueue.shift(); const msg = this.msgQueue.shift();
this.sendMessage(msg); this.sendMessage(msg);
setTimeout(() => { setTimeout(() => {
this.runMsgQueue(); this.runMsgQueue();
@ -178,7 +178,7 @@ class WSControl {
if (!this.isOpen()) { if (!this.isOpen()) {
return; return;
} }
let msg = JSON.stringify(data); const msg = JSON.stringify(data);
const byteSize = new Blob([msg]).size; const byteSize = new Blob([msg]).size;
if (byteSize > MaxWebSocketSendSize) { if (byteSize > MaxWebSocketSendSize) {
console.log("ws message too large", byteSize, data.wscommand, msg.substring(0, 100)); console.log("ws message too large", byteSize, data.wscommand, msg.substring(0, 100));

View File

@ -66,7 +66,7 @@ async function* rpcResponseGenerator(
} }
function sendRpcCommand(msg: RpcMessage): AsyncGenerator<RpcMessage, void, boolean> { function sendRpcCommand(msg: RpcMessage): AsyncGenerator<RpcMessage, void, boolean> {
let wsMsg: WSRpcCommand = { wscommand: "rpc", message: msg }; const wsMsg: WSRpcCommand = { wscommand: "rpc", message: msg };
globalWS.pushMessage(wsMsg); globalWS.pushMessage(wsMsg);
if (msg.reqid == null) { if (msg.reqid == null) {
return null; return null;