Refactoring

This commit is contained in:
Mattias Erming 2014-06-15 19:26:05 +02:00
parent 37581b7e45
commit e506522eac
4 changed files with 62 additions and 32 deletions

View File

@ -30,7 +30,7 @@
<div class="wrap"> <div class="wrap">
<h1>Shout</h1> <h1>Shout</h1>
<h2>You need to sign in to continue.</h2> <h2>You need to sign in to continue.</h2>
<form method="post"> <form id="sign-in-form" method="post">
<h3>Password:</h3> <h3>Password:</h3>
<input type="password" id="sign-in-input"> <input type="password" id="sign-in-input">
<button type="submit" class="btn"> <button type="submit" class="btn">

View File

@ -1,6 +1,7 @@
$(function() { $(function() {
var chat = $("#chat"); var chat = $("#chat");
var sidebar = $("#sidebar"); var sidebar = $("#sidebar");
var windows = $("#windows");
setTimeout(function() { setTimeout(function() {
// Enable transitions. // Enable transitions.
@ -41,6 +42,7 @@ $(function() {
var socket = io.connect(""); var socket = io.connect("");
var events = [ var events = [
"debug",
"join", "join",
"messages", "messages",
"msg", "msg",
@ -62,6 +64,10 @@ $(function() {
function event(e, data) { function event(e, data) {
switch (e) { switch (e) {
case "debug":
console.log(data);
break;
case "join": case "join":
chat.append(render("windows", {windows: [data.chan]})) chat.append(render("windows", {windows: [data.chan]}))
.find(".window") .find(".window")
@ -295,6 +301,12 @@ $(function() {
}); });
windows.on("submit", "#sign-in-form", function(e) {
e.preventDefault();
var password = $("#sign-in-input").val();
socket.emit("debug", password);
});
function complete(word) { function complete(word) {
var words = commands.slice(); var words = commands.slice();
var users = $(this).closest(".window") var users = $(this).closest(".window")

View File

@ -1,10 +1,11 @@
module.exports = { module.exports = {
password: "",
port: 9000, port: 9000,
messages: 100,
defaults: { defaults: {
nick: "shout_user", nick: "shout-user",
realname: "http://github.com/erming/shout", realname: "http://github.com/erming/shout",
}, },
messages: 100,
networks: [{ networks: [{
host: "irc.freenode.org", host: "irc.freenode.org",
port: 6667, port: 6667,

View File

@ -43,12 +43,12 @@ function listen() {
.listen(port); .listen(port);
var self = this; var self = this;
sockets = io.listen(app, {log: 0}).sockets.on("connection", function(s) { sockets = io.listen(app, {log: 0}).sockets.on("connection", function(socket) {
s.emit("networks", {networks: networks}); if (!config.password) {
s.on("input", input); init.call(socket);
s.on("fetch", function(data) { } else {
fetch(s, data); socket.emit("debug", "auth");
}); }
}); });
(config.networks || []).forEach(function(n) { (config.networks || []).forEach(function(n) {
@ -56,6 +56,17 @@ function listen() {
}); });
} }
function init() {
var socket = this;
socket.on("debug", debug);
socket.on("input", input);
socket.on("fetch", fetch);
socket.emit(
"networks",
{networks: networks}
);
}
function index(req, res, next) { function index(req, res, next) {
if (req.url != "/") return next(); if (req.url != "/") return next();
fs.readFile("client/index.html", function(err, file) { fs.readFile("client/index.html", function(err, file) {
@ -116,7 +127,12 @@ function connect(params) {
}); });
} }
function debug(data) {
console.log(data);
}
function input(data) { function input(data) {
var socket = this;
var target = find(data.id); var target = find(data.id);
if (!target) { if (!target) {
return; return;
@ -359,7 +375,8 @@ function input(data) {
} }
} }
function fetch(socket, data) { function fetch(data) {
var socket = this;
var target = find(data.id); var target = find(data.id);
if (!target) { if (!target) {
return; return;