Refactoring
This commit is contained in:
parent
37581b7e45
commit
e506522eac
@ -26,20 +26,20 @@
|
||||
</aside>
|
||||
<div id="main">
|
||||
<div id="windows">
|
||||
<div id="sign-in" class="window">
|
||||
<div class="wrap">
|
||||
<h1>Shout</h1>
|
||||
<h2>You need to sign in to continue.</h2>
|
||||
<form method="post">
|
||||
<h3>Password:</h3>
|
||||
<input type="password" id="sign-in-input">
|
||||
<button type="submit" class="btn">
|
||||
Sign in
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<div id="sign-in" class="window">
|
||||
<div class="wrap">
|
||||
<h1>Shout</h1>
|
||||
<h2>You need to sign in to continue.</h2>
|
||||
<form id="sign-in-form" method="post">
|
||||
<h3>Password:</h3>
|
||||
<input type="password" id="sign-in-input">
|
||||
<button type="submit" class="btn">
|
||||
Sign in
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="chat">
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,6 +1,7 @@
|
||||
$(function() {
|
||||
var chat = $("#chat");
|
||||
var sidebar = $("#sidebar");
|
||||
var windows = $("#windows");
|
||||
|
||||
setTimeout(function() {
|
||||
// Enable transitions.
|
||||
@ -41,6 +42,7 @@ $(function() {
|
||||
|
||||
var socket = io.connect("");
|
||||
var events = [
|
||||
"debug",
|
||||
"join",
|
||||
"messages",
|
||||
"msg",
|
||||
@ -62,6 +64,10 @@ $(function() {
|
||||
|
||||
function event(e, data) {
|
||||
switch (e) {
|
||||
case "debug":
|
||||
console.log(data);
|
||||
break;
|
||||
|
||||
case "join":
|
||||
chat.append(render("windows", {windows: [data.chan]}))
|
||||
.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) {
|
||||
var words = commands.slice();
|
||||
var users = $(this).closest(".window")
|
||||
|
27
config.js
27
config.js
@ -1,15 +1,16 @@
|
||||
module.exports = {
|
||||
port: 9000,
|
||||
messages: 100,
|
||||
defaults: {
|
||||
nick: "shout_user",
|
||||
realname: "http://github.com/erming/shout",
|
||||
},
|
||||
networks: [{
|
||||
host: "irc.freenode.org",
|
||||
port: 6667,
|
||||
channels: [
|
||||
"#shout-irc",
|
||||
],
|
||||
}]
|
||||
password: "",
|
||||
port: 9000,
|
||||
defaults: {
|
||||
nick: "shout-user",
|
||||
realname: "http://github.com/erming/shout",
|
||||
},
|
||||
messages: 100,
|
||||
networks: [{
|
||||
host: "irc.freenode.org",
|
||||
port: 6667,
|
||||
channels: [
|
||||
"#shout-irc",
|
||||
],
|
||||
}]
|
||||
};
|
||||
|
@ -43,12 +43,12 @@ function listen() {
|
||||
.listen(port);
|
||||
|
||||
var self = this;
|
||||
sockets = io.listen(app, {log: 0}).sockets.on("connection", function(s) {
|
||||
s.emit("networks", {networks: networks});
|
||||
s.on("input", input);
|
||||
s.on("fetch", function(data) {
|
||||
fetch(s, data);
|
||||
});
|
||||
sockets = io.listen(app, {log: 0}).sockets.on("connection", function(socket) {
|
||||
if (!config.password) {
|
||||
init.call(socket);
|
||||
} else {
|
||||
socket.emit("debug", "auth");
|
||||
}
|
||||
});
|
||||
|
||||
(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) {
|
||||
if (req.url != "/") return next();
|
||||
fs.readFile("client/index.html", function(err, file) {
|
||||
@ -116,7 +127,12 @@ function connect(params) {
|
||||
});
|
||||
}
|
||||
|
||||
function debug(data) {
|
||||
console.log(data);
|
||||
}
|
||||
|
||||
function input(data) {
|
||||
var socket = this;
|
||||
var target = find(data.id);
|
||||
if (!target) {
|
||||
return;
|
||||
@ -359,7 +375,8 @@ function input(data) {
|
||||
}
|
||||
}
|
||||
|
||||
function fetch(socket, data) {
|
||||
function fetch(data) {
|
||||
var socket = this;
|
||||
var target = find(data.id);
|
||||
if (!target) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user