diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 8e97be2a3..1acd73fa6 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -110,7 +110,8 @@ export async function connectScryptedClient(options: ScryptedClientOptions): Pro }; const explicitBaseUrl = baseUrl || `${window.location.protocol}//${window.location.host}`; - if (addresses && !addresses.includes(explicitBaseUrl)) { + const isLocalHost = ['127.0.0.1', 'localhost'].includes(window.location.hostname); + if (!isLocalHost && addresses && !addresses.includes(explicitBaseUrl)) { const publicEioOptions: Partial = { transports: ["websocket", "polling"], path: `${endpointPath}/public/engine.io/api`, @@ -119,7 +120,7 @@ export async function connectScryptedClient(options: ScryptedClientOptions): Pro }; let sockets: IOClientSocket[] = []; - const promises: Promise[] = []; + const promises: Promise<{ ready: IOClientSocket, id: string }>[] = []; promises.push(new Promise((_, rj) => setTimeout(() => rj(new Error('timeout')), 1000))); @@ -128,12 +129,18 @@ export async function connectScryptedClient(options: ScryptedClientOptions): Pro for (const address of addresses) { const check = new eio.Socket(address, publicEioOptions); sockets.push(check); - promises.push(once(check, 'open').then(() => check)); + promises.push((async () => { + await once(check, 'open'); + const [json] = await once(socket, 'message'); + const { id } = JSON.parse(json); + return { + ready: check, + id, + }; + })()); } - socket = await Promise.race(promises); + const { ready, id } = await Promise.race(promises); console.log('using local address'); - const [json] = await once(socket, 'message'); - const { id } = JSON.parse(json); const url = `${eioOptions.path}/activate`; await axios.post(url, { @@ -142,6 +149,7 @@ export async function connectScryptedClient(options: ScryptedClientOptions): Pro ...axiosConfig, }); + socket = ready; socket.send('/api/start'); sockets = sockets.filter(s => s !== socket); } diff --git a/plugins/core/package-lock.json b/plugins/core/package-lock.json index 1638b220d..cd23ad690 100644 --- a/plugins/core/package-lock.json +++ b/plugins/core/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/core", - "version": "0.1.6", + "version": "0.1.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/core", - "version": "0.1.6", + "version": "0.1.7", "license": "Apache-2.0", "dependencies": { "@scrypted/common": "file:../../common", diff --git a/plugins/core/package.json b/plugins/core/package.json index 0ee71a68b..3a65f4c93 100644 --- a/plugins/core/package.json +++ b/plugins/core/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/core", - "version": "0.1.6", + "version": "0.1.7", "description": "Scrypted Core plugin. Provides the UI, websocket, and engine.io APIs.", "author": "Scrypted", "license": "Apache-2.0",