SHARE
TWEET

Untitled

a guest May 21st, 2017 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var socket = io.connect("http://76.4.123.203:8001");
  2.  
  3. socket.on('connect_error', function() {
  4.     console.log("Socket is unable to connect.");
  5. });
  6.  
  7. socket.on('connect', function() {
  8.     console.log("Socket is connected!");
  9.     var connect = new Audio("connected.ogg");
  10.     connect.play();
  11. });
  12.  
  13. $(document).ready(function() {
  14.  
  15. $("#play").click(function() {
  16.     var data = $("input[name=jukebox]").val();
  17.     socket.emit("jukebox-send", data);
  18. });
  19.  
  20. socket.on("jukebox-play", function(data) {
  21.     $("#jukebox").attr("src", "https://www.youtube.com/embed/" + data + "?autoplay=1");
  22. });
  23.  
  24. });
  25.  
  26. // EHWe_f1IQ_s
  27.  
  28.  
  29. -------- SERVER ---------
  30.  
  31. var client = require("socket.io").listen(8001).sockets;
  32. var mysql = require("mysql");
  33. var colors = require("colors");
  34. var crypto = require("crypto");
  35. var fs = require("fs");
  36.  
  37. var config = {
  38.     host: "localhost",
  39.     user: "root",
  40.     password: "",
  41.     database: "melonpw"
  42. };
  43.  
  44. var users = {};
  45.  
  46. var num = 0;
  47. var con;
  48.  
  49. function log(text, color) {
  50.     var d = new Date();
  51.     var h = d.getHours();
  52.     var m = d.getMinutes();
  53.     var ap = "AM";
  54.     if (h > 12) {
  55.         h -= 12;
  56.         var ap = "PM";
  57.     }
  58.     if (m < 10) {
  59.         m = "0" + m;
  60.     }
  61.     time = h + ":" + m + " " + ap;
  62.  
  63.     if (typeof(color) == "undefined") {
  64.         display = colors.grey(time) + ": " + text;
  65.         console.log(display);
  66.     } else {
  67.         console.log(colors.grey(time) + ": " + colors[color](text));
  68.     }
  69. }
  70.  
  71. function handleConnection() {
  72.     con = mysql.createConnection(config);
  73.  
  74.     con.connect(function(err) {
  75.         if (err) {
  76.             log("An error has occurred while connection: " + err, "red");
  77.             setTimeout(handleConnection, 2000);
  78.         } else {
  79.             log("Connection successful.", "green");
  80.         }
  81.     });
  82.  
  83.     con.on("error", function(err) {
  84.         console.log("Error: " + err);
  85.         if (err.code === "PROTOCOL_CONNECTION_LOST") {
  86.             handleConnection();
  87.         } else {
  88.             throw err;
  89.         }
  90.     });
  91. }
  92.  
  93. function getCurrentTime() {
  94.     var date = new Date();
  95.     var hours = date.getHours();
  96.     var minutes = date.getMinutes();
  97.     var period = "AM";
  98.  
  99.     if (minutes < 10) {
  100.         minutes = "0" + minutes;
  101.     }
  102.  
  103.     if (hours > 12) {
  104.         hours -= 12;
  105.         period = "PM";
  106.     }
  107.  
  108.     return hours + ":" + minutes + " " + period;
  109. }
  110.  
  111. function genID() {
  112.     var length = 8;
  113.     var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVYXYZ';
  114.     var result = '';
  115.     for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
  116.     return result;
  117. }
  118.  
  119. handleConnection();
  120. client.on("connection", function(socket) {
  121.  
  122. socket.on("jukebox-send", function(data) {
  123.     socket.emit("jukebox-play", data);
  124. });
  125.  
  126. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top