diff --git a/lecture2gether-vue/src/components/Player.vue b/lecture2gether-vue/src/components/Player.vue index 0f8cee4..84e6852 100644 --- a/lecture2gether-vue/src/components/Player.vue +++ b/lecture2gether-vue/src/components/Player.vue @@ -88,7 +88,13 @@ export default class L2gPlayer extends Vue { getSourceFromURL(url: string): {type: string; src: string} { // shared media logic in src/mediaURLs.ts checkURL - const res = checkURL(url); + let parsedUrl; + try { + parsedUrl = new URL(url); + } catch (e) { + throw new Error('Invalid URL'); + } + const res = checkURL(parsedUrl); if (res === undefined) { throw new Error('URL not supported'); } else { diff --git a/lecture2gether-vue/src/components/Toolbar.vue b/lecture2gether-vue/src/components/Toolbar.vue index 69ef100..6fd8313 100644 --- a/lecture2gether-vue/src/components/Toolbar.vue +++ b/lecture2gether-vue/src/components/Toolbar.vue @@ -96,26 +96,32 @@ export default class Toolbar extends Vue { } // update the url to point to the lecture2go playlist when it is a // lecture2go url - let url: string = this.url; - if (url.includes('lecture2go') || url.includes('/l2go/')) { + let url; + try { + url = new URL(this.url); + } catch (e) { + this.urlIsValid = false; + return; + } + if (url.host.includes('lecture2go') || url.pathname.includes('/l2go/')) { this.urlIsValid = true; const password = this.$store.state.player.password; - url = await getL2goPlaylist(this.$store, url, password); + url = await getL2goPlaylist(this.$store, url.toString(), password); if (url === '') return; } - if (this.isValidVideoUrl(url)) { + if (checkURL(url) !== undefined) { this.urlIsValid = true; if (this.$store.state.isConnected) this.$store.dispatch('setUrl', url); else console.warn('Not setting url because we are not connected'); + } else if (url.host === window.location.host) { + // A lecture2gether url was entered, redirect to that room + await this.$store.dispatch('leaveRoom'); + await this.$router.push(url.pathname); } else { this.urlIsValid = false; } } - isValidVideoUrl(url: string) { - return checkURL(url) !== undefined; - } - // Save url to clipboard async saveUrlClipboard() { this.showingTooltip = true; diff --git a/lecture2gether-vue/src/mediaURLs.ts b/lecture2gether-vue/src/mediaURLs.ts index d128685..e1eeb63 100644 --- a/lecture2gether-vue/src/mediaURLs.ts +++ b/lecture2gether-vue/src/mediaURLs.ts @@ -1,5 +1,5 @@ -export function checkURL(url: string): {type: string, src: URL,} | undefined { - const extensions2types: [string,string][] = +export function checkURL(url: URL): {type: string, src: URL,} | undefined { + const extensions2types: [string,string][] = [['m3u8', 'application/x-mpegURL'] ,['mp4', 'video/mp4'] ,['ogg', 'video/ogg'] @@ -15,24 +15,17 @@ export function checkURL(url: string): {type: string, src: URL,} | undefined { return res === undefined ? undefined : res[1]; }; - let host, extension, urlobj; - try { - urlobj = new URL(url); - host = urlobj.hostname; - extension = urlobj.pathname.split('.').pop(); - } catch { - return undefined; - } + let host = url.hostname; + let extension = url.pathname.split('.').pop(); - let type; //check type based on extension first - type = assoc(extensions2types, extension); + let type = assoc(extensions2types, extension); //check type based on hostname next if (type === undefined) type = assoc(host2types, host); if (type === undefined) return undefined; return { type: type, - src: urlobj, + src: url, }; }