add new items to public log when syncing

english
Ev Bogue 4 years ago
parent 3986e1d438
commit 249f0a43fe

@ -2,7 +2,7 @@ var screen = h('div', {id: 'screen'})
document.body.appendChild(screen)
var header = h('div', {classList: 'message'})
//var header = h('div', {classList: 'message'})
var keys = getKeys()
@ -129,12 +129,6 @@ function route () {
clientLog.log = []
}
/*if (localSTorage['log']) {
var publicLog = localStorage['log']
} else {
var publicLog = []
}*/
ws.onopen = function () {
ws.send(JSON.stringify(clientLog))
}
@ -142,7 +136,17 @@ function route () {
ws.onmessage = function (ev) {
var serverData = JSON.parse(ev.data)
if (serverData.log.length > clientLog.log.length) {
// update the log of the id
localStorage[src] = JSON.stringify(serverData.log)
// contact new items from the log onto the client's log of everything
var num = serverData.log.length - clientLog.log.length
var diff = serverData.log.slice(0, num)
var oldLog = JSON.parse(localStorage['log'])
var newLog = diff.concat(oldLog)
localStorage['log'] = JSON.stringify(newLog)
location.reload()
}
}

Loading…
Cancel
Save