From 721b4fb1b32ee47f158fb3b9a1ad0747ff579044 Mon Sep 17 00:00:00 2001 From: lassulus Date: Tue, 12 Nov 2013 02:59:28 +0100 Subject: webchat: remove input parser --- webchat/public/client.js | 100 ++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 48 deletions(-) (limited to 'webchat/public/client.js') 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 = $('
').text(params.msg).html(); + safe_message = replaceURLWithHTMLLinks(safe_message); + var safe_from = $('
').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 = $('
').text(params.oldnick).html(); + var safe_newnick = $('
').text(params.newnick).html(); + var safe_type = $('
').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('
' + safe_newnick + '
') ; + 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 = $('
').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 = $('
').text(params.nick).html(); + var safe_type = $('
').text(params.type).html(); + $('#nicklist').append('
' + safe_nick + '
') ; + chatboxAppend(safe_nick, 'has joined'); + return callback(null) +}) +rpc.register('part', {type: 'string', nick: 'string'}, function(params, callback) { + var safe_nick = $('
').text(params.nick).html(); + var safe_type = $('
').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 = $('
').text(params.msg).html(); - safe_message = replaceURLWithHTMLLinks(safe_message); - var safe_from = $('
').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 = $('
').text(params.oldnick).html(); - var safe_newnick = $('
').text(params.newnick).html(); - var safe_type = $('
').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('
' + safe_newnick + '
') ; - 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 = $('
').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 = $('
').text(params.nick).html(); - var safe_type = $('
').text(params.type).html(); - $('#nicklist').append('
' + safe_nick + '
') ; - chatboxAppend(safe_nick, 'has joined'); - return callback(null) - }) - rpc.register('part', {type: 'string', nick: 'string'}, function(params, callback) { - var safe_nick = $('
').text(params.nick).html(); - var safe_type = $('
').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) + } } }); -- cgit v1.2.3