Skip to content

Commit 80f11aa

Browse files
committed
fix(mqtt): derive websocket protocol from html app protocol
1 parent 1cfc16d commit 80f11aa

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

src/app/KVNRV/App.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useVisibleWidgetsStore } from "../MarineApp/modules"
99
import { KVNRV } from "./KVNRV"
1010

1111
export type AppProps = {
12+
protocol: string
1213
host: string
1314
port: number | null
1415
}
@@ -23,12 +24,21 @@ const App = observer((props: AppProps) => {
2324

2425
useEffect(() => {
2526
if (!appStore.remote) {
26-
mqtt.boot(props.host, props.port)
27+
mqtt.boot(props.protocol, props.host, props.port)
2728
} else if (appStore.remote && vrmStore?.webhost && vrmStore?.portalId && vrmStore?.siteId) {
28-
mqtt.boot(vrmStore.webhost, null, "", true, vrmStore.portalId)
29+
mqtt.boot("https", vrmStore.webhost, null, "", true, vrmStore.portalId)
2930
}
3031
// eslint-disable-next-line react-hooks/exhaustive-deps
31-
}, [props.host, props.port, appStore.remote, vrmStore.webhost, vrmStore.portalId, vrmStore.siteId, locale])
32+
}, [
33+
props.protocol,
34+
props.host,
35+
props.port,
36+
appStore.remote,
37+
vrmStore.webhost,
38+
vrmStore.portalId,
39+
vrmStore.siteId,
40+
locale,
41+
])
3242

3343
useEffect(() => {
3444
visibleWidgetsStore.clearVisibleElements()

src/app/Marine2/App.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { appErrorBoundaryProps } from "./components/ui/Error/appErrorBoundary"
1010
import "./css/global.css"
1111

1212
export type AppProps = {
13+
protocol: string
1314
host: string
1415
port: number | null
1516
}
@@ -26,12 +27,21 @@ const App = (props: AppProps) => {
2627

2728
useEffect(() => {
2829
if (!appStore.remote) {
29-
mqtt.boot(props.host, props.port)
30+
mqtt.boot(props.protocol, props.host, props.port)
3031
} else if (appStore.remote && vrmStore?.webhost && vrmStore?.portalId && vrmStore?.siteId) {
31-
mqtt.boot(vrmStore.webhost, null, "", true, vrmStore.portalId)
32+
mqtt.boot("https", vrmStore.webhost, null, "", true, vrmStore.portalId)
3233
}
3334
// eslint-disable-next-line react-hooks/exhaustive-deps
34-
}, [props.host, props.port, appStore.remote, vrmStore.webhost, vrmStore.portalId, vrmStore.siteId, locale])
35+
}, [
36+
props.protocol,
37+
props.host,
38+
props.port,
39+
appStore.remote,
40+
vrmStore.webhost,
41+
vrmStore.portalId,
42+
vrmStore.siteId,
43+
locale,
44+
])
3545

3646
useEffect(() => {
3747
if (appStore.language) {

src/app/MarineApp/App.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ErrorModal } from "./components/ErrorModal"
99
import { Marine } from "./Marine"
1010

1111
export type AppProps = {
12+
protocol: string
1213
host: string
1314
port: number | null
1415
}
@@ -23,12 +24,21 @@ const App = observer((props: AppProps) => {
2324

2425
useEffect(() => {
2526
if (!appStore.remote) {
26-
mqtt.boot(props.host, props.port)
27+
mqtt.boot(props.protocol, props.host, props.port)
2728
} else if (appStore.remote && vrmStore?.webhost && vrmStore?.portalId && vrmStore?.siteId) {
28-
mqtt.boot(vrmStore.webhost, null, "", true, vrmStore.portalId)
29+
mqtt.boot("https", vrmStore.webhost, null, "", true, vrmStore.portalId)
2930
}
3031
// eslint-disable-next-line react-hooks/exhaustive-deps
31-
}, [props.host, props.port, appStore.remote, vrmStore.webhost, vrmStore.portalId, vrmStore.siteId, locale])
32+
}, [
33+
props.protocol,
34+
props.host,
35+
props.port,
36+
appStore.remote,
37+
vrmStore.webhost,
38+
vrmStore.portalId,
39+
vrmStore.siteId,
40+
locale,
41+
])
3242

3343
useEffect(() => {
3444
visibleWidgetsStore.clearVisibleElements()

src/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,25 @@ const getApp = () => {
2424
case "KVNRV":
2525
return (
2626
<React.Suspense fallback={<Loading />}>
27-
<KvnrvApp host={host} port={port} />
27+
<KvnrvApp protocol={proto} host={host} port={port} />
2828
</React.Suspense>
2929
)
3030
case "Marine":
3131
return (
3232
<React.Suspense fallback={<Loading />}>
33-
<MarineApp host={host} port={port} />
33+
<MarineApp protocol={proto} host={host} port={port} />
3434
</React.Suspense>
3535
)
3636
default:
3737
return (
3838
<React.Suspense fallback={<Loading />}>
39-
<Marine2App host={host} port={port} />
39+
<Marine2App protocol={proto} host={host} port={port} />
4040
</React.Suspense>
4141
)
4242
}
4343
}
4444

45+
const proto = window.location.protocol
4546
const host = getParameterByName("host") || window.location.hostname || "localhost"
4647
const port = parseInt(getParameterByName("port") || window.location.port) || null
4748

0 commit comments

Comments
 (0)