-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(dgw): fallback to recording playback when shadowing is not possible #1181
Changes from 9 commits
1421eb8
46365d6
642c95c
e4f6b28
a063985
c3a3a98
b27f66b
bf052b8
7c87697
3d3faa0
38ac122
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||||
import { GatewayAccessApi } from '../gateway'; | ||||||
import { removeTerminal } from '../terminal'; | ||||||
import { handleCast } from './cast'; | ||||||
import { handleWebm } from './webm'; | ||||||
|
||||||
export const getShadowPlayer = (fileType) => { | ||||||
const player = { | ||||||
play: (_: GatewayAccessApi) => {}, | ||||||
|
@@ -17,3 +17,12 @@ export const getShadowPlayer = (fileType) => { | |||||
|
||||||
return player; | ||||||
}; | ||||||
|
||||||
export const cleanUpStreamers = () => { | ||||||
// Clean up any existing shadow-player elements | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: This comment is probably unnecessary, but if you want to keep it, here is a better wording.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that in this case, it’s much more useful to describe the why, rather than the what. Maybe it makes more sense to explain the why at the callsite of this function. |
||||||
const shadowPlayers = document.querySelectorAll('shadow-player'); | ||||||
for (const shadowPlayer of shadowPlayers) { | ||||||
shadowPlayer.remove(); | ||||||
} | ||||||
removeTerminal(); | ||||||
}; |
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: This comment is also not clearly worded out. Here is how you could improve that.