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 1
1
import { createBoard , playMove } from "./connect4.js" ;
2
2
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
+
3
13
function initGame ( websocket ) {
4
14
websocket . addEventListener ( "open" , ( ) => {
5
15
// Send an "init" event according to who is connecting.
@@ -76,7 +86,7 @@ window.addEventListener("DOMContentLoaded", () => {
76
86
const board = document . querySelector ( ".board" ) ;
77
87
createBoard ( board ) ;
78
88
// Open the WebSocket connection and register event handlers.
79
- const websocket = new WebSocket ( "ws://localhost:8001/" ) ;
89
+ const websocket = new WebSocket ( getWebSocketServer ( ) ) ;
80
90
initGame ( websocket ) ;
81
91
receiveMoves ( board , websocket ) ;
82
92
sendMoves ( board , websocket ) ;
You can’t perform that action at this time.
0 commit comments