initial import
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<template>
|
||||
<div id="app">
|
||||
<nav class="navbar" role="navigation" aria-label="main navigation">
|
||||
<div class="container">
|
||||
<div class="navbar-brand">
|
||||
<a class="navbar-item" href="https://bulma.io">
|
||||
<img src="https://bulma.io/images/bulma-logo.png" width="112" height="28" />
|
||||
</a>
|
||||
|
||||
<a
|
||||
role="button"
|
||||
class="navbar-burger burger"
|
||||
aria-label="menu"
|
||||
aria-expanded="false"
|
||||
data-target="navbarBasicExample"
|
||||
>
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div id="navbarBasicExample" class="navbar-menu">
|
||||
<div class="navbar-start">
|
||||
<a class="navbar-item">Home</a>
|
||||
</div>
|
||||
<div class="navbar-end"></div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<router-view />
|
||||
</div>
|
||||
</template>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 6.7 KiB |
@@ -0,0 +1,7 @@
|
||||
@import "~bulma/sass/utilities/initial-variables";
|
||||
|
||||
$scheme-main: $black-ter;
|
||||
$scheme-invert: $white-ter;
|
||||
$text: $grey-lightest;
|
||||
|
||||
@import "~bulma/bulma";
|
||||
@@ -0,0 +1,24 @@
|
||||
<template>
|
||||
<div class="notification" v-bind:class="active ? 'is-success' : 'is-danger'">
|
||||
<span v-if="active">Connected as {{ channel }}</span>
|
||||
<span v-else>Disconnected</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import eventSource from "@/eventsource";
|
||||
|
||||
export default {
|
||||
name: "Connection",
|
||||
computed: {
|
||||
active() {
|
||||
return eventSource.isConnected()
|
||||
},
|
||||
|
||||
},
|
||||
props: {
|
||||
channel: String,
|
||||
active: Boolean,
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,14 @@
|
||||
<template>
|
||||
<div class="hello">
|
||||
<h1>{{ msg }}</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'HelloWorld',
|
||||
props: {
|
||||
msg: String
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,17 @@
|
||||
import Vue from 'vue'
|
||||
import VueRouter from 'vue-router'
|
||||
import App from './App.vue'
|
||||
import store from './store'
|
||||
import router from './router'
|
||||
|
||||
import './assets/main.scss'
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
Vue.use(VueRouter)
|
||||
|
||||
new Vue({
|
||||
data: store.state,
|
||||
router,
|
||||
render: h => h(App)
|
||||
}).$mount('#app')
|
||||
@@ -0,0 +1,27 @@
|
||||
import Vue from 'vue'
|
||||
import VueRouter from 'vue-router'
|
||||
import Home from '../views/Home.vue'
|
||||
|
||||
Vue.use(VueRouter)
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/:channel?',
|
||||
name: 'Home',
|
||||
component: Home
|
||||
}
|
||||
// {
|
||||
// path: '/about',
|
||||
// name: 'About',
|
||||
// // route level code-splitting
|
||||
// // this generates a separate chunk (about.[hash].js) for this route
|
||||
// // which is lazy-loaded when the route is visited.
|
||||
// component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
|
||||
// }
|
||||
]
|
||||
|
||||
const router = new VueRouter({
|
||||
routes
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,20 @@
|
||||
const store = {
|
||||
state: {
|
||||
credits: 0,
|
||||
message: 'Hello World!',
|
||||
},
|
||||
setCreditsAction(newValue) {
|
||||
this.state.credits = newValue
|
||||
},
|
||||
setRawMessageAction(newValue) {
|
||||
this.state.message = newValue
|
||||
},
|
||||
setMessageAction(newValue) {
|
||||
this.state.message = newValue
|
||||
},
|
||||
clearMessageAction() {
|
||||
this.state.message = ''
|
||||
}
|
||||
}
|
||||
|
||||
export default store
|
||||
@@ -0,0 +1,61 @@
|
||||
<template>
|
||||
<div class="home">
|
||||
<Connection v-bind:active="active" v-bind:channel="currentChannel" />
|
||||
<HelloWorld v-bind:msg="message" />
|
||||
<div>
|
||||
Credits: {{ credits }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// @ is an alias to /src
|
||||
import HelloWorld from "@/components/HelloWorld.vue";
|
||||
import Connection from "@/components/Connection.vue";
|
||||
import eventSource from "@/eventsource";
|
||||
|
||||
var connect = function (channel) {
|
||||
if (channel != "undefined" && channel != data.currentChannel) {
|
||||
data.currentChannel = channel;
|
||||
eventSource.connect(channel);
|
||||
}
|
||||
};
|
||||
|
||||
var data = {
|
||||
active: false,
|
||||
currentChannel: "",
|
||||
};
|
||||
|
||||
export default {
|
||||
name: "Home",
|
||||
data() {
|
||||
return data;
|
||||
},
|
||||
computed: {
|
||||
message() {
|
||||
return this.$root.message;
|
||||
},
|
||||
credits() {
|
||||
return this.$root.credits;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
$route(to) {
|
||||
connect(to.params.channel);
|
||||
},
|
||||
},
|
||||
created() {
|
||||
eventSource.onOpen(function () {
|
||||
data.active = true;
|
||||
});
|
||||
eventSource.onClose(function () {
|
||||
data.active = false;
|
||||
});
|
||||
connect(this.$route.params.channel);
|
||||
},
|
||||
components: {
|
||||
HelloWorld,
|
||||
Connection,
|
||||
},
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user