Skip to content
Browse files

Merge pull request #35 from thedjpetersen/25/feature/message_signals

25/feature/message signals
  • Loading branch information...
2 parents 4e9967d + dba9b54 commit fae1cf13dfba279fd7d198ca734d2405a9ade746 @thedjpetersen committed Jan 28, 2012
View
13 README.md
@@ -5,7 +5,7 @@ Subway
Subway is an IRC client/server combination. The server works for multiple simultaneous users, with optional persistent connections and logging. The client is a modern JavaScript-heavy web interface. Server/client communication is done with websockets (or best available fallback) via socket.io.
-Subway utilizes [node.js](http://nodejs.org/) and
+Subway utilizes [node.js](http://nodejs.org/) and
Martyn Smith's [node-irc](https://github.com/martynsmith/node-irc) on the backend,
and [Backbone.js](http://documentcloud.github.com/backbone/) and
[jQuery](http://jquery.com/) on the frontend.
@@ -14,7 +14,7 @@ and [Backbone.js](http://documentcloud.github.com/backbone/) and
Status
------
-Nothing works yet. Functionality to come shortly. If you'd like to contribute,
+Nothing works yet. Functionality to come shortly. If you'd like to contribute,
there is plenty to do. Tickets for needed functionality also to come shortly.
Installation
@@ -49,10 +49,10 @@ node_modules directory.
History
-------
-Subway is a combination of two projects that started independently
+Subway is a combination of two projects that started independently
with a similar technology stack and similar aims:
-- [subway-web](https://github.com/thedjpetersen/subway-web) /
+- [subway-web](https://github.com/thedjpetersen/subway-web) /
[subway-server](https://github.com/thedjpetersen/subway-server)
by David Petersen
- [web-irc](https://github.com/akavlie/web-irc) by Aaron Kavlie
@@ -63,9 +63,14 @@ Its goals are twofold:
from any web browser
+
License
-------
+Excepting third-party assets (licensed as specified in their respective files
+or directories), this project is covered by the MIT License:
+
+
The MIT License (MIT)
Copyright (c) 2011 David Petersen
View
7 assets/js/collections.js
@@ -16,11 +16,10 @@ var WindowList = Backbone.Collection.extend({
model: ChatWindow,
initialize: function() {
- var self = this;
+ this.bind('add', this.setActive, this);
this.bind('add', function(chat) {
- self.setActive(chat);
- });
-
+ if (chat.get('type') === 'pm') this.trigger('forMe', 'newPm');
+ })
},
getByName: function(name) {
View
10 assets/js/models.js
@@ -164,10 +164,16 @@ var ChatWindow = Backbone.Model.extend({
setUnread: function(msg) {
if (this.get('active')) return;
- // Increment our unread messages
+ var signal = false;
+ // Increment unread messages
this.set({unread: this.get('unread') + 1});
- if (msg.get('mention'))
+ if (this.get('type') === 'pm') signal = true;
+ if (msg.get('mention')) {
this.set({unreadMentions: this.get('unreadMentions') + 1});
+ signal = true;
+ }
+ // All PMs & mentions
+ if (signal) this.trigger('forMe', 'message');
}
});
View
35 assets/js/views/chat_application.js
@@ -3,10 +3,18 @@ var ChatApplicationView = Backbone.View.extend({
originalTitle: document.title,
initialize: function() {
+ irc.chatWindows.bind('change:active', this.focus, this)
+ .bind('change:unread', this.showUnread, this)
+ .bind('change:unreadMentions', this.showUnread, this)
+ .bind('forMe', this.playSound, this);
+ // Preload sound files
+ if (this._supportedFormat) {
+ this.sounds = {
+ newPm: this._loadSound('new-pm'),
+ message: this._loadSound('msg')
+ };
+ }
this.render();
- irc.chatWindows.bind('change:active', this.focus, this);
- irc.chatWindows.bind('change:unread', this.showUnread, this);
- irc.chatWindows.bind('change:unreadMentions', this.showUnread, this);
},
render: function() {
@@ -33,5 +41,26 @@ var ChatApplicationView = Backbone.View.extend({
document.title = '(' + unreads + ') ' + this.originalTitle;
else
document.title = this.originalTitle;
+ },
+
+ playSound: function(type) {
+ this.sounds && this.sounds[type].play();
+ },
+
+ _loadSound: function(name) {
+ var a = new Audio();
+ a.src = '/assets/sounds/' + name + '.' + this._supportedFormat();
+ console.log(a.src);
+ return a;
+ },
+
+ // Detect supported HTML5 audio format
+ _supportedFormat: function() {
+ var a = document.createElement('audio');
+ if (!a.canPlayType) return false;
+ else if (!!(a.canPlayType('audio/ogg; codecs="vorbis"').replace(/no/, '')))
+ return 'ogg'
+ else if (!!(a.canPlayType('audio/mpeg;').replace(/no/, '')))
+ return 'mp3'
}
});
View
12 assets/sounds/LICENSE.txt
@@ -0,0 +1,12 @@
+The following sound files were taken from the "Visions I" Adium Sound Set:
+
+- msg.ogg
+- msg.mp3
+- new-pm.ogg
+- new-pm.mp3
+
+This sound set was created by Jamie Soar, and is covered by the
+Creative Commons BY-ND 3.0 license (http://creativecommons.org/licenses/by-nd/3.0/)
+
+The original sound set can be found here:
+http://www.adiumxtras.com/index.php?a=xtras&xtra_id=7612
View
BIN assets/sounds/msg.mp3
Binary file not shown.
View
BIN assets/sounds/msg.ogg
Binary file not shown.
View
BIN assets/sounds/new-pm.mp3
Binary file not shown.
View
BIN assets/sounds/new-pm.ogg
Binary file not shown.
View
2 lib/webserver.js
@@ -5,7 +5,7 @@ var app = exports.app = express.createServer();
app.configure(function() {
// executed for each env
app.use(require('connect-assets')());
- app.use("/assets/images", express.static(__dirname + '/../assets/images'));
+ app.use("/assets", express.static(__dirname + '/../assets'));
console.log(__dirname);
});

0 comments on commit fae1cf1

Please sign in to comment.
Something went wrong with that request. Please try again.