Skip to content

Commit

Permalink
fix: fix github lint
Browse files Browse the repository at this point in the history
  • Loading branch information
akitaSummer committed May 20, 2023
1 parent bbfa34e commit 9a02be6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
7 changes: 3 additions & 4 deletions crates/runtime/tests/websocket.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use httptest::{matchers::*, responders::*, Expectation, Server};
use hyper::{ext::Protocol, header::CONTENT_TYPE, Request, Response};
use hyper::Request;
use lagon_runtime_isolate::options::IsolateOptions;
use lagon_runtime_websocket::{accept_async, Message, SendValue, StreamExt, WebSocketStream};
use lagon_runtime_websocket::{accept_async, Message, StreamExt, WebSocketStream};
use tokio::{
io::{AsyncRead, AsyncWrite},
net::{TcpListener, TcpStream},
net::TcpListener,
};

mod utils;
Expand Down
30 changes: 16 additions & 14 deletions packages/js-runtime/src/runtime/global/webscoket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@
CLOSED = '__RUNTIME_WS_EVENT_CLOSED__',
}

// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
globalThis.WebSocket = class extends EventTarget {
private _url: string;
get url() {
return this._url;
}
private wsId: string = '';
private _protocols: string = '';
private wsId = '';
private _protocols = '';
get protocols() {
return this._protocols;
}
private _extensions: string = '';
private _extensions = '';
get extensions() {
return this._extensions;
}
private _readyState: WsState = WsState.CONNECTING;
private _readyState = WsState.CONNECTING;
get readyState() {
return this._readyState;
}
Expand All @@ -48,11 +49,7 @@
if (url instanceof URL) {
wsURL = url;
} else {
try {
wsURL = new URL(url);
} catch (e) {
throw e;
}
wsURL = new URL(url);
}

if (wsURL.protocol !== 'ws:' && wsURL.protocol !== 'wss:') {
Expand Down Expand Up @@ -101,7 +98,7 @@
})
.catch(err => {
this._readyState = WsState.CLOSED;

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const errorEv = new Event('error', { error: err, message: err.toString() });
this.dispatchEvent(errorEv);
Expand All @@ -127,6 +124,7 @@

LagonAsync.websocketClose(this.wsId, code, reason).catch(err => {
const errorEv = new Event('error', {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
error: err,
message: err.toString(),
Expand Down Expand Up @@ -165,27 +163,29 @@
}

const event = new Event('close', {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
wasClean: true,
});
this.dispatchEvent(event);
break;
}
default:
default: {
this.serverHandleIdleTimeout();

const event = new Event('message', {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
data,
origin: this._url,
});
this.dispatchEvent(event);
}
}
} catch (e: any) {
this._readyState = WsState.CLOSED;

// @ts-ignore
const errorEv = new Event('error', {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
message: e,
});
Expand Down Expand Up @@ -213,12 +213,14 @@
this._readyState = WsState.CLOSED;

const errEvent = new Event('error', {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
message: reason,
});
this.dispatchEvent(errEvent);

const event = new Event('close', {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
wasClean: false,
code: 1001,
Expand Down

0 comments on commit 9a02be6

Please sign in to comment.