-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 더 많은 브라우저에서 WebSocket 연결 문제가 없도록 수정 (#207)
fix: 상대 url을 websocket에 사용할 수 있도록 폴리필
- Loading branch information
Showing
2 changed files
with
19 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
packages/frontend/src/lib/polyfill-relative-urls-websocket.ts
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,17 @@ | ||
// Monkey Patch로 WebSocket 생성자를 오버라이드 | ||
const OriginalWebSocket = window.WebSocket; | ||
|
||
// @ts-expect-error Monkey Patch | ||
window.WebSocket = function WebSocket(url, protocols) { | ||
const parsedUrl = new URL(url, window.location.href); | ||
|
||
if (parsedUrl.protocol === "http:") { | ||
parsedUrl.protocol = "ws:"; | ||
} else if (parsedUrl.protocol === "https:") { | ||
parsedUrl.protocol = "wss:"; | ||
} | ||
|
||
return new OriginalWebSocket(parsedUrl.href, protocols); | ||
}; | ||
|
||
window.WebSocket.prototype = OriginalWebSocket.prototype; |
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