Skip to content

Commit

Permalink
redirect to lecture2gether room when it is entered
Browse files Browse the repository at this point in the history
This also cleans up some URL logic and closes #13
  • Loading branch information
timonegk committed Jun 5, 2020
1 parent af68854 commit 3f97c86
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
8 changes: 7 additions & 1 deletion lecture2gether-vue/src/components/Player.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 14 additions & 8 deletions lecture2gether-vue/src/components/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 6 additions & 13 deletions lecture2gether-vue/src/mediaURLs.ts
Original file line number Diff line number Diff line change
@@ -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']
Expand All @@ -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,
};
}

0 comments on commit 3f97c86

Please sign in to comment.