From 2afbcf4e7d000d99fdbc582d7113684ee00e80cc Mon Sep 17 00:00:00 2001 From: yo mama Date: Fri, 20 Mar 2015 17:33:43 -0700 Subject: first --- public/javascripts/client.js | 249 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 public/javascripts/client.js (limited to 'public/javascripts/client.js') diff --git a/public/javascripts/client.js b/public/javascripts/client.js new file mode 100644 index 0000000..793ae89 --- /dev/null +++ b/public/javascripts/client.js @@ -0,0 +1,249 @@ +var webcam_videos = []; +var chat_users = []; +var webcam_width = 130; +var webcam_height = 90; +var peerConnection; +var websocketChat = { + send: function (message) { + rtc._socket.send(message); + }, + recv: function (message) { + return message; + }, + event: 'receive_chat_msg' +}; +var dataChannelChat = { + broadcast: function(message) { + for(var connection in rtc.dataChannels) { + var channel = rtc.dataChannels[connection]; + if (rtc.connection_ok_to_send[connection]) { + channel.send(message); + } else { + console.log("unable to send message to " + connection); + } + } + }, + send: function(connection, message) { + var channel = rtc.dataChannels[connection]; + if (rtc.connection_ok_to_send[connection]) { + channel.send(message); + } else { + console.log("unable to send message to " + connection); + } + }, + recv: function(channel, message) { + return JSON.parse(message).data; + }, + event: 'data stream data' +}; + +var ppChat = { + init:function(){ + $('#chat-wrapper').window('open'); + }, + addmsg_to_board : function(username, msg, color) { + var messages = $('#msgboard'); + msg = ppChat.sanitize(msg); + if(color) { + msg = '' + username + ' : ' + '' + msg + ''; + } else { + msg = '' + username + ' : ' + '' + msg + ''; + } + messages.html(messages.html() + msg + '
'); + messages.scrollTop(10000); + }, + dispsystemmessage : function(msg) { + var messages = $('#msgboard'); + msg = ppChat.sanitize(msg); + msg = '' + msg + ''; + messages.html(messages.html() + msg + '
'); + messages.scrollTop(10000); + }, + sanitize : function(msg) { + /* this isn't actual security, just avoids accidential html input */ + return msg.replace(/