Cleaning up files and some organization

This commit is contained in:
joeyak 2019-03-10 16:45:10 -04:00
parent 5cdafe8f42
commit ecf64dff8a
9 changed files with 280 additions and 418 deletions

View File

@ -90,11 +90,10 @@ func main() {
// Chat websocket
http.HandleFunc("/ws", wsHandler)
http.HandleFunc("/static/", wsStaticFiles)
http.HandleFunc("/static/js/", wsStaticFiles)
http.HandleFunc("/static/site.css", wsStaticFiles)
http.HandleFunc("/emotes/", wsEmotes)
http.HandleFunc("/favicon.ico", wsStaticFiles)
http.HandleFunc("/jquery.js", wsStaticFiles)
http.HandleFunc("/ractive.min.js", wsStaticFiles)
http.HandleFunc("/justchat", wsStaticFiles)
http.HandleFunc("/justvideo", wsStaticFiles)

View File

@ -1,140 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<title>Movie Night!</title>
<style>
body {
margin:0;
padding:0;
background:#000;
}
<head>
<meta charset='utf-8'>
<title>Movie Night!</title>
<link rel="stylesheet" type="text/css" href="/static/site.css">
<script type="application/javascript" src="/static/js/jquery.js"></script>
<script type="application/javascript" src="/static/js/flv.min.js"></script>
<script type="application/javascript" src="/static/js/client.js"></script>
</head>
html, body, #messages, #phase2 {
height:100%;
}
video {
width:100%;
}
#streambox {
width: 80%;
float: left;
margin: 0;
}
#chatbox {
width: 19%;
float: right;
height:85%;
}
#messages {
border: 1px solid #666;
width: 95%;
overflow: auto;
color: #f4f4f4;
}
#msg {
width: 94%;
height: 3em;
}
#error {
color: #f00;
padding: 5px;
font-weight: bold;
}
span.name {
font-weight:bold;
}
span.cmdme {
font-style: italic;
}
span.msg {
font-style: normal;
color: #cfccd1;
}
span.svmsg {
font-style: italic;
color: #ea6260;
}
.announcement {
font-weight: bold;
color: #ea6260;
text-align: center;
width: 100%;
margin-top: 10px;
margin-bottom: 10px;
border-top: 3px solid red;
border-bottom: 3px solid red;
}
#playingDiv {
color: #8b6a96;
font-weight: bold;
padding: 10px;
}
#playing {
font-size: x-Large;
}
</style>
<script src="/static/jquery.js"></script>
<script src="/static/flv.min.js"></script>
<script>
function initPlayer() {
if (flvjs.isSupported()) {
var videoElement = document.getElementById('videoElement');
var flvPlayer = flvjs.createPlayer({
type: 'flv',
url: '/live'
});
flvPlayer.attachMediaElement(videoElement);
flvPlayer.load();
flvPlayer.play();
}
}
function escapeHtml(string) {
return string;
//return String(string).replace(/[&<>"'\/]/g, function (s) {
// return entityMap[s];
//});
}
//helper function for debugging purposes
function toHex(str) {
var result = '';
for (var i=0; i<str.length; i++) {
result += ("0"+str.charCodeAt(i).toString(16)).slice(-2)+" ";
}
return result.toUpperCase();
}
function setPlaying(title, link) {
if (title === "") {
$('#playingDiv').hide();
document.title = "Movie Night"
return;
}
$('#playingDiv').show();
$('#playing').text(title);
document.title = "Movie Night | " + title
if (link === "") {
$('#playinglink').hide();
return;
}
$('#playinglink').show();
$('#playinglink').text('[Info Link]');
$('#playinglink').attr('href', link);
}
</script>
</head>
<body>
<div id="streambox">
<body>
<div id="streambox">
<video id="videoElement" controls autoplay x5-video-player-type="h5" x5-video-player-fullscreen="true" playsinline webkit-playsinline>
Your browser is too old and doesn't support HTML5 video.
@ -143,87 +19,19 @@ function setPlaying(title, link) {
<button style="float:right" id="reload" onclick="initPlayer();">Reload Player</button>
<div id="playingDiv"><span id="playing"></span><br /><a href="" target="_blank" id="playinglink"></a></div>
</div>
<div id="chatbox">
<div id="phase1">
<p style="color:#e5e0e5">Please enter your name to Join the chat</P>
<input id="name">
<button id="join">Join</button>
</div>
<div id="chatbox">
<div id="phase1">
<p style="color:#e5e0e5">Please enter your name to Join the chat</P>
<input id="name">
<button id="join">Join</button>
</div>
<div id="error"></div>
<div id="phase2" style="opacity:0">
<div id="messages"></div>
<textarea id="msg"></textarea>
<br/><button id="send">Send</button>
</div>
<script>
$("INPUT").val("")
$("#name").keypress(function(evt){
if(evt.originalEvent.keyCode==13){
$("#join").trigger("click")
//submit name
}
})
//handling the start of the chat
$("#join").click(function(){
$("#error").html("");
var name= escapeHtml($("#name").val())
if(name.length<3){
$("#error").html("Name is too short!");
return
}
console.log("join started")
chat = new WebSocket("ws://"+window.location.host+":8089/ws");
chat.onopen = function(evt) {
chat.send(name); //sending the chat name
$("#phase1").animate({opacity:0},500,"linear",function(){
$("#phase1").css({display:"none"})
$("#phase2").css({opacity:1})
$("#msg").focus()
})
};
chat.onerror = function(evt) {
console.log("Websocket Error:",evt)
};
chat.onclose = function(evt) {
console.log("chat closing")
$("#phase1").stop().css({display:"block"}).animate({opacity:1},500)
$("#phase2").stop().animate({opacity:0})
$("#error").html("That name was already used!")
};
chat.onmessage = function(evt) {
$("#messages").append(evt.data).scrollTop(9e6)
};
})
$("#msg").keypress(function(evt){
if(evt.originalEvent.keyCode==13 && !evt.originalEvent.shiftKey){
$("#send").trigger("click")
evt.preventDefault();
// submit name
}
})
$("#send").click(function(){
chat.send(escapeHtml($("#msg").val()));
$("#msg").val("");
})
//helper function for escaping HTML
var entityMap = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;',
"\n": '<BR/>'
};
</script>
<div id="error"></div>
<div id="phase2" style="opacity:0">
<div id="messages"></div>
<textarea id="msg"></textarea>
<br/><button id="send">Send</button>
</div>
</body>
</div>
</body>
</html>

118
static/js/client.js Normal file
View File

@ -0,0 +1,118 @@
function initPlayer() {
if (flvjs.isSupported()) {
var videoElement = document.getElementById('videoElement');
var flvPlayer = flvjs.createPlayer({
type: 'flv',
url: '/live'
});
flvPlayer.attachMediaElement(videoElement);
flvPlayer.load();
flvPlayer.play();
}
}
function escapeHtml(string) {
return string;
//return String(string).replace(/[&<>"'\/]/g, function (s) {
// return entityMap[s];
//});
}
//helper function for debugging purposes
function toHex(str) {
var result = '';
for (var i = 0; i < str.length; i++) {
result += ("0" + str.charCodeAt(i).toString(16)).slice(-2) + " ";
}
return result.toUpperCase();
}
function setPlaying(title, link) {
if (title === "") {
$('#playingDiv').hide();
document.title = "Movie Night"
return;
}
$('#playingDiv').show();
$('#playing').text(title);
document.title = "Movie Night | " + title
if (link === "") {
$('#playinglink').hide();
return;
}
$('#playinglink').show();
$('#playinglink').text('[Info Link]');
$('#playinglink').attr('href', link);
}
window.onload = function () {
console.log("TEST 1")
$("INPUT").val("")
$("#name").keypress(function (evt) {
console.log("TEST 2")
if (evt.originalEvent.keyCode == 13) {
console.log("TEST 3")
$("#join").trigger("click")
}
})
//handling the start of the chat
$("#join").click(function () {
$("#error").html("");
var name = escapeHtml($("#name").val())
if (name.length < 3) {
$("#error").html("Name is too short!");
return
}
console.log("join started")
chat = new WebSocket("ws://" + window.location.host + ":8089/ws");
chat.onopen = function (evt) {
chat.send(name); //sending the chat name
$("#phase1").animate({ opacity: 0 }, 500, "linear", function () {
$("#phase1").css({ display: "none" })
$("#phase2").css({ opacity: 1 })
$("#msg").focus()
})
};
chat.onerror = function (evt) {
console.log("Websocket Error:", evt)
};
chat.onclose = function (evt) {
console.log("chat closing")
$("#phase1").stop().css({ display: "block" }).animate({ opacity: 1 }, 500)
$("#phase2").stop().animate({ opacity: 0 })
$("#error").html("That name was already used!")
};
chat.onmessage = function (evt) {
$("#messages").append(evt.data).scrollTop(9e6)
};
})
$("#msg").keypress(function (evt) {
if (evt.originalEvent.keyCode == 13 && !evt.originalEvent.shiftKey) {
$("#send").trigger("click")
evt.preventDefault();
// submit name
}
})
$("#send").click(function () {
chat.send(escapeHtml($("#msg").val()));
$("#msg").val("");
})
//helper function for escaping HTML
var entityMap = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;',
"\n": '<BR/>'
};
}

View File

@ -1,169 +1,35 @@
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<title>Movie Night! - Chat</title>
<style>
body {
margin:0;
padding:0;
background:#000;
}
html, body, #messages, #phase2 {
height:100%;
}
video {
width:100%;
}
<head>
<meta charset='utf-8'>
<title>Movie Night! - Chat</title>
<link rel="stylesheet" type="text/css" href="/static/site.css">
<script src="/static/js/jquery.js"></script>
<script src="/static/js/client.js"></script>
<style>
#chatbox {
width: 100%;
height:85%;
}
#messages {
border: 1px solid #666;
width: 95%;
overflow: auto;
color: #f4f4f4;
}
#msg {
width: 94%;
height: 3em;
}
#error {
color: #f00;
padding: 5px;
font-weight: bold;
}
span.name {
font-weight:bold;
}
span.cmdme {
font-style: italic;
}
span.msg {
font-style: normal;
color: #cfccd1;
}
span.svmsg {
font-style: italic;
color: #ea6260;
float: left;
}
.announcement {
font-weight: bold;
color: #ea6260;
text-align: center;
width: 100%;
margin-top: 10px;
margin-bottom: 10px;
border-top: 3px solid red;
border-bottom: 3px solid red;
#phase1 {
margin: 0px 10px;
}
</style>
<script src="/static/jquery.js"></script>
<script>
function escapeHtml(string) {
return string
//return String(string).replace(/[&<>"'\/]/g, function (s) {
// return entityMap[s];
//});
}
</style>
</head>
//helper function for debugging purposes
function toHex(str) {
var result = '';
for (var i=0; i<str.length; i++) {
result += ("0"+str.charCodeAt(i).toString(16)).slice(-2)+" ";
}
return result.toUpperCase();
}
</script>
</head>
<body>
<div id="chatbox">
<div id="phase1">
<p style="color:#e5e0e5">Please enter your name to Join the chat</P>
<input id="name">
<button id="join">Join</button>
</div>
<div id="error"></div>
<div id="phase2" style="opacity:0">
<div id="messages"></div>
<textarea id="msg"></textarea>
<br/><button id="send">Send</button>
</div>
<script>
$("INPUT").val("")
$("#name").keypress(function(evt){
if(evt.originalEvent.keyCode==13){
$("#join").trigger("click")
//submit name
}
})
//handling the start of the chat
$("#join").click(function(){
$("#error").html("");
var name= escapeHtml($("#name").val())
if(name.length<3){
$("#error").html("Name is too short!");
return
}
console.log("join started")
chat = new WebSocket("ws://"+window.location.host+":8089/ws");
chat.onopen = function(evt) {
chat.send(name); //sending the chat name
$("#phase1").animate({opacity:0},500,"linear",function(){
$("#phase1").css({display:"none"})
$("#phase2").css({opacity:1})
$("#msg").focus()
})
};
chat.onerror = function(evt) {
console.log("Websocket Error:",evt)
};
chat.onclose = function(evt) {
console.log("chat closing")
$("#phase1").stop().css({display:"block"}).animate({opacity:1},500)
$("#phase2").stop().animate({opacity:0})
$("#error").html("That name was already used!")
};
chat.onmessage = function(evt) {
$("#messages").append(evt.data).scrollTop(9e6)
};
})
$("#msg").keypress(function(evt){
if(evt.originalEvent.keyCode==13 && !evt.originalEvent.shiftKey){
$("#send").trigger("click")
evt.preventDefault();
// submit name
}
})
$("#send").click(function(){
chat.send(escapeHtml($("#msg").val()));
$("#msg").val("");
})
//helper function for escaping HTML
var entityMap = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;',
"\n": '<BR/>'
};
</script>
<body>
<div id="chatbox">
<div id="phase1">
<p style="color:#e5e0e5">Please enter your name to Join the chat</P>
<input id="name">
<button id="join">Join</button>
</div>
</body>
<div id="error"></div>
<div id="phase2" style="opacity:0">
<div id="messages"></div>
<textarea id="msg"></textarea>
<br /><button id="send">Send</button>
</div>
</div>
</body>
</html>

View File

@ -1,48 +1,33 @@
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<title>Movie Night!</title>
<style>
body {
margin:0;
padding:0;
background:#000;
}
html, body{
height:100%;
}
video {
width:100%;
height:100%;
}
</style>
<script src="/static/jquery.js"></script>
<script src="/static/flv.min.js"></script>
<head>
<meta charset='utf-8'>
<title>Movie Night!</title>
<link rel="stylesheet" type="text/css" href="/static/site.css">
<script src="/static/js/jquery.js"></script>
<script src="/static/js/flv.min.js"></script>
<script>
function initPlayer() {
if (flvjs.isSupported()) {
var videoElement = document.getElementById('videoElement');
var flvPlayer = flvjs.createPlayer({
type: 'flv',
url: '/live'
});
flvPlayer.attachMediaElement(videoElement);
flvPlayer.load();
flvPlayer.play();
}
}
function initPlayer() {
if (flvjs.isSupported()) {
var videoElement = document.getElementById('videoElement');
var flvPlayer = flvjs.createPlayer({
type: 'flv',
url: '/live'
});
flvPlayer.attachMediaElement(videoElement);
flvPlayer.load();
flvPlayer.play();
}
}
</script>
</head>
</head>
<body>
<video id="videoElement" controls autoplay x5-video-player-type="h5" x5-video-player-fullscreen="true" playsinline webkit-playsinline>
Your browser is too old and doesn't support HTML5 video.
</video>
<script>initPlayer();</script>
</body>
<body>
<video id="videoElement" controls autoplay x5-video-player-type="h5" x5-video-player-fullscreen="true" playsinline webkit-playsinline>
Your browser is too old and doesn't support HTML5 video.
</video>
<script>initPlayer();</script>
</body>
</html>

86
static/site.css Normal file
View File

@ -0,0 +1,86 @@
body {
margin: 0;
padding: 0;
background: #000;
}
html,
body,
#messages,
#phase2 {
height: 100%;
}
video {
width: 100%;
height: 100%;
}
#streambox {
width: 80%;
float: left;
margin: 0;
}
#chatbox {
width: 19%;
float: right;
height: 85%;
}
#messages {
border: 1px solid #666;
width: 95%;
overflow: auto;
color: #f4f4f4;
}
#msg {
width: 94%;
height: 3em;
}
#error {
color: #f00;
padding: 5px;
font-weight: bold;
}
span.name {
font-weight: bold;
}
span.cmdme {
font-style: italic;
}
span.msg {
font-style: normal;
color: #cfccd1;
}
span.svmsg {
font-style: italic;
color: #ea6260;
}
.announcement {
font-weight: bold;
color: #ea6260;
text-align: center;
width: 100%;
margin-top: 10px;
margin-bottom: 10px;
border-top: 3px solid red;
border-bottom: 3px solid red;
}
#playingDiv {
color: #8b6a96;
font-weight: bold;
padding: 10px;
}
#playing {
font-size: x-Large;
}