fix: ws eventlistener bug

This commit is contained in:
Percs 2024-11-30 01:54:05 -06:00
parent ca3e09af8e
commit f62648f250
4 changed files with 90 additions and 90 deletions

View file

@ -7,10 +7,10 @@ type FakeWebSocketState = {
url: string;
binaryType: string;
barews: BareWebSocket;
/*
captureListeners: Record<string, EventListener[]>;
listeners: Record<string, EventListener[]>;
*/
onclose?: (ev: CloseEvent) => any;
onerror?: (ev: Event) => any;
onmessage?: (ev: MessageEvent) => any;
@ -49,13 +49,14 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
url: ctx.args[0],
binaryType: "blob",
barews,
/*
captureListeners: {},
listeners: {},
*/
onclose: null,
onerror: null,
onmessage: null,
onopen: null,
captureListeners: {},
listeners: {},
};
function fakeEventSend(fakeev: Event) {
@ -106,7 +107,8 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
ctx.return(fakeWebSocket);
},
});
// i have no clue why this is here but it prevents the real event listener from ever happening so im commenting it out for now
/*
client.Proxy("EventTarget.prototype.addEventListener", {
apply(ctx) {
const ws = socketmap.get(ctx.this);
@ -156,7 +158,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
ctx.return(undefined);
},
});
*/
client.Trap("WebSocket.prototype.binaryType", {
get(ctx) {
const ws = socketmap.get(ctx.this);

View file

@ -7,8 +7,6 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
if (self.Worker) {
client.Proxy("Worker", {
construct({ args, call }) {
if (args[0] instanceof URL) args[0] = args[0].href;
args[0] = rewriteUrl(args[0], client.meta) + "?dest=worker";
if (args[1] && args[1].type === "module") {
@ -43,8 +41,6 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
// sharedworkers can only be constructed from window
client.Proxy("SharedWorker", {
construct({ args, call }) {
if (args[0] instanceof URL) args[0] = args[0].href;
args[0] = rewriteUrl(args[0], client.meta) + "?dest=worker";
if (args[1] && typeof args[1] === "string")