1
0
Fork 0
mirror of synced 2024-09-18 18:28:33 +12:00
budibase/packages/client/src/websocket.js

25 lines
695 B
JavaScript
Raw Normal View History

2022-08-19 22:09:20 +12:00
import { builderStore } from "./stores/index.js"
import { get } from "svelte/store"
import { io } from "socket.io-client"
export const initWebsocket = () => {
const { inBuilder, location } = get(builderStore)
console.log(location)
if (!inBuilder || !location) {
return
}
// Websocket
const tls = location.protocol === "https:"
const proto = tls ? "wss:" : "ws:"
const host = location.hostname
const port = location.port || (tls ? 433 : 80)
console.log(`${proto}//${host}:${port}`)
const socket = io(`${proto}//${host}:${port}`, {
path: "/socket/",
})
socket.on("plugin-update", data => {
builderStore.actions.updateUsedPlugin(data.name, data.hash)
})
}