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,
|
GetRequestHeadersCallback,
|
||||||
MetaCallback,
|
MetaCallback,
|
||||||
ReadyStateCallback,
|
ReadyStateCallback,
|
||||||
|
WebSocketFields,
|
||||||
WebSocketImpl,
|
WebSocketImpl,
|
||||||
WebSocketFields
|
|
||||||
} from "bare-client-custom";
|
} from "bare-client-custom";
|
||||||
import { Connection } from "./Connection";
|
import { Connection } from "./Connection";
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ export class AdriftBareClient extends Client {
|
||||||
headers,
|
headers,
|
||||||
}) as BareResponse;
|
}) as BareResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(
|
connect(
|
||||||
remote: URL,
|
remote: URL,
|
||||||
protocols: string[],
|
protocols: string[],
|
||||||
|
@ -75,26 +76,29 @@ export class AdriftBareClient extends Client {
|
||||||
onReadyState: ReadyStateCallback,
|
onReadyState: ReadyStateCallback,
|
||||||
webSocketImpl: WebSocketImpl
|
webSocketImpl: WebSocketImpl
|
||||||
): WebSocket {
|
): WebSocket {
|
||||||
const ws = new WebSocket("ws:null");
|
const ws = new webSocketImpl("ws:null");
|
||||||
// this will error. that's okay
|
// this will error. that's okay
|
||||||
|
|
||||||
|
let send = this.connection.wsconnect(
|
||||||
|
remote,
|
||||||
|
() => {
|
||||||
|
onReadyState(WebSocketFields.OPEN);
|
||||||
|
ws.dispatchEvent(new Event("open"));
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
onReadyState(WebSocketFields.CLOSED);
|
||||||
|
ws.dispatchEvent(new Event("close"));
|
||||||
|
|
||||||
let send = this.connection.wsconnect(remote, () => {
|
// what do i do for WebSocketFields.closing?
|
||||||
onReadyState(WebSocketFields.OPEN);
|
},
|
||||||
ws.dispatchEvent(new Event('open'));
|
(data) => {
|
||||||
|
ws.dispatchEvent(
|
||||||
}, () => {
|
new MessageEvent("message", {
|
||||||
onReadyState(WebSocketFields.CLOSED);
|
data,
|
||||||
ws.dispatchEvent(new Event('close'));
|
})
|
||||||
|
);
|
||||||
// what do i do for WebSocketFields.closing?
|
}
|
||||||
}, (data) => {
|
);
|
||||||
ws.dispatchEvent(new MessageEvent("message", {
|
|
||||||
data,
|
|
||||||
// might be other shit here idk
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// const cleanup = () => {
|
// const cleanup = () => {
|
||||||
// ws.removeEventListener('close', closeListener);
|
// ws.removeEventListener('close', closeListener);
|
||||||
|
@ -105,17 +109,15 @@ export class AdriftBareClient extends Client {
|
||||||
// cleanup();
|
// cleanup();
|
||||||
// };
|
// };
|
||||||
|
|
||||||
|
|
||||||
(ws as any).__defineGetter__("send", () => (data: any) => {
|
(ws as any).__defineGetter__("send", () => (data: any) => {
|
||||||
send(data);
|
send(data);
|
||||||
});
|
});
|
||||||
(ws as any).__defineSetter__("send", () => { });
|
(ws as any).__defineSetter__("send", () => {});
|
||||||
// ws.send = (data) => {
|
// ws.send = (data) => {
|
||||||
// console.log("sending data to server:" + data);
|
// console.log("sending data to server:" + data);
|
||||||
// };
|
// };
|
||||||
// console.log(ws.send);
|
// console.log(ws.send);
|
||||||
|
|
||||||
|
|
||||||
const messageListener = (event: MessageEvent) => {
|
const messageListener = (event: MessageEvent) => {
|
||||||
// cleanup();
|
// 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
|
// // now we want the client to see the websocket is open and ready to communicate with the remote
|
||||||
// onReadyState(WebSocketFields.OPEN);
|
// onReadyState(WebSocketFields.OPEN);
|
||||||
|
|
||||||
ws.dispatchEvent(new Event('open'));
|
ws.dispatchEvent(new Event("open"));
|
||||||
};
|
};
|
||||||
|
|
||||||
setTimeout(messageListener, 30);
|
|
||||||
|
|
||||||
// ws.addEventListener('close', closeListener);
|
// ws.addEventListener('close', closeListener);
|
||||||
ws.addEventListener('message', messageListener);
|
ws.addEventListener("message", messageListener);
|
||||||
|
|
||||||
// // CONNECTED TO THE BARE SERVER, NOT THE REMOTE
|
// // CONNECTED TO THE BARE SERVER, NOT THE REMOTE
|
||||||
// ws.addEventListener(
|
// ws.addEventListener(
|
||||||
|
@ -177,7 +177,6 @@ export class AdriftBareClient extends Client {
|
||||||
// { once: true }
|
// { once: true }
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
|
||||||
return ws;
|
return ws;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue