mirror of
https://github.com/MercuryWorkshop/adrift.git
synced 2025-05-13 06:10:01 -04:00
bit of cleanup
This commit is contained in:
parent
bb6eb218d0
commit
296288467b
1 changed files with 25 additions and 26 deletions
|
@ -5,8 +5,8 @@ import {
|
|||
GetRequestHeadersCallback,
|
||||
MetaCallback,
|
||||
ReadyStateCallback,
|
||||
WebSocketFields,
|
||||
WebSocketImpl,
|
||||
WebSocketFields
|
||||
} from "bare-client-custom";
|
||||
import { Connection } from "./Connection";
|
||||
|
||||
|
@ -67,6 +67,7 @@ export class AdriftBareClient extends Client {
|
|||
headers,
|
||||
}) as BareResponse;
|
||||
}
|
||||
|
||||
connect(
|
||||
remote: URL,
|
||||
protocols: string[],
|
||||
|
@ -75,26 +76,29 @@ export class AdriftBareClient extends Client {
|
|||
onReadyState: ReadyStateCallback,
|
||||
webSocketImpl: WebSocketImpl
|
||||
): WebSocket {
|
||||
const ws = new WebSocket("ws:null");
|
||||
const ws = new webSocketImpl("ws:null");
|
||||
// this will error. that's okay
|
||||
|
||||
|
||||
let send = this.connection.wsconnect(remote, () => {
|
||||
let send = this.connection.wsconnect(
|
||||
remote,
|
||||
() => {
|
||||
onReadyState(WebSocketFields.OPEN);
|
||||
ws.dispatchEvent(new Event('open'));
|
||||
|
||||
}, () => {
|
||||
ws.dispatchEvent(new Event("open"));
|
||||
},
|
||||
() => {
|
||||
onReadyState(WebSocketFields.CLOSED);
|
||||
ws.dispatchEvent(new Event('close'));
|
||||
ws.dispatchEvent(new Event("close"));
|
||||
|
||||
// what do i do for WebSocketFields.closing?
|
||||
}, (data) => {
|
||||
ws.dispatchEvent(new MessageEvent("message", {
|
||||
},
|
||||
(data) => {
|
||||
ws.dispatchEvent(
|
||||
new MessageEvent("message", {
|
||||
data,
|
||||
// might be other shit here idk
|
||||
}));
|
||||
});
|
||||
|
||||
})
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// const cleanup = () => {
|
||||
// ws.removeEventListener('close', closeListener);
|
||||
|
@ -105,17 +109,15 @@ export class AdriftBareClient extends Client {
|
|||
// cleanup();
|
||||
// };
|
||||
|
||||
|
||||
(ws as any).__defineGetter__("send", () => (data: any) => {
|
||||
send(data);
|
||||
});
|
||||
(ws as any).__defineSetter__("send", () => { });
|
||||
(ws as any).__defineSetter__("send", () => {});
|
||||
// ws.send = (data) => {
|
||||
// console.log("sending data to server:" + data);
|
||||
// };
|
||||
// console.log(ws.send);
|
||||
|
||||
|
||||
const messageListener = (event: MessageEvent) => {
|
||||
// cleanup();
|
||||
|
||||
|
@ -139,13 +141,11 @@ export class AdriftBareClient extends Client {
|
|||
// // now we want the client to see the websocket is open and ready to communicate with the remote
|
||||
// onReadyState(WebSocketFields.OPEN);
|
||||
|
||||
ws.dispatchEvent(new Event('open'));
|
||||
ws.dispatchEvent(new Event("open"));
|
||||
};
|
||||
|
||||
setTimeout(messageListener, 30);
|
||||
|
||||
// ws.addEventListener('close', closeListener);
|
||||
ws.addEventListener('message', messageListener);
|
||||
ws.addEventListener("message", messageListener);
|
||||
|
||||
// // CONNECTED TO THE BARE SERVER, NOT THE REMOTE
|
||||
// ws.addEventListener(
|
||||
|
@ -177,7 +177,6 @@ export class AdriftBareClient extends Client {
|
|||
// { once: true }
|
||||
// );
|
||||
|
||||
|
||||
return ws;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue