Browse Source

Handle state

master
Roderic Day 5 years ago
parent
commit
0552e31d63
1 changed files with 2 additions and 5 deletions
  1. +2
    -5
      pico.js

+ 2
- 5
pico.js View File

const signalPeerStop = (username) => signal({kind: 'peerInfo', value: {type: 'stop'}, source: username}) const signalPeerStop = (username) => signal({kind: 'peerInfo', value: {type: 'stop'}, source: username})
const listen = (kind, handler) => addEventListener(kind, handler) const listen = (kind, handler) => addEventListener(kind, handler)
listen('login', ({detail}) => State.username = detail.value) listen('login', ({detail}) => State.username = detail.value)
listen('state', ({detail}) => Object.assign(State, detail))
listen('post', ({detail}) => State.posts.push(detail)) listen('post', ({detail}) => State.posts.push(detail))
listen('peerInfo', (e) => onPeerInfo(e)) listen('peerInfo', (e) => onPeerInfo(e))
const doNotLog = new Set(['login', 'post', 'peerInfo'])
const doNotLog = new Set(['login', 'state', 'post', 'peerInfo'])


/* /*
* *
State.websocket.onmessage = (e) => { State.websocket.onmessage = (e) => {
const message = JSON.parse(e.data) const message = JSON.parse(e.data)


if(message.online) {
State.online = message.online
}

if(!doNotLog.has(message.kind)) { if(!doNotLog.has(message.kind)) {
console.log(message) console.log(message)
} }

Loading…
Cancel
Save