summaryrefslogtreecommitdiffstats
path: root/webchat/public
diff options
context:
space:
mode:
authorlassulus <lassulus@googlemail.com>2013-11-12 02:59:28 +0100
committerlassulus <lassulus@googlemail.com>2013-11-12 02:59:28 +0100
commit721b4fb1b32ee47f158fb3b9a1ad0747ff579044 (patch)
tree8ba76f01ae92a1439df5607517313e20cda5d2dc /webchat/public
parenta170673b55215137b5e7fe19e587767c2ef57453 (diff)
webchat: remove input parser
Diffstat (limited to 'webchat/public')
-rw-r--r--webchat/public/client.js100
-rw-r--r--webchat/public/commands.js24
-rw-r--r--webchat/public/functions.js8
-rw-r--r--webchat/public/sockjs_client_transport.js2
4 files changed, 52 insertions, 82 deletions
diff --git a/webchat/public/client.js b/webchat/public/client.js
index 58002f78..d7a5ecab 100644
--- a/webchat/public/client.js
+++ b/webchat/public/client.js
@@ -1,4 +1,50 @@
var settings = {}
+settings.sock = new SockJS('/echo');
+settings.waiting_callbacks = {}
+
+var transport = make_sockjs_client_transport(settings.sock)
+var rpc = new RPC(transport)
+
+rpc.register('msg', {type: 'string', nick: 'string', msg: 'string'}, function(params, callback) {
+ var safe_message = $('<div/>').text(params.msg).html();
+ safe_message = replaceURLWithHTMLLinks(safe_message);
+ var safe_from = $('<div/>').text(params.nick).html();
+ chatboxAppend(safe_from, safe_message, 'web_msg')
+ return callback(null)
+})
+rpc.register('nick', {type: 'string', newnick: 'string', oldnick: 'string'}, function(params, callback) {
+ var safe_oldnick = $('<div/>').text(params.oldnick).html();
+ var safe_newnick = $('<div/>').text(params.newnick).html();
+ var safe_type = $('<div/>').text(params.type).html();
+ if (safe_oldnick === settings.nick){
+ settings.nick = safe_newnick
+ $('#nick').html(settings.nick)
+ }
+ $(getNicklistElement(safe_oldnick,safe_type)).remove();
+ $('#nicklist').append('<div class="'+safe_type+'_name">' + safe_newnick + '</div>') ;
+ chatboxAppend(safe_oldnick, 'is now known as ' + safe_newnick, 'nick');
+ return callback(null)
+})
+rpc.register('your_nick', {nick: 'string'}, function(params, callback) {
+ var safe_nick = $('<div/>').text(params.nick).html();
+ settings.nick = safe_nick
+ $('#nick').html(settings.nick)
+ return callback(null)
+})
+rpc.register('join', {type: 'string', nick: 'string'}, function(params, callback) {
+ var safe_nick = $('<div/>').text(params.nick).html();
+ var safe_type = $('<div/>').text(params.type).html();
+ $('#nicklist').append('<div class="'+safe_type+'_name">' + safe_nick + '</div>') ;
+ chatboxAppend(safe_nick, 'has joined');
+ return callback(null)
+})
+rpc.register('part', {type: 'string', nick: 'string'}, function(params, callback) {
+ var safe_nick = $('<div/>').text(params.nick).html();
+ var safe_type = $('<div/>').text(params.type).html();
+ $(getNicklistElement(safe_nick,safe_type)).remove();
+ chatboxAppend(safe_nick, 'has parted');
+ return callback(null)
+})
$(function updateTime () {
$('#time').html(getCurTime());
@@ -6,53 +52,7 @@ $(function updateTime () {
return true;
});
-settings.waiting_callbacks = {}
-$(function connect() {
- settings.sock = new SockJS('/echo');
- var transport = make_sockjs_client_transport(settings.sock)
- var rpc = new RPC(transport)
- rpc.register('msg', {type: 'string', nick: 'string', msg: 'string'}, function(params, callback) {
- var safe_message = $('<div/>').text(params.msg).html();
- safe_message = replaceURLWithHTMLLinks(safe_message);
- var safe_from = $('<div/>').text(params.nick).html();
- chatboxAppend(safe_from, safe_message, 'web_msg')
- return callback(null)
- })
- rpc.register('nick', {type: 'string', newnick: 'string', oldnick: 'string'}, function(params, callback) {
- var safe_oldnick = $('<div/>').text(params.oldnick).html();
- var safe_newnick = $('<div/>').text(params.newnick).html();
- var safe_type = $('<div/>').text(params.type).html();
- if (safe_oldnick === settings.nick){
- settings.nick = safe_newnick
- $('#nick').html(settings.nick)
- }
- $(getNicklistElement(safe_oldnick,safe_type)).remove();
- $('#nicklist').append('<div class="'+safe_type+'_name">' + safe_newnick + '</div>') ;
- chatboxAppend(safe_oldnick, 'is now known as ' + safe_newnick, 'nick');
- return callback(null)
- })
- rpc.register('your_nick', {nick: 'string'}, function(params, callback) {
- var safe_nick = $('<div/>').text(params.nick).html();
- settings.nick = safe_nick
- $('#nick').html(settings.nick)
- return callback(null)
- })
- rpc.register('join', {type: 'string', nick: 'string'}, function(params, callback) {
- var safe_nick = $('<div/>').text(params.nick).html();
- var safe_type = $('<div/>').text(params.type).html();
- $('#nicklist').append('<div class="'+safe_type+'_name">' + safe_nick + '</div>') ;
- chatboxAppend(safe_nick, 'has joined');
- return callback(null)
- })
- rpc.register('part', {type: 'string', nick: 'string'}, function(params, callback) {
- var safe_nick = $('<div/>').text(params.nick).html();
- var safe_type = $('<div/>').text(params.type).html();
- $(getNicklistElement(safe_nick,safe_type)).remove();
- chatboxAppend(safe_nick, 'has parted');
- return callback(null)
- })
-});
$(function() {
$('#input').keydown(function(e) {
if (e.keyCode === 13) {
@@ -62,8 +62,12 @@ $(function() {
var input = ($('#input').val());
$('#input').val('');
- var command = inputParser(input)
- return (commands[command.method] || commands.badcommand)(settings, command.params)
+ var match = /^\/([a-z]+)(?:\s+(.*\S))?\s*$/.exec(input)
+ if (match) {
+ return rpc.send(match[1], match[2])
+ } else {
+ return rpc.send('msg', input)
+ }
}
});
diff --git a/webchat/public/commands.js b/webchat/public/commands.js
deleted file mode 100644
index f19c78dc..00000000
--- a/webchat/public/commands.js
+++ /dev/null
@@ -1,24 +0,0 @@
-var commands = {}
-
-commands.msg = function (settings, params) {
- var sendObj = {
- method: 'msg',
- params: { msg: params }
- }
- settings.sock.send(JSON.stringify(sendObj))
-}
-
-commands.nick = function (settings, params) {
- var sendObj = {
- method: 'nick',
- params: { nick: params },
- }
- settings.sock.send(JSON.stringify(sendObj))
-}
-
-commands.badcommand = function (settings, params) {
- console.log("error", params);
- chatboxAppend( '<span class="from_system">error</span>', 'command not found' )
-
-
-}
diff --git a/webchat/public/functions.js b/webchat/public/functions.js
index 781fafce..318d0865 100644
--- a/webchat/public/functions.js
+++ b/webchat/public/functions.js
@@ -1,11 +1,3 @@
-function inputParser (str) {
- var match = /^\/([a-z]+)(?:\s+(.*\S))?\s*$/.exec(str)
- if (match) {
- return { method: match[1], params: match[2] }
- } else {
- return { method: 'msg', params: str }
- }
-}
function replaceURLWithHTMLLinks (text) {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
diff --git a/webchat/public/sockjs_client_transport.js b/webchat/public/sockjs_client_transport.js
index 4e525d0d..a7b76af3 100644
--- a/webchat/public/sockjs_client_transport.js
+++ b/webchat/public/sockjs_client_transport.js
@@ -23,5 +23,3 @@ function make_sockjs_client_transport (sock) {
return transport
}
-
-