diff --git a/public/js/cryptalk_modules/audio.js b/public/js/cryptalk_modules/audio.js index 97efc39..ce8fa9f 100644 --- a/public/js/cryptalk_modules/audio.js +++ b/public/js/cryptalk_modules/audio.js @@ -9,7 +9,7 @@ // Sounds module, used for emitting those annoying bl-up sounds when receiving a message define(['queue','mediator'], function (queue,mediator) { - var ac = false, + var ac = false, enabled = true, channel = mediator(), diff --git a/public/js/cryptalk_modules/cryptalk.js b/public/js/cryptalk_modules/cryptalk.js index 595fa5b..da8783d 100644 --- a/public/js/cryptalk_modules/cryptalk.js +++ b/public/js/cryptalk_modules/cryptalk.js @@ -1,8 +1,9 @@ // Main cryptalk module define({ compiles: ['$'], - requires: ['mediator','hosts', 'templates', 'audio', 'fandango','notifications','sounds'] + requires: ['mediator','hosts', 'templates', 'audio', 'fandango','notifications','sounds','win'] }, function ($, requires, data) { + var socket, key, host, @@ -31,6 +32,7 @@ define({ templates = requires.templates, sounds = requires.sounds, channel = requires.mediator(), + win = requires.win, lockInput = function () { components.input[0].setAttribute('disabled', 'disabled'); @@ -346,10 +348,17 @@ define({ mute: function () { mute = true; + return post('info', templates.messages.muted); }, unmute: function () { mute = false; + return post('info', templates.messages.unmuted); + }, + + title: function (payload) { + win.setTitle(payload); + return post('info', $.template(templates.messages.title_set, { title: payload})); }, join: function (payload) { diff --git a/public/js/cryptalk_modules/notifications.js b/public/js/cryptalk_modules/notifications.js index 007f9d2..3125bc0 100644 --- a/public/js/cryptalk_modules/notifications.js +++ b/public/js/cryptalk_modules/notifications.js @@ -15,7 +15,7 @@ Usage channel.emit('notification:off'); */ -define(['mediator','window'],function (mediator,win){ +define(['mediator','win'],function (mediator,win){ var enabled = true, @@ -111,7 +111,7 @@ define(['mediator','window'],function (mediator,win){ enableNative(); off(); - + // Make sure we are at square one resetState(); diff --git a/public/js/cryptalk_modules/templates.js b/public/js/cryptalk_modules/templates.js index a134991..dba77a6 100644 --- a/public/js/cryptalk_modules/templates.js +++ b/public/js/cryptalk_modules/templates.js @@ -23,22 +23,30 @@ define({ ' \n' + '---------------------------------------------------------------------- \n' + ' \n' + - 'Available commands: \n' + - ' /generate Generate random room \n' + - ' /join RoomId Join a room \n' + - ' /count Count participants of room \n' + + 'Client: \n' + + ' /key StrongPassphrase Sets encryption key \n' + ' /nick NickName Sets an optional nick \n' + - ' /mute Toggle notification sounds \n' + - ' /key OurStrongPassphrase Sets encryption key \n' + - ' /leave Leave the room \n' + + ' /mute Audio on \n' + + ' /unmute Audio off \n' + ' /clear Clear on-screen buffer \n' + ' /help This \n' + + ' /title Set your local page title \n' + ' \n' + + 'Room: \n' + + ' /generate Generate random room \n' + + ' /join RoomId Join a room \n' + + ' /leave Leave the room \n' + + ' /count Count participants \n' + + ' \n' + + 'Host: \n' + + ' /hosts List available hosts \n' + + ' /connect HostIndex Connect to selected host \n' + + ' /disconnect Disconnect from host \n' + ' \n' + 'You can select any of the five last commands/messages with up/down key.\n' + ' \n' + 'Due to security reasons, /key command is not saved, and command \n' + - 'history is automatically cleared after one minute of inactivity. \n' + + 'history is automatically cleared after one minute of inactivity. \n' + ' \n' + 'It is highly recommended to use incognito mode while chatting, \n' + 'to prevent browsers from keeping history or cache. \n' + @@ -78,11 +86,11 @@ define({ msg_no_key: 'You have to set an encryption key before sending a message. See /help.', leave_from_nowhere: 'How are you supposed to leave, while being nowhere?', - // Sounds + title_set: 'The title of this window is now \'{title}\'.', + muted: 'Notifications and sounds are now muted.', unmuted: 'Notifications and sounds are now on.', - // Extra variables: 'commandName' unrecognized_command: 'Unrecognized command: "{commandName}"', joined_room: 'Joined room {room}', diff --git a/public/js/cryptalk_modules/win.js b/public/js/cryptalk_modules/win.js new file mode 100644 index 0000000..e787675 --- /dev/null +++ b/public/js/cryptalk_modules/win.js @@ -0,0 +1,41 @@ +/* + + Emits: + 'window:focused' + 'window:blurred' + + Exports: + title = window.getTitle(); + window.setTitle(title); + +*/ +define(['mediator'],function (mediator){ + + var exports = {}, + channel = mediator(), + + focusCallback = function() { + channel.emit('window:focused'); + }, + + blurCallback = function() { + channel.emit('window:blurred'); + }; + + exports.setTitle = function(t) { document.title = t; }, + exports.getTitle = function() { return document.title; }; + + // Keep track of document focus/blur + if (window.addEventListener){ + // Normal browsers + window.addEventListener("focus", focusCallback, true); + window.addEventListener("blur", blurCallback, true); + } else { + // IE + window.observe("focusin", focusCallback); + window.observe("focusout", blurCallback); + } + + return exports; + +}); \ No newline at end of file