Skip to content

Commit

Permalink
Invalid URL Conditions (#90)
Browse files Browse the repository at this point in the history
Entering an invalid url not does not perform any undefined
functionality. It sends a notify alert to whoever inputted the url.
  • Loading branch information
kyle8998 committed Jun 17, 2018
1 parent 0c82e7b commit 54088cc
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 21 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

Vynchronize is a online video synchronization platform where you can watch videos online with friends in real time!

This is a work in progress, and it is only in the beta stages. Don't expect it to be perfect!

Vynchronize currently supports YouTube, Daily Motion, and Vimeo!

[![forthebadge](https://forthebadge.com/images/badges/60-percent-of-the-time-works-every-time.svg)](http://forthebadge.com)
Expand Down Expand Up @@ -180,3 +178,8 @@ io.sockets.adapter.rooms['room-'+roomnum]
The Queue object consists of arrays for each specific player. Each array then
consists of objects that hold both the id and title. It was created this way because
grabbing the title required extra work, and could not be done continuously on the spot.

##### In Depth Functionality

Please see the [Wiki](https://github.com/kyle8998/Vynchronize/wiki) for more
information.
13 changes: 9 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ <h4 class="modal-title">Invite a Friend</h4>
<!-- Call to Action Well -->
<div class="card text-white bg-secondary my-4 text-center">
<div class="card-body">
<p class="text-white m-0">*The synchronization is not perfect at the moment! It's a work in progress</p>
<p class="text-white m-0">*The synchronization may not be perfect! It's a work in progress, submit an issue on github if you wish to submit a bug report/suggestion.</p>
</div>
</div>

Expand Down Expand Up @@ -499,7 +499,8 @@ <h2>About Vynchronize</h2>
var html = ''
if (yt.length > 0) {
for (i = 0; i < yt.length; i++) {
html += '<li class="vid-item"><div class="thumb"><a href="javascript: removeAt(' + i + ')" class="ghost-button-full-color"><i class="far fa-times-circle"></i></a><a href="javascript: playAt(' + i + ')"><img src="http://img.youtube.com/vi/' + yt[i].videoId + '/0.jpg"></a></div><a href="javascript: playAt(' + i + ')" class="desc">' + yt[i].title + '</a></li>'
html += '<li class="vid-item"><div class="thumb"><a href="javascript: removeAt(' + i + ')" class="ghost-button-full-color"><i class="far fa-times-circle"></i></a><a href="javascript: playAt(' + i +
')"><img src="http://img.youtube.com/vi/' + yt[i].videoId + '/0.jpg"></a></div><a href="javascript: playAt(' + i + ')" class="desc">' + yt[i].title + '</a></li>'
}
} else {
html += '<li class="vid-item"></li>'
Expand All @@ -511,11 +512,15 @@ <h2>About Vynchronize</h2>

// Remove the video from the queue at idx
function removeAt(idx) {
socket.emit('remove at', { idx: idx })
socket.emit('remove at', {
idx: idx
})
}

function playAt(idx) {
socket.emit('play at', { idx: idx }, function(data){
socket.emit('play at', {
idx: idx
}, function(data) {
var videoId = data.videoId

// Change the video
Expand Down
23 changes: 23 additions & 0 deletions js/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,26 @@ function playNextAlert() {
z_index: 1031,
});
}

// When user enters a url, but the url is invalid
function invalidURL() {
$.notify({
title: '<strong>Error: </strong>',
icon: 'fas fa-id-card',
message: "Entered invalid video url"
}, {
type: 'danger',
delay: 400,
animate: {
enter: 'animated fadeInUp',
exit: 'animated fadeOutRight'
},
placement: {
from: "bottom",
align: "right"
},
offset: 20,
spacing: 10,
z_index: 1031,
})
}
45 changes: 30 additions & 15 deletions js/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function seekTo(time) {
// This parses the ID out of the video link
function idParse(videoId) {
// If user enters a full link
if (videoId.includes("https://") || videoId.includes("http://")) {
if (videoId.includes("https://") || videoId.includes("http://") || videoId.includes(".com/")) {
// Do some string processing with regex
switch (currPlayer) {
case 0:
Expand All @@ -137,6 +137,7 @@ function idParse(videoId) {
console.log("You entered a link, but you really meant " + match[1])
return match[1]
}
videoId = "invalid"
break;

case 1:
Expand All @@ -150,6 +151,7 @@ function idParse(videoId) {
console.log("You entered a link, but you really meant " + match[1])
return match[1]
}
videoId = "invalid"
break;

case 2:
Expand All @@ -159,6 +161,7 @@ function idParse(videoId) {
console.log("You entered a link, but you really meant " + match[1])
return match[1]
}
videoId = "invalid"
break;

default:
Expand All @@ -173,12 +176,18 @@ function enqueueVideo(roomnum) {
var videoId = document.getElementById("inputVideoId").value;
videoId = idParse(videoId)

// Actually change the video!
socket.emit('enqueue video', {
room: roomnum,
videoId: videoId,
user: username
});
if (videoId != "invalid") {
// Actually change the video!
socket.emit('enqueue video', {
room: roomnum,
videoId: videoId,
user: username
})
}
else {
console.log("User entered an invalid video url :(")
invalidURL()
}
}

// Empty Queue
Expand All @@ -201,14 +210,20 @@ function changeVideo(roomnum) {
var videoId = document.getElementById("inputVideoId").value;
videoId = idParse(videoId)

var time = getTime()
console.log("The time is this man: " + time)
// Actually change the video!
socket.emit('change video', {
room: roomnum,
videoId: videoId,
time: time
});
if (videoId != "invalid") {
var time = getTime()
console.log("The time is this man: " + time)
// Actually change the video!
socket.emit('change video', {
room: roomnum,
videoId: videoId,
time: time
});
}
else {
console.log("User entered an invalid video url :(")
invalidURL()
}
//player.loadVideoById(videoId);
}

Expand Down

0 comments on commit 54088cc

Please sign in to comment.