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 20, 2020
1 parent 7075bfc commit 31a3c4c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 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 @@ -93,7 +93,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
18 changes: 12 additions & 6 deletions lecture2gether-vue/src/components/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ export default class Toolbar extends Vue {
throw new Error(`${response.status}: Resource not available`);
});
}
// update the url to point to the lecture2go playlist when it is a
if (this.isValidVideoUrl(this.url) || this.url.includes('lecture2go') || this.url.includes('/l2go/')) {
let url;
try {
url = new URL(this.url);
} catch (e) {
this.urlIsValid = false;
return;
}
if (checkURL(url) || this.url.includes('lecture2go') || this.url.includes('/l2go/')) {
const password = this.$store.state.player.password;
const videoMetaData = await getVideoMetaData(this.$store, this.url, password);
if (!videoMetaData) {
Expand All @@ -105,6 +111,10 @@ export default class Toolbar extends Vue {
delete videoMetaData.streamUrl;
this.$store.dispatch('setVideoMetaData', videoMetaData);
}
} 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;
}
Expand All @@ -114,10 +124,6 @@ export default class Toolbar extends Vue {
return this.$store.state.rooms.userCount;
}
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 31a3c4c

Please sign in to comment.