From 7f222f547283b03a6e53ef69b228abf11e46e5c8 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 30 Dec 2013 03:10:21 +0100 Subject: webchat -> Cancher --- Cancer/webchat/public/client.js | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Cancer/webchat/public/client.js (limited to 'Cancer/webchat/public/client.js') diff --git a/Cancer/webchat/public/client.js b/Cancer/webchat/public/client.js new file mode 100644 index 00000000..54ccfe34 --- /dev/null +++ b/Cancer/webchat/public/client.js @@ -0,0 +1,70 @@ +var settings = {} +settings.sock = new SockJS('/echo'); +settings.waiting_callbacks = {} + +var transport = make_sockjs_client_transport(settings.sock) +settings.rpc = new RPC(transport) + +settings.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) +}) +settings.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) +}) +settings.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) +}) +settings.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) +}) +settings.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()); + setTimeout(updateTime,'1000'); + return true; +}); + + +$(function() { + $('#input').keydown(function(e) { + if (e.keyCode === 13) { + e.preventDefault(); + e.stopPropagation(); + e.stopImmediatePropagation(); + var input = ($('#input').val()); + $('#input').val('') + + var command = inputParser(input) + return (commands[command.method] || commands.badcommand)(settings, command.params) + } + }); + +}); -- cgit v1.2.3