Archived
2
0

relative websocket URL.

This commit is contained in:
m1k1o 2021-03-10 23:02:34 +01:00
parent afb416ea57
commit 69e7990afb
2 changed files with 3 additions and 3 deletions

View File

@ -59,7 +59,7 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
this[EVENT.CONNECTING]()
try {
this._ws = new WebSocket(`${url}ws?password=${password}`)
this._ws = new WebSocket(`${url}?password=${encodeURIComponent(password)}`)
this.emit('debug', `connecting to ${this._ws.url}`)
this._ws.onmessage = this.onMessage.bind(this)
this._ws.onerror = (event) => this.onError.bind(this)

View File

@ -33,8 +33,8 @@ export class NekoClient extends BaseClient implements EventEmitter<NekoEvents> {
init(vue: Vue) {
const url =
process.env.NODE_ENV === 'development'
? `ws://${location.host.split(':')[0]}:${process.env.VUE_APP_SERVER_PORT}/`
: `${/https/gi.test(location.protocol) ? 'wss' : 'ws'}://${location.host}/`
? `ws://${location.host.split(':')[0]}:${process.env.VUE_APP_SERVER_PORT}/ws`
: location.href.replace(/^http/, 'ws').replace(/\/$/, '')+'/ws'
this.initWithURL(vue, url)
}