-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dgw):properly fallback to recording when streaming is not available
- Loading branch information
1 parent
8a52585
commit 1421eb8
Showing
6 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
let beforeClose = (args: CloseEvent): CloseEvent => { | ||
return args; | ||
}; | ||
|
||
export const OnBeforeClose = (callback: (args: CloseEvent) => CloseEvent) => { | ||
beforeClose = callback; | ||
}; | ||
|
||
const WebSocketProxy = new Proxy(window.WebSocket, { | ||
construct(target, args: [url: string | URL, protocols?: string | string[]]) { | ||
console.log('Proxying WebSocket connection', ...args); | ||
const ws = new target(...args); // Create the actual WebSocket instance | ||
|
||
// Proxy for intercepting `addEventListener` | ||
ws.addEventListener = new Proxy(ws.addEventListener, { | ||
apply(target, thisArg, args) { | ||
if (args[0] === 'close') { | ||
console.log('Intercepted addEventListener for close event'); | ||
const transformedArgs = beforeClose(args as unknown as CloseEvent); | ||
return target.apply(thisArg, transformedArgs); | ||
} | ||
return target.apply(thisArg, args); | ||
}, | ||
}); | ||
|
||
// Proxy for intercepting `onclose` | ||
return new Proxy(ws, { | ||
set(target, prop, value) { | ||
if (prop === 'onclose') { | ||
console.log('Intercepted setting of onclose'); | ||
const transformedValue = (...args) => { | ||
const transformedArgs = beforeClose(args as unknown as CloseEvent); | ||
if (typeof value === 'function') { | ||
value(transformedArgs); // Call the original handler | ||
} | ||
}; | ||
return Reflect.set(target, prop, transformedValue); | ||
} | ||
return Reflect.set(target, prop, value); | ||
}, | ||
}); | ||
}, | ||
}); | ||
|
||
window.WebSocket = WebSocketProxy; |