Archived
2
0
This commit is contained in:
gbrian 2021-03-09 15:56:52 +01:00
parent 15edc0f73e
commit dc3bb4f837
3 changed files with 67 additions and 3 deletions

View File

@ -16,7 +16,8 @@
"serve": "vue-cli-service serve --mode development", "serve": "vue-cli-service serve --mode development",
"build": "vue-cli-service build", "build": "vue-cli-service build",
"build:emoji": "ts-node --files --project tools/tsconfig.json tools/emoji.ts", "build:emoji": "ts-node --files --project tools/tsconfig.json tools/emoji.ts",
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint",
"lib": "vue-cli-service build --target lib --name neko-lib 'src/lib.ts'"
}, },
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^5.14.0", "@fortawesome/fontawesome-free": "^5.14.0",

57
client/src/lib.ts Normal file
View File

@ -0,0 +1,57 @@
// accessor
import { accessor as neko } from './store'
// Plugins
import Logger from './plugins/log'
import Client from './plugins/neko'
import Axios from './plugins/axios'
import Swal from './plugins/swal'
import Anime from './plugins/anime'
// Components
import Connect from '~/components/connect.vue'
import Video from '~/components/video.vue'
import Menu from '~/components/menu.vue'
import Side from '~/components/side.vue'
import Controls from '~/components/controls.vue'
import Members from '~/components/members.vue'
import Emotes from '~/components/emotes.vue'
import About from '~/components/about.vue'
import Header from '~/components/header.vue'
const exportMixin = {
computed: {
$accessor() {
return neko
},
$client () {
return window.$client
}
},
}
function extend (component: any) {
return component
.use(Logger)
.use(Axios)
.use(Swal)
.use(Anime)
.use(Client)
.extend(exportMixin)
}
export const components = {
'neko-connect': extend(Connect),
'neko-video': extend(Video),
'neko-menu': extend(Menu),
'neko-side': extend(Side),
'neko-controls': extend(Controls),
'neko-members': extend(Members),
'neko-emotes': extend(Emotes),
'neko-about': extend(About),
'neko-header': extend(Header),
}
neko.initialise()
export default neko

View File

@ -28,10 +28,16 @@ interface NekoEvents extends BaseEvents {}
export class NekoClient extends BaseClient implements EventEmitter<NekoEvents> { export class NekoClient extends BaseClient implements EventEmitter<NekoEvents> {
private $vue!: Vue private $vue!: Vue
private $accessor!: typeof accessor private $accessor!: typeof accessor
private url!: string
init(vue: Vue) { init(vue: Vue) {
this.initWithSettings(vue, '')
}
initWithSettings(vue: Vue, url: string) {
this.$vue = vue this.$vue = vue
this.$accessor = vue.$accessor this.$accessor = vue.$accessor
this.url = url
} }
private cleanup() { private cleanup() {
@ -43,12 +49,12 @@ export class NekoClient extends BaseClient implements EventEmitter<NekoEvents> {
} }
login(password: string, displayname: string) { login(password: string, displayname: string) {
const url = const url =
process.env.NODE_ENV === 'development' process.env.NODE_ENV === 'development'
? `ws://${location.host.split(':')[0]}:${process.env.VUE_APP_SERVER_PORT}/` ? `ws://${location.host.split(':')[0]}:${process.env.VUE_APP_SERVER_PORT}/`
: `${/https/gi.test(location.protocol) ? 'wss' : 'ws'}://${location.host}/` : `${/https/gi.test(location.protocol) ? 'wss' : 'ws'}://${location.host}/`
this.connect(url, password, displayname) this.connect(this.url || url, password, displayname)
} }
logout() { logout() {