File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 11import { createBoard , playMove } from "./connect4.js" ;
22
3+ function getWebSocketServer ( ) {
4+ if ( window . location . host === "python-websockets.github.io" ) {
5+ return "wss://websockets-tutorial.koyeb.app/" ;
6+ } else if ( window . location . host === "localhost:8000" ) {
7+ return "ws://localhost:8001/" ;
8+ } else {
9+ throw new Error ( `Unsupported host: ${ window . location . host } ` ) ;
10+ }
11+ }
12+
313function initGame ( websocket ) {
414 websocket . addEventListener ( "open" , ( ) => {
515 // Send an "init" event according to who is connecting.
@@ -76,7 +86,7 @@ window.addEventListener("DOMContentLoaded", () => {
7686 const board = document . querySelector ( ".board" ) ;
7787 createBoard ( board ) ;
7888 // Open the WebSocket connection and register event handlers.
79- const websocket = new WebSocket ( "ws://localhost:8001/" ) ;
89+ const websocket = new WebSocket ( getWebSocketServer ( ) ) ;
8090 initGame ( websocket ) ;
8191 receiveMoves ( board , websocket ) ;
8292 sendMoves ( board , websocket ) ;
You can’t perform that action at this time.
0 commit comments