zc 2 anni fa
parent
commit
b38a4c7df9
2 ha cambiato i file con 26 aggiunte e 8 eliminazioni
  1. 25 7
      assets/scripts/gameCtr.ts
  2. 1 1
      assets/scripts/socket/SocketClient.ts

+ 25 - 7
assets/scripts/gameCtr.ts

@@ -127,12 +127,29 @@ export class GameCtr extends Component {
     public bg2AudioSource: AudioSource = null!
     private isPlayBgm1 = true
 
+    public originUrl:string = null
+    public hostName:string = null
+
+    private globalUrl:string = 'https://airpg1.izouma.com'
+    private globalHostname:string = 'airpg1.izouma.com'
 
     private moveNum:number = 1
 
     init() {
         //播放第一个背景音乐
         this.bg1AudioSource.play()
+        
+        console.log(location.href)
+        
+        if(location.hostname === 'localhost')
+        {
+            this.originUrl = this.globalUrl
+            this.hostName = this.globalHostname
+        }
+        else{
+            this.originUrl = location.origin
+            this.hostName = location.hostname
+        }
 
         let roomId = new URLSearchParams(location.search).get("roomId")
         if (roomId != null) {
@@ -142,8 +159,9 @@ export class GameCtr extends Component {
             console.log("use defult roomId")
         }
 
-        const roomUrl = `https://airpg1.izouma.com/api/room/${this.roomId}`
-
+        
+        const roomUrl = `${this.originUrl}/api/room/${this.roomId}`
+        console.log(roomUrl)
         fetch(roomUrl)
             .then((response) => {
                 if (!response.ok) {
@@ -164,7 +182,7 @@ export class GameCtr extends Component {
                     this.socketClient.initSocketConnection()
                 }
 
-                const gameUrl = `https://airpg1.izouma.com/api/game/${this.gameId}`
+                const gameUrl = `${this.originUrl}/api/game/${this.gameId}`
                 fetch(gameUrl)
                     .then((response) => {
                         if (!response.ok) {
@@ -174,7 +192,7 @@ export class GameCtr extends Component {
                     })
                     .then((data) => {
                         console.log(data)
-                        const historyUrl = `https://airpg1.izouma.com/api/game/${this.gameId}/history`
+                        const historyUrl = `${this.originUrl}/api/game/${this.gameId}/history`
                         this.gameInfo = data
                         this.resetNum = data.resetNum
 
@@ -233,17 +251,17 @@ export class GameCtr extends Component {
         //加载音频播放组件
         this.audioSource = this.node.getComponent(AudioSource)
 
-        // this.startResetAnimation()
+        this.startResetAnimation()
         // this.scheduleOnce(() => { this.accessTargetComponent() }, 0.1)
         this.scheduleOnce(() => {
             this.init()
-        }, 5)
+        }, 10)
         this.processCtr.init(this)
         this.schedule(this.chackGameInfo, 5 * 60)
     }
 
     chackGameInfo() {
-        const roomUrl = `https://airpg1.izouma.com/api/room/${this.roomId}`
+        const roomUrl = `${this.originUrl}/api/room/${this.roomId}`
 
         fetch(roomUrl)
             .then((response) => {

+ 1 - 1
assets/scripts/socket/SocketClient.ts

@@ -13,7 +13,7 @@ export class SocketClient extends Component {
 
     public gameId: number = 8
 
-    private SERVER_URL: String = "wss://airpg1.izouma.com"
+    private SERVER_URL: String = `wss://${location.hostname === 'localhost' ? 'airpg1.izouma.com' :location.hostname}`
 
     public socket:any ;