Permalink
Browse files

Merge pull request #46 from microp11/master

Removed dependency on irc-js.
  • Loading branch information...
chrismatthieu committed Apr 18, 2012
2 parents 61c1670 + 5f21c0c commit b22d5cd1096b67b94e7791bb59508f6f23de1f0c
Showing with 831 additions and 443 deletions.
  1. +105 −368 irc.js
  2. +0 −1 package.json
  3. +1 −1 public/css/irc.css
  4. +12 −10 public/index.html
  5. +56 −63 public/js/app.js
  6. +446 −0 public/js/irc-client.js
  7. +4 −0 public/js/jquery-1.7.2.min.js
  8. +108 −0 public/js/tcp-client.js
  9. +99 −0 tcp-proxy.js
View
473 irc.js

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -5,7 +5,6 @@
, "author":"Alejandro Morales"
, "dependencies":{
"socket.io":"0.9.x"
- , "irc-js":"*"
, "express":"2.5.x"
}
}
View
@@ -3,7 +3,7 @@
}
html {
background: url(/grad.png);
- font-family: "Open Sans";
+ font-family: Verdana,"Open Sans";
}
#rocket {
margin-left: auto;
View
@@ -3,10 +3,9 @@
<head>
<meta charset="utf-8">
<title>Nodester IRC Channel</title>
- <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
- <link rel="stylesheet" href="css/irc.css" >
+ <link href="http://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
+ <link href="css/irc.css" rel="stylesheet">
</head>
-<body onload="">
<div id="main-wrapper">
<div id="wrapper" class="rocket box">
@@ -16,11 +15,11 @@
<div class="rocket">
<h2>IRC #nodester channel</h2>
<br />
- <p class="off" style="color:red;" id="wrong"> You need to specify a valid nickname</p>
+ <p class="off" style="color:red;" id="wrong">You need to specify a valid nickname</p>
<p class="off" id="login-msg"></p>
<form id="join-form">
<input type="text" id="nick" class="btn" placeholder="username">
- <button href="#" class="btn btn-info" id="join">Join</button>
+ <button type="submit" href="#" class="btn btn-info" id="join">Join</button>
</form>
</div>
<table id="login-status">
@@ -50,7 +49,7 @@ <h2>IRC #nodester channel</h2>
</div>
<div id="chat_bar">
<form id="chat-form">
- <input type="text" id="text_input" class="btn" placeholder="send a message" size="80">
+ <input type="text" id="text_input" class="btn" placeholder="send a message" size="80" />
<button type="submit" class="btn btn-info clic" id="sendMessage">Send</button>
</form>
</div>
@@ -65,12 +64,15 @@ <h2>IRC #nodester channel</h2>
</div>
<div id="js">
- <script src="//code.jquery.com/jquery.js" type="text/javascript"></script>
+ <script src="/js/jquery-1.7.2.min.js" type="text/javascript"></script>
+ <script src="/js/tcp-client.js" type="text/javascript"></script>
+ <script src="/js/irc-client.js" type="text/javascript"></script>
+ <script src="/js/app.js" type="text/javascript"></script>
+ <script src="/socket.io/socket.io.js"></script>
+
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.1/underscore-min.js" type="text/javascript"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.string/1.1.6/underscore.string.min.js" type="text/javascript"></script>
- <script type="text/javascript" src="/js/plugins.min.js"></script>
- <script src="/socket.io/socket.io.js"></script>
- <script src="/js/app.js" type="text/javascript"></script>
+ <script src="/js/plugins.min.js" type="text/javascript"></script>
<script src="/js/date.utils.js" type="text/javascript"></script>
<script src="/js/utils.js" type="text/javascript"></script>
</div>
View
@@ -1,5 +1,6 @@
$(document).ready(function() {
- var sock = null,
+ var ircClient = new IRCClient("irc.freenode.net", 6667);
+ var channel = "#nodester",
rv = null,
nickname = null,
nicks = [], //could be an object if later we decide to add the nick attributes (+,... @)
@@ -56,7 +57,7 @@ $(document).ready(function() {
top : 'auto',
left : 'auto'
},
- stats = null, //statistics
+ stats = null, //statistics .st .current .min .max
serverStartTime = null; //server start time
this.getOpts = function() {
@@ -119,14 +120,15 @@ $(document).ready(function() {
loginWrong.addClass('off');
loginMsg.removeClass('off');
chatBody.text("");
- if (sock !== null && sock.socket.connected === false) {
- sock.socket.reconnect();
- } else {
- sock = io.connect('http://' + window.location.host, {'reconnect': false});
- sock.on('message', handleMessage);
- sock.on('disconnect', handleDisconnect);
- sock.on('connect', handleConnect);
- };
+
+ //initiate connect to the irc server
+ ircClient.clearAll();
+ ircClient.on("connected", handleOnConnected);
+ ircClient.on("disconnected", handleOnDisconnected);
+ ircClient.on("closed", handleOnClosed);
+ ircClient.on("error", handleOnError);
+ ircClient.on("data", handleOnData);
+ ircClient.connect();
} else {
loginWrong.removeClass('off');
}
@@ -187,6 +189,7 @@ $(document).ready(function() {
};
var appendEvent = function (from, event, isSelf, extra) {
+ extra = extra || "no reason";
var row = $('<tr/>');
if (typeof isSelf !== 'undefined' && isSelf === true) {
row.addClass('me btn btn-info');
@@ -198,13 +201,20 @@ $(document).ready(function() {
switch (event) {
case "join":
- message = '<span class="msg-join">joined the channel</span>';
+ message = '<span class="msg-join">joined (' + extra + ')</span>';
break;
case "quit":
+ message = '<span class="msg-quitpart">left (' + extra + ')</span>';
+ break;
case "part":
- message = '<span class="msg-quitpart">left the channel</span>';
+ message = '<span class="msg-quitpart">parted (' + extra + ')</span>';
break;
case "nick":
+ if (isSelf) {
+ //server has automatically changed the nickname
+ nickname = extra;
+ nickLabel.text(nickname);
+ }
message = '<span class="msg-nick">is now known as ' + extra + '</span>';
break;
case "endmotd":
@@ -286,24 +296,22 @@ $(document).ready(function() {
nickUl.html(content);
};
- var handleMessage = function (data) {
+ var handleOnData = function (data) {
var obj = JSON.parse(data);
if (obj && obj.messagetype) {
var isSelf = (obj.from == nickname) ? true : false;
switch (obj.messagetype) {
case "433": //nick already in use
window.spinner.stop();
- sock.disconnect();
+ ircClient.disconnect();
loginMsg.addClass('off');
loginWrong.text("");
loginWrong.removeClass('off');
loginWrong.text(obj.message);
joinBtn.removeAttr("disabled");
return;
- //notice at login
case "notice":
case "notice-err":
- //notice for content
case "notice-msg":
if (c.getIrcNoticesEnabled() == true) {
appendMessage(obj.from, obj.message, false);
@@ -314,18 +322,18 @@ $(document).ready(function() {
loginStatus.html(html);
}
break;
- case "error": //nick already in use
+ case "error": //any error
window.spinner.stop();
- sock.disconnect();
+ ircClient.disconnect();
loginMsg.addClass('off');
loginWrong.text("");
loginWrong.removeClass('off');
- loginWrong.text("Oh well, try again!");
+ loginWrong.text(obj.message);
joinBtn.removeAttr("disabled");
return;
case "message":
appendMessage(obj.from, obj.message, false);
- requestStatistics();
+ ircClient.requestStatistics();
break;
case "topic":
appendMessage("Topic", obj.message, false);
@@ -362,27 +370,29 @@ $(document).ready(function() {
logBox.slideToggle();
nickLabel.text(nickname);
joinBtn.removeAttr("disabled");
+ //initiate single-channel join
+ ircClient.joinChannel(channel);
break;
case "join":
- appendEvent(obj.from, obj.messagetype, isSelf);
+ appendEvent(obj.from, obj.messagetype, isSelf, obj.message);
if (isSelf == false) {
nicks.push(obj.from);
nicks.sort(cisort);
nicksToList();
}
- requestStatistics();
+ ircClient.requestStatistics();
break;
case "quit":
case "part":
- appendEvent(obj.from, obj.messagetype, isSelf);
+ appendEvent(obj.from, obj.messagetype, isSelf, obj.message);
for (var i = 0; i < nicks.length; i++) {
if (nicks[i] == obj.from) {
nicks.splice(i,1);
break;
}
}
nicksToList();
- requestStatistics();
+ ircClient.requestStatistics();
break;
case "nick":
appendEvent(obj.from, obj.messagetype, isSelf, obj.message);
@@ -394,20 +404,20 @@ $(document).ready(function() {
}
nicks.sort(cisort);
nicksToList();
- //requestStatistics(); this call will be needed if the web client will also send commends
+ ircClient.requestStatistics();
break;
case "statistics":
c.updateStats(obj);
if (obj.wud == true) {
- //the webusers list has been changed, we initiate retrieval
- requestWebUsers();
+ //the webUsers list has been changed, we initiate retrieval
+ ircClient.requestWebUsers();
}
var header_class = (c.getStatsEnabled() == true) ? 'header-stats' : 'header-stats off';
nickLabel.html('<span class="'+header_class+'">Server up for ' + c.getServerTime()
+ ', using ' + c.getMinRss() + '-' + c.getMaxRss() + ' MB of RAM</span> ' + nickname);
break;
case "webusers":
- webNicks = obj.wu;
+ webNicks = obj.webusers;
nicksToList();
break;
default:
@@ -419,14 +429,14 @@ $(document).ready(function() {
}
};
- var handleConnect = function () {
+ var handleOnConnected = function () {
loginMsg.text("");
loginStatus.html("");
var nick = window.nick = getNickname(nickText.val());
loginMsg.text("Joining as " + nick + "...");
joinBtn.prop("disabled", "disabled");
c.setIrcNoticesEnabled(false);
- sock.send(JSON.stringify({ nickname: nick }));
+ ircClient.registerNick(nick);
//start spinner
window.target = document.getElementById('join-form');
window.spinner = new Spinner(c.getOpts()).spin(window.target);
@@ -436,34 +446,33 @@ $(document).ready(function() {
* set a time delay for disconnect
* in case we exit the form we do not want the user to see it
*/
- var handleDisconnect = function () {
+ var handleOnDisconnected = function () {
setTimeout( function () {
appendEvent("*", "disconnected", false);
nicks = [];
nicksToList();
}, 1000);
};
- var sendMessage = function () {
- appendMessage(nickname, textInput.val(), true);
- sock.send(JSON.stringify({
- messagetype: "message",
- message: textInput.val()
- }));
- textInput.val('');
- };
-
/*
- * requesting statistics is user action triggered
- * in case it is proven to be to resource intensive
- * another solution can be sought, e.g., on a timer
+ * TODO
+ * These messages and actions are to be refined later once we cover
+ * the entire existing functionality
*/
- var requestStatistics = function () {
- sock.send(JSON.stringify({ statistics: ""}))
+ var handleOnClosed = function () {
+ appendEvent("*", "disconnected", false);
+ nicks = [];
+ nicksToList();
};
- var requestWebUsers = function () {
- sock.send(JSON.stringify({ webusers: ""}))
+ var handleOnError = function () {
+ appendEvent("*", "error", false);
+ };
+
+ var sendMessage = function () {
+ appendMessage(nickname, textInput.val(), true);
+ ircClient.sendPrivMsg(textInput.val());
+ textInput.val('');
};
chatForm.on('submit', function (e) {
@@ -477,22 +486,6 @@ $(document).ready(function() {
return false;
});
-/* var ocolors = {
- 'bold' : ['\033[1m', '\033[22m'],
- 'italic' : ['\033[3m', '\033[23m'],
- 'underline' : ['\033[4m', '\033[24m'],
- 'inverse' : ['\033[7m', '\033[27m'],
- 'white' : ['\033[37m', '\033[39m'],
- 'grey' : ['\033[90m', '\033[39m'],
- 'black' : ['\033[30m', '\033[39m'],
- 'blue' : ['\033[34m', '\033[39m'],
- 'cyan' : ['\033[36m', '\033[39m'],
- 'green' : ['\033[32m', '\033[39m'],
- 'magenta' : ['\033[35m', '\033[39m'],
- 'red' : ['\033[31m', '\033[39m'],
- 'yellow' : ['\033[33m', '\033[39m']
- };
-*/
var colors = {
'p' :['<p>','</p>'],
'[1m' :['<strong>','</strong>'],
Oops, something went wrong.

0 comments on commit b22d5cd

Please sign in to comment.