Websocket connection established

This commit is contained in:
Raelon Masters
2020-08-08 10:12:06 -04:00
parent 5d97c066a9
commit f3d9d8160f
13 changed files with 205 additions and 72 deletions

View File

@@ -6,19 +6,24 @@ $(document).ready(function(){
};
};
/* Initialize ui variables */
var outstream = []; // put customlog messages here
var win_height = window.innerHeight; // Get the displays height
var win_width = window.innerWidth; // Get the displays width
var scr_height = window.outerHeight;
var scr_width = window.outerWidth;
var hdr_height = $('.app_hdr').height(); // Get our header height
var ftr_height = $('.app_footer').height(); // Get our footer height
var nav_width = $('.nav_l').width(); // Get the width of our nav items
var cmp_height = window.screen.availHeight;
var max_height = win_height - (hdr_height + ftr_height) - (scr_height - win_height); // Set our available height
var u_string = "Username";
var p_string = "Password";
var s_string = "search by Title, Author, Tags, or Collections";
let outstream = []; // put customlog messages here
let win_height = window.innerHeight; // Get the displays height
let win_width = window.innerWidth; // Get the displays width
let scr_height = window.outerHeight;
let scr_width = window.outerWidth;
let hdr_height = $('.app_hdr').height(); // Get our header height
let ftr_height = $('.app_footer').height(); // Get our footer height
let nav_width = $('.nav_l').width(); // Get the width of our nav items
let cmp_height = window.screen.availHeight;
let max_height = win_height - (hdr_height + ftr_height) - (scr_height - win_height); // Set our available height
const u_string = "Username";
const p_string = "Password";
const s_string = "search by Title, Author, Tags, or Collections";
const popover = $('#pop_over_0')
const navlink = $('.nav_link')
const inputbox = $('input_box')
const loginbtn = $('#btn_login')
const server = ('ws://127.0.0.1:1337')
customlog([cmp_height]);
$(".search_submit").click(function(){
var query = $('.nav_search').val();
@@ -33,7 +38,7 @@ $(document).ready(function(){
$(this).removeAttr("disabled");
}
});
$('.nav_link').on('mouseover', function (e){
$(navlink).on('mouseover', function (e){
var popover_str = $(this).attr('alt');
x = $(this).offset().left;
y = $(this).offset().to;
@@ -42,7 +47,7 @@ $(document).ready(function(){
$('.popover').css('top', y);
$('.popover').css('display','flex');
});
$('.nav_link').on('mouseout', function (e){
$(navlink).on('mouseout', function (e){
var popover_str = $(this).attr('alt');
x = $(this).offset().left;
y = $(this).offset().top;
@@ -54,10 +59,10 @@ $(document).ready(function(){
$('#btn_collections').on('click', function (e){
$('.hidden.vert-nav.collections').toggle();
});
$('.input_box').on('click', function(){
$(inputbox).on('click', function(){
$(this).attr("value","");
});
$('.input_box').focusout(function(){
$(inputbox).focusout(function(){
if ($(this).hasClass('nav_search') && $(this).val() == "") {
$(this).attr("value", s_string);
}
@@ -68,7 +73,7 @@ $(document).ready(function(){
$(this).attr("value", p_string);
}
});
$('#btn_login').on('click', function(){
$(loginbtn).on('click', function(){
$('#hdr_nav_login').toggle();
})
$('.favorite_action').on('click', function(){
@@ -88,11 +93,11 @@ $(document).ready(function(){
window.location.href="/flip_sort/"+$("#_order").val();
});
$('#search_string').html("<i> "+$('#_search').val().substr(0,15)+"</i>");
$('#pop_over_0').dialog({ autoOpen: false });
$('#pop_over_0').on('click', 'div.collection', function(){
$(popover).dialog({ autoOpen: false });
$(popover).on('click', 'div.collection', function(){
window.location.href = '/show_collection/'+$(this).attr('data');
});
$('#btn_login').on('click', function() {
$(loginbtn).on('click', function() {
var isopen = $('#pop_over_0').dialog("isOpen");
if (isopen) {
$('#pop_over_0').dialog("close");
@@ -167,36 +172,8 @@ $(document).ready(function(){
});
$(document).on('click', '.logout-btn', function(){window.location.href = '/logout'});
$(document).on('click', '.import-btn', function(){
$.ajax({
type: "GET", url: "/live", data: {hook: 'import_books'},
success: function (response) {
// Set the dialog title
$('#pop_over_0').dialog({
title: "User Controls",
maxHeight: (win_height - 100),
minWidth: $("#horiz_nav_main").width(),
hide: {effect: "blind", duration: 1000},
show: {effect: "blind", duration: 1000},
position: {
my: "top", at: "bottom", of: $("#horiz_nav_main")
}
});
// clear and create a new container
$('#pop_over_0').html('<div id=usercp class="mx-auto">');
// Populate the container from response.data
$('#usercp').append('<div class="row" id="usercp-inner">');
$('#usercp-inner').append(response.data);
$('#usercp-inner').append('</div>');
$('#usercp').append('</div>');
// Close the container
$('#pop_over').append('</div>');
// Now open this dialog
$('#pop_over_0').dialog("open");
},
error: function (response) {
customlog(["Failure", response]);
}
});
let socket = PyshelfSocket(server);
ping(socket);
});
$('#coll_button').on('click', function(){
var isopen = $('#pop_over_0').dialog("isOpen");
@@ -279,6 +256,7 @@ $(document).ready(function(){
resize_search();
$(window).resize(resize_search(win_width));
});
function resize_search(win_width){
if (win_width <= 1025){
$('.search_string').attr('size', 20);
@@ -290,3 +268,28 @@ function resize_search(win_width){
}
}
function PyshelfSocket(address) {
const connection = new WebSocket(address);
connection.onconnect = function(e){
ping(connection);
};
connection.onmessage = function(rcvd){
sock_rx(rcvd)
};
return connection;
}
function sock_rx(rcvd) {
if (rcvd.data == 'pong') { pong(rcvd.data) }
else { console.log("<<[rx] :"+rcvd.data) }
}
function sock_status(sock) {
let buffered = sock.connection.bufferedAmmount;
let ready = sock.connection.readyState;
return [buffered, ready];
}
function ping(sock) {
sock.send('ping')
}
function pong(rcvd) {
console.log("<<["+rcvd.data+"] "+rcvd.data)
}