mirror of
https://github.com/thelounge/thelounge
synced 2024-11-29 07:20:25 +00:00
Replace node-irc with slate-irc
This commit is contained in:
parent
dc0add0fef
commit
d88967e712
5 changed files with 163 additions and 67 deletions
|
@ -90,7 +90,7 @@
|
|||
</div>
|
||||
<div class="users">
|
||||
{{#each users}}
|
||||
<a href="{{name}}" class="user" style="color: {{color name}}">
|
||||
<a href="{{name}}" class="user">
|
||||
{{mode}}{{name}}
|
||||
</a>
|
||||
{{/each}}
|
||||
|
@ -99,8 +99,8 @@
|
|||
{{#each messages}}
|
||||
<div class="message {{type}}">
|
||||
<span class="time">{{time}}</span>
|
||||
<a href="{{user}}" class="user" style="color: {{color user}}">{{mode}}{{user}}</a>
|
||||
<span class="text">{{type}} {{{link text}}}</span>
|
||||
<a href="{{user}}" class="user">{{mode}}{{user}}</a>
|
||||
<span class="text">{{type}} {{{link message}}}</span>
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
|
@ -114,7 +114,7 @@
|
|||
|
||||
<script type="text/html" id="user">
|
||||
{{#users}}
|
||||
<a href="{{name}}" class="user" style="color: {{color name}}">
|
||||
<a href="{{name}}" class="user">
|
||||
{{mode}}{{name}}
|
||||
</a>
|
||||
{{/users}}
|
||||
|
@ -124,8 +124,8 @@
|
|||
{{#messages}}
|
||||
<div class="message {{type}}">
|
||||
<span class="time">{{time}}</span>
|
||||
<a href="{{user}}" class="user" style="color: {{color user}}">{{mode}}{{user}}</a>
|
||||
<span class="text">{{type}} {{{link text}}}</span>
|
||||
<a href="{{user}}" class="user">{{mode}}{{user}}</a>
|
||||
<span class="text">{{type}} {{{link message}}}</span>
|
||||
</div>
|
||||
{{/messages}}
|
||||
</script>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
$(function() {
|
||||
var socket = io.connect("");
|
||||
$.each(["networks", "channels", "messages", "users"], function(i, type) {
|
||||
$.each(["network", "channel", "message", "user"], function(i, type) {
|
||||
socket.on(type, function(json) {
|
||||
event(type, json);
|
||||
});
|
||||
|
@ -16,9 +16,10 @@ $(function() {
|
|||
}
|
||||
|
||||
function event(type, json) {
|
||||
console.log(json);
|
||||
switch (type) {
|
||||
|
||||
case "networks":
|
||||
case "network":
|
||||
var html = "";
|
||||
json.forEach(function(network) {
|
||||
html += render("#window", network);
|
||||
|
@ -37,7 +38,7 @@ $(function() {
|
|||
.bringToTop();
|
||||
break;
|
||||
|
||||
case "channels":
|
||||
case "channel":
|
||||
var target = json.target;
|
||||
if (json.action == "remove") {
|
||||
$("[data-id='" + json.data.id + "']").remove();
|
||||
|
@ -65,7 +66,7 @@ $(function() {
|
|||
.scrollGlue({animate: 400});
|
||||
break;
|
||||
|
||||
case "users":
|
||||
case "user":
|
||||
var target;
|
||||
if (typeof json.target !== "undefined") {
|
||||
target = chat.find(".window[data-id='" + json.target + "']");
|
||||
|
@ -75,7 +76,7 @@ $(function() {
|
|||
target.html(render("#user", {users: json.data}));
|
||||
break;
|
||||
|
||||
case "messages":
|
||||
case "message":
|
||||
var target;
|
||||
if (typeof json.target !== "undefined") {
|
||||
target = chat.find(".window[data-id='" + json.target + "']");
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
var irc = require("irc");
|
||||
var _ = require("lodash");
|
||||
var Backbone = require("backbone");
|
||||
var moment = require("moment");
|
||||
var backbone = require("backbone");
|
||||
var moment = require("moment");
|
||||
|
||||
var id = 1;
|
||||
var models =
|
||||
module.exports =
|
||||
{};
|
||||
|
||||
var id = 1;
|
||||
|
||||
models.User = Backbone.Model.extend({
|
||||
models.User = backbone.Model.extend({
|
||||
defaults: {
|
||||
mode: "",
|
||||
name: ""
|
||||
name: "",
|
||||
}
|
||||
});
|
||||
|
||||
models.Users = Backbone.Collection.extend({
|
||||
models.Users = backbone.Collection.extend({
|
||||
model: models.User,
|
||||
sort: function(options) {
|
||||
this.models = _.sortBy(
|
||||
|
@ -39,23 +37,23 @@ models.Users = Backbone.Collection.extend({
|
|||
}
|
||||
});
|
||||
|
||||
models.Message = Backbone.Model.extend({
|
||||
models.Message = backbone.Model.extend({
|
||||
defaults: {
|
||||
type: "",
|
||||
time: "",
|
||||
user: "",
|
||||
text: "",
|
||||
type: ""
|
||||
from: "",
|
||||
message: "",
|
||||
},
|
||||
initialize: function() {
|
||||
this.set("time", moment().format("HH:mm"));
|
||||
}
|
||||
});
|
||||
|
||||
models.Messages = Backbone.Collection.extend({
|
||||
models.Messages = backbone.Collection.extend({
|
||||
model: models.Message
|
||||
});
|
||||
|
||||
models.Channel = Backbone.Model.extend({
|
||||
models.Channel = backbone.Model.extend({
|
||||
defaults: {
|
||||
type: "channel",
|
||||
name: ""
|
||||
|
@ -67,7 +65,7 @@ models.Channel = Backbone.Model.extend({
|
|||
|
||||
this.set("messages", new models.Messages());
|
||||
this.get("messages").on("all", function(action, data) {
|
||||
this.trigger("MESSAGES", {
|
||||
this.trigger("message", {
|
||||
target: this.get("id"),
|
||||
type: "message",
|
||||
data: data,
|
||||
|
@ -77,7 +75,7 @@ models.Channel = Backbone.Model.extend({
|
|||
|
||||
this.set("users", new models.Users());
|
||||
this.get("users").on("all", function(action) {
|
||||
this.trigger("USERS", {
|
||||
this.trigger("user", {
|
||||
target: this.get("id"),
|
||||
type: "user",
|
||||
data: this.get("users"),
|
||||
|
@ -87,14 +85,13 @@ models.Channel = Backbone.Model.extend({
|
|||
}
|
||||
});
|
||||
|
||||
models.Channels = Backbone.Collection.extend({
|
||||
models.Channels = backbone.Collection.extend({
|
||||
model: models.Channel
|
||||
});
|
||||
|
||||
models.Network = Backbone.Model.extend({
|
||||
models.Network = backbone.Model.extend({
|
||||
defaults: {
|
||||
host: "",
|
||||
nick: "nick"
|
||||
host: ""
|
||||
},
|
||||
initialize: function() {
|
||||
this.set({
|
||||
|
@ -103,10 +100,10 @@ models.Network = Backbone.Model.extend({
|
|||
|
||||
this.set("channels", new models.Channels());
|
||||
this.get("channels").on("all", function(action, data) {
|
||||
if (action == "USERS" || action == "MESSAGES") {
|
||||
if (action == "user" || action == "message") {
|
||||
this.trigger(action, data);
|
||||
} else {
|
||||
this.trigger("CHANNELS", {
|
||||
this.trigger("channel", {
|
||||
target: this.get("id"),
|
||||
type: "channel",
|
||||
data: data,
|
||||
|
@ -122,12 +119,11 @@ models.Network = Backbone.Model.extend({
|
|||
}
|
||||
});
|
||||
|
||||
models.Networks = Backbone.Collection.extend({
|
||||
models.Networks = backbone.Collection.extend({
|
||||
model: models.Network,
|
||||
initialize: function() {
|
||||
this.add(new models.Network({
|
||||
host: "Lobby",
|
||||
connect: false
|
||||
host: "Status"
|
||||
}));
|
||||
},
|
||||
find: function(id) {
|
||||
|
|
148
lib/server.js
148
lib/server.js
|
@ -1,31 +1,71 @@
|
|||
var connect = require("connect");
|
||||
var _ = require("lodash");
|
||||
var io = require("socket.io");
|
||||
|
||||
// Local library
|
||||
var models = require("./models");
|
||||
var http = require("connect");
|
||||
var io = require("socket.io");
|
||||
var irc = require("slate-irc");
|
||||
var models = require(__dirname + "/models");
|
||||
var net = require("net");
|
||||
var _ = require("lodash");
|
||||
|
||||
var sockets;
|
||||
var networks = new models.Networks;
|
||||
|
||||
module.exports = function server(options) {
|
||||
var app = connect().use(connect.static("client")).listen(9000);
|
||||
sockets = io.listen(app, {log: 0}).sockets;
|
||||
sockets.on("connection", function(s) {
|
||||
init(s);
|
||||
var events = [
|
||||
"away",
|
||||
"join",
|
||||
"kick",
|
||||
"names",
|
||||
"nick",
|
||||
"notice",
|
||||
"part",
|
||||
"pong",
|
||||
"privmsg",
|
||||
"quit",
|
||||
"topic",
|
||||
"welcome",
|
||||
"whois"
|
||||
];
|
||||
|
||||
module.exports = function listen() {
|
||||
var app = http()
|
||||
.use(http.static("client"))
|
||||
.listen(9000);
|
||||
|
||||
sockets = io.listen(app, {log: 0}).sockets.on("connection", function(s) {
|
||||
s.on("input", input);
|
||||
sockets.emit("network", networks);
|
||||
});
|
||||
|
||||
networks.on("all", function(e) {
|
||||
sockets.emit("networks", networks);
|
||||
networks.on("all", function() {
|
||||
sockets.emit.apply(sockets, arguments);
|
||||
});
|
||||
};
|
||||
|
||||
function init(socket) {
|
||||
socket.on("input", function(json) { clientInput(json); });
|
||||
sockets.emit("networks", networks);
|
||||
function connect(host) {
|
||||
var network = new models.Network({host: host}, {silent: true});
|
||||
networks.add(network);
|
||||
networks.trigger("network", networks);
|
||||
|
||||
var stream = net.connect({
|
||||
port: 6667,
|
||||
host: host,
|
||||
});
|
||||
|
||||
stream.on("error", function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
var client = irc(stream);
|
||||
|
||||
client.nick("t_user");
|
||||
client.user("t_user", "temp user");
|
||||
|
||||
events.forEach(function(e) {
|
||||
client.on(e, function(data) {
|
||||
event.apply(network, [e, data]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function clientInput(json) {
|
||||
function input(json) {
|
||||
var target = networks.find(json.id);
|
||||
if (!target) {
|
||||
return;
|
||||
|
@ -48,18 +88,14 @@ function clientInput(json) {
|
|||
channel.get("name")
|
||||
);
|
||||
case "msg":
|
||||
var m = new models.Message({text: _.tail(args, 2)});
|
||||
channel.get("messages").add(m);
|
||||
channel.get("messages").add(new models.Message({text: _.tail(args, 2)}));
|
||||
break;
|
||||
|
||||
case "server":
|
||||
case "connect":
|
||||
if (!args[1]) {
|
||||
break;
|
||||
if (args[1]) {
|
||||
connect(args[1]);
|
||||
}
|
||||
|
||||
var n = new models.Network({host: args[1]});
|
||||
networks.add(n);
|
||||
break;
|
||||
|
||||
case "quit":
|
||||
|
@ -68,4 +104,68 @@ function clientInput(json) {
|
|||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function event(event, data) {
|
||||
var network = this;
|
||||
var channels = network.get("channels");
|
||||
|
||||
switch (event) {
|
||||
|
||||
case "away":
|
||||
console.log(event);
|
||||
break;
|
||||
|
||||
case "join":
|
||||
console.log(event);
|
||||
break;
|
||||
|
||||
case "kick":
|
||||
console.log(event);
|
||||
break;
|
||||
|
||||
case "names":
|
||||
console.log(event);
|
||||
break;
|
||||
|
||||
case "nick":
|
||||
console.log(event);
|
||||
break;
|
||||
|
||||
case "notice":
|
||||
channels.first().get("messages").add(new models.Message(data));
|
||||
break;
|
||||
|
||||
case "part":
|
||||
console.log(event);
|
||||
break;
|
||||
|
||||
case "pong":
|
||||
console.log(event);
|
||||
break;
|
||||
|
||||
case "privmsg":
|
||||
console.log(event);
|
||||
break;
|
||||
|
||||
case "quit":
|
||||
console.log(event);
|
||||
break;
|
||||
|
||||
case "topic":
|
||||
console.log(event);
|
||||
break;
|
||||
|
||||
case "welcome":
|
||||
console.log(event);
|
||||
break;
|
||||
|
||||
case "whois":
|
||||
console.log(event);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// Debug
|
||||
console.log(data);
|
||||
}
|
13
package.json
13
package.json
|
@ -7,13 +7,12 @@
|
|||
"email": "mattias@mattiaserming.com"
|
||||
},
|
||||
"dependencies": {
|
||||
"backbone": "1.1.2",
|
||||
"connect": "2.13.0",
|
||||
"irc": "0.3.6",
|
||||
"lodash": "2.4.1",
|
||||
"moment": "2.5.1",
|
||||
"socket.io": "0.9.16",
|
||||
"slate-irc": "~0.4.0"
|
||||
"lodash": "~2.4.1",
|
||||
"backbone": "~1.1.2",
|
||||
"slate-irc": "~0.4.0",
|
||||
"moment": "~2.5.1",
|
||||
"connect": "~2.14.3",
|
||||
"socket.io": "~0.9.16"
|
||||
},
|
||||
"keywords": [
|
||||
"chat",
|
||||
|
|
Loading…
Reference in a new issue