Skip to content

Commit

Permalink
fix: improve polyfill for addEventListener in WebSocketHandler; use O…
Browse files Browse the repository at this point in the history
…bject.defineProperty for better compatibility
  • Loading branch information
Zoltan Erdos committed Feb 2, 2025
1 parent e32d3bd commit a9b1478
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/spike.land/src/websocketHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ export class WebSocketHandler {
public handleWebsocketSession(webSocket: WebSocket): void {
// Polyfill addEventListener if not available
if (typeof webSocket.addEventListener !== "function") {
(webSocket as any).addEventListener = function(type: string, listener: any) {
this["on" + type] = listener;
webSocket.addEventListener = function(type, listener) {
const handlerName = "on" + type;
Object.defineProperty(webSocket, handlerName, ()=>listener);
};
}
try {
Expand Down

0 comments on commit a9b1478

Please sign in to comment.