Commit f472f87c authored by Aral Balkan's avatar Aral Balkan
Browse files

Add public socket

parent acfde169
......@@ -9,8 +9,21 @@
import SignOutSection from './sections/SignOut.svelte'
import NotFound from './sections/NotFound.svelte'
import { initialise } from './state.js'
import { onMount, getContext } from 'svelte'
// Initialise state.
import { initialise, state } from './state.js'
initialise()
const { publicSocket } = getContext(state)
onMount(() => {
// Make the public socket connection.
$publicSocket = new WebSocket(`wss://${location.hostname}/public`)
$publicSocket.onmessage = message => {
alert(message.data)
}
})
</script>
<style>
......
......@@ -12,9 +12,10 @@ export function initialise () {
const signedIn = writable(false)
const privateToken = writable(null)
const privateSocket = writable(null)
const publicSocket = writable(null)
const currentSection = writable(currentSectionFromHash(false))
setContext(state, { currentSection, signedIn, privateToken, privateSocket })
setContext(state, { currentSection, signedIn, publicSocket, privateToken, privateSocket })
window.addEventListener('hashchange', () => {
const _signedIn = get(signedIn)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment