initial import

This commit is contained in:
2021-05-05 19:17:01 +00:00
commit 09e1d643b6
54 changed files with 14073 additions and 0 deletions
@@ -0,0 +1,7 @@
import store from '@/store'
export default {
handle(data) {
store.setCreditsAction(data.content)
}
}
@@ -0,0 +1,13 @@
import credits from './credits'
var handlers = {
'credits': credits
}
export default {
handle(data) {
if(handlers[data.type]) {
handlers[data.type].handle(data)
}
}
}
+56
View File
@@ -0,0 +1,56 @@
import store from "../store"
import handler from './handlers'
var connection = null
var onOpenCallback = null
var onCloseCallback = null
const eventSource = {
connect(channel) {
if(connection != null) {
connection.close();
}
connection = new EventSource('/feed/updates/' + channel)
connection.addEventListener("message", function(message) {
var data = JSON.parse(message.data)
handler.handle(data)
store.setRawMessageAction(message.data)
})
connection.addEventListener("open", function () {
if(typeof onOpenCallback === 'function') {
onOpenCallback()
}
})
connection.addEventListener("close", function () {
if(typeof onCloseCallback === 'function') {
onCloseCallback()
}
})
connection.addEventListener("error", function () {
if(connection.readyState !== EventSource.CONNECTING) {
if(typeof onCloseCallback === 'function') {
onCloseCallback()
}
}
})
},
isConnected() {
return connection.readyState === EventSource.OPEN
},
isConnecting() {
return connection.readyState === EventSource.CONNECTING
},
onOpen(callback) {
onOpenCallback = callback
},
onClose(callback) {
onCloseCallback = callback
}
}
export default eventSource