moi-computer 0.3.0-next.0 → 0.3.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/hooks/useMeiEvents.ts +2 -1
- package/client/lib/connection.ts +2 -1
- package/client/lib/ws-url.ts +10 -0
- package/dist/{chunk-c3zjp9ez.js → chunk-w18801vn.js} +126 -126
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/server/api.ts +8 -3
- package/server/applets.ts +84 -8
- package/server/views.ts +0 -0
- package/server/widgets.ts +3 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react'
|
|
2
2
|
|
|
3
|
+
import { wsUrl } from '@/client/lib/ws-url'
|
|
3
4
|
import type { ViewInfo, WidgetInfo } from '@/lib/types'
|
|
4
5
|
|
|
5
6
|
export type MeiEvent =
|
|
@@ -26,7 +27,7 @@ function ensureConnection() {
|
|
|
26
27
|
if (ws || connecting) return
|
|
27
28
|
connecting = true
|
|
28
29
|
|
|
29
|
-
const socket = new WebSocket(
|
|
30
|
+
const socket = new WebSocket(wsUrl('/api/workspaces/ws'))
|
|
30
31
|
|
|
31
32
|
socket.onopen = () => {
|
|
32
33
|
ws = socket
|
package/client/lib/connection.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { QueryClient } from '@tanstack/react-query'
|
|
|
2
2
|
|
|
3
3
|
import { workspaceKeys } from '@/client/api/workspaces'
|
|
4
4
|
import { getScratchExecutor } from '@/client/lib/scratch-executor'
|
|
5
|
+
import { wsUrl } from '@/client/lib/ws-url'
|
|
5
6
|
import { liveStore } from '@/client/store/live'
|
|
6
7
|
import { applyEvent } from '@/lib/format'
|
|
7
8
|
import type {
|
|
@@ -55,7 +56,7 @@ function connect() {
|
|
|
55
56
|
reconnectTimer = null
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
const s = new WebSocket(
|
|
59
|
+
const s = new WebSocket(wsUrl('/ws'))
|
|
59
60
|
socket = s
|
|
60
61
|
|
|
61
62
|
s.onopen = () => {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Build a WebSocket URL for a same-origin path, deriving the scheme from the
|
|
2
|
+
// page protocol: `wss://` when the page is served over HTTPS, `ws://` otherwise.
|
|
3
|
+
// Hardcoding `ws://` breaks live updates behind any TLS-terminating proxy
|
|
4
|
+
// (Cloudflare Tunnel, nginx, ngrok) — the browser blocks the insecure socket as
|
|
5
|
+
// mixed content. The proxy forwards `wss://` to the origin's plain `ws://`, so
|
|
6
|
+
// no server change is needed.
|
|
7
|
+
export function wsUrl(path: string) {
|
|
8
|
+
const scheme = location.protocol === 'https:' ? 'wss' : 'ws'
|
|
9
|
+
return `${scheme}://${location.host}${path}`
|
|
10
|
+
}
|