diff --git a/src/component/main.vue b/src/component/main.vue index 336e1f75..9e1d1104 100644 --- a/src/component/main.vue +++ b/src/component/main.vue @@ -88,6 +88,12 @@ @Prop({ type: Boolean }) private readonly autoplay!: boolean + @Prop({ type: Boolean }) + private readonly autologin!: boolean + + @Prop({ type: String }) + private readonly server!: string + ///////////////////////////// // Public state ///////////////////////////// @@ -164,10 +170,31 @@ ///////////////////////////// // Public methods ///////////////////////////// + @Watch('server', { immediate: true }) public setUrl(url: string) { + if (!url) { + url = location.href + } + const httpURL = url.replace(/^ws/, 'http').replace(/\/$|\/ws\/?$/, '') this.api.setUrl(httpURL) this.websocket.setUrl(httpURL) + + if (this.connected) { + this.websocket.disconnect(new Error('url changed')) + } + + if (this.authenticated) { + Vue.set(this.state.connection, 'authenticated', false) + } + + // check if is user logged in + if (this.autologin) { + this.api.session.whoami().then(() => { + Vue.set(this.state.connection, 'authenticated', true) + this.websocket.connect() + }) + } } public async login(id: string, secret: string) { @@ -483,12 +510,6 @@ } }) - // check if is user logged in - this.api.session.whoami().then(() => { - Vue.set(this.state.connection, 'authenticated', true) - this.websocket.connect() - }) - // unmute on users first interaction if (this.autoplay) { document.addEventListener('click', this.unmute, { once: true })