Skip to content
This repository
  • 2 commits
  • 7 files changed
  • 0 comments
  • 2 contributors
Sep 29, 2012
HyeonJe Jun Make 'keeping connection alive' optional. de7bcea
Oct 01, 2012
David Petersen Merge pull request #168 from noraesae/master
make 'keeping connection alive' optional
9505050
3  assets/js/client.js
@@ -75,9 +75,9 @@ $(function() {
75 75 });
76 76
77 77 irc.socket.on('login_success', function(data) {
  78 + window.irc.loggedIn = true;
78 79 if(data.exists){
79 80 irc.socket.emit('connect', {});
80   - window.irc.loggedIn = true;
81 81 } else {
82 82 irc.appView.overview.render({currentTarget: {id: "connection"}});
83 83 }
@@ -90,6 +90,7 @@ $(function() {
90 90
91 91
92 92 irc.socket.on('register_success', function(data) {
  93 + window.irc.loggedIn = true;
93 94 irc.appView.overview.render({currentTarget: {id: "connection"}});
94 95 });
95 96
12 assets/js/views/overview.js
@@ -22,7 +22,7 @@ var OverviewView = Backbone.View.extend({
22 22 $('#overview').html(ich.overview_home());
23 23 } else {
24 24 var func = ich['overview_' + event.currentTarget.id];
25   - $('#overview').html(func());
  25 + $('#overview').html(func({'loggedIn': irc.loggedIn}));
26 26 }
27 27
28 28 $('.overview_button').bind('click', $.proxy(this.render, this));
@@ -57,7 +57,8 @@ var OverviewView = Backbone.View.extend({
57 57 selfSigned = $('#connect-selfSigned').is(':checked'),
58 58 rejoin = $('#connect-rejoin').is(':checked'),
59 59 password = $('#connect-password').val(),
60   - encoding = $('#connect-encoding').val();
  60 + encoding = $('#connect-encoding').val(),
  61 + keepAlive = false;
61 62
62 63 if (!server) {
63 64 $('#connect-server').closest('.control-group').addClass('error');
@@ -66,6 +67,10 @@ var OverviewView = Backbone.View.extend({
66 67 if (!nick) {
67 68 $('#connect-nick').closest('.control-group').addClass('error');
68 69 }
  70 +
  71 + if (irc.loggedIn && $('#connect-keep-alive').length) {
  72 + keepAlive = $('#connect-keep-alive').is(':checked');
  73 + }
69 74
70 75 if (nick && server) {
71 76 $('form').append(ich.load_image());
@@ -81,7 +86,8 @@ var OverviewView = Backbone.View.extend({
81 86 away: away,
82 87 realName: realName,
83 88 password: password,
84   - encoding: encoding
  89 + encoding: encoding,
  90 + keepAlive: keepAlive
85 91 };
86 92
87 93 irc.me = new User(connectInfo);
7 lib/irclink.js
@@ -8,7 +8,7 @@ var Connection = mongoose.model('Connection');
@@ -42,6 +42,8 @@ var IRCLink = function(hostname, port, ssl, selfSigned, nick, realName, password
@@ -138,6 +140,9 @@ IRCLink.prototype = {
3  lib/models.js
@@ -21,7 +21,8 @@ module.exports = function() {
21 21 channels: [String],
22 22 nick: String,
23 23 password: String,
24   - encoding: String
  24 + encoding: String,
  25 + keepAlive: Boolean
25 26 });
26 27
27 28 var Messages = new Schema({
2  lib/restore.js
@@ -8,7 +8,7 @@ module.exports = function (connections) {
8 8 // restore connections
9 9 Connection.find({},function(err, docs){
10 10 docs.forEach(function(doc){
11   - var connection = new IRCLink(doc.hostname, doc.port, doc.ssl, doc.selfSigned, doc.nick, doc.realName, doc.password, doc.rejoin, doc.away, doc.encoding, doc.channels);
  11 + var connection = new IRCLink(doc.hostname, doc.port, doc.ssl, doc.selfSigned, doc.nick, doc.realName, doc.password, doc.rejoin, doc.away, doc.encoding, doc.keepAlive, doc.channels);
12 12 connection.associateUser(doc.user);
13 13 connections[doc.user] = connection;
14 14 // set ourselves as away
20 lib/socket.js
@@ -57,7 +57,7 @@ module.exports = function(socket, connections) {
57 57 connection = connections[current_user.username];
58 58 }
59 59 if(connection === undefined) {
60   - connection = new IRCLink(data.server, data.port, data.secure, data.selfSigned, data.nick, data.realName, data.password, data.rejoin, data.away, data.encoding);
  60 + connection = new IRCLink(data.server, data.port, data.secure, data.selfSigned, data.nick, data.realName, data.password, data.rejoin, data.away, data.encoding, data.keepAlive);
61 61
62 62 // save this connection
63 63 if(current_user){
@@ -75,12 +75,16 @@ module.exports = function(socket, connections) {
75 75 channels: data.channels,
76 76 nick: data.nick,
77 77 password: data.password,
78   - encoding: data.encoding});
  78 + encoding: data.encoding,
  79 + keepAlive: data.keepAlive});
79 80
80 81 conn.save();
81 82 connections[current_user.username] = connection;
82 83 }
83 84 } else {
  85 + if(!connection.keepAlive) {
  86 + connection.connect();
  87 + }
84 88 socket.emit('restore_connection', {nick: connection.client.nick,
85 89 server: connection.client.opt.server, channels: connection.client.chans});
86 90 connection.clearUnreads();
@@ -164,9 +168,15 @@ module.exports = function(socket, connections) {
164 168 // not logged in, drop this session
165 169 connection.disconnect();
166 170 } else {
167   - // keep the session alive, remove this socket, and clear unreads
168   - connection.removeSocket(socket);
169   - connection.clearUnreads();
  171 + if(connection.keepAlive) {
  172 + // keep the session alive, remove this socket, and clear unreads
  173 + connection.removeSocket(socket);
  174 + connection.clearUnreads();
  175 + }
  176 + else {
  177 + // disconnect the session
  178 + connection.disconnect();
  179 + }
170 180 }
171 181 });
172 182
5 views/templates.jade
@@ -87,6 +87,11 @@ script(id="overview_connection", type="text/html")
87 87 option(value="CP1251") CP1251 (Cyrillic)
88 88 option(value="CP1256") CP1256 (Arabic)
89 89 option(value="CP1257") CP1257 (baltic)
  90 + .control-group
  91 + {{#loggedIn}}
  92 + label.checkbox(for="connect-keep-alive", style="width:100%") Keep connection alive after browser closed
  93 + input#connect-keep-alive(type="checkbox")
  94 + {{/loggedIn}}
90 95 a(id="connect-button", class="btn btn-primary spacing-right", type="button") Connect
91 96 a(id="connect-more-options-button", class="btn", type="button") More Options
92 97

No commit comments for this range

Something went wrong with that request. Please try again.