Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect to lecture2gether room when it is entered #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the check if the URL contains e.g. lecture2go is missing in the new version. Or is this handled in another way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I can see it; yes that check has been removed. But I don't really understand what it was supposed to do?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this comment a long time ago, but I think it this check checks if the entered url is a valid one for one of our services (l2f, yt, mp4, ...) otherwise the red url bar is shown.

let url;
try {
url = new URL(this.url);
} catch (e) {
this.urlIsValid = false;
return;
}
if (checkURL(url)) {
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,
};
}