From 540e7a13de09b08d101f739adce352e9a1cf2c5d Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Fri, 25 Mar 2016 05:18:46 +0100 Subject: Multiple channels sending and receiving. Help I'm tired --- index.html | 28 +++++++++++++++-------- index.js | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- package.json | 11 +++++---- 3 files changed, 88 insertions(+), 26 deletions(-) diff --git a/index.html b/index.html index 461856b..081ea9e 100644 --- a/index.html +++ b/index.html @@ -1,17 +1,25 @@ - + - -
- Hello world
+ +
+ +
- - - +
+
+ +
+
+ + + + diff --git a/index.js b/index.js index e5d3b0c..c3db74d 100644 --- a/index.js +++ b/index.js @@ -1,22 +1,75 @@ +$(document).ready(function(){ +}); -$("#submitb").click(function() { - sendMsg(); +$("#send-message").keypress(function(e) { + if(e.which == 13) { + var channel = $(".tab.chat.active").attr("data-tab").replace("chan-", "#") + sendMsg($("#send-message").val(), channel) + $("#send-message").val(''); + } }); +function sendMsg(message, channel) { + console.log(channel + ': ' + message); + client.say(channel, message); + var chanTab = $("[data-tab=chan-"+ channel.replace("#","") +"].chat"); + chanTab.append("

<" + "wclient" + "> " + message +"

"); + chanTab.scrollTop(chanTab.prop("scrollHeight")); +} + +function joinChannel(channel) { + client.join(channel); + channel = channel.replace("#",""); + + $(".active").removeClass("active"); + $(".ui.menu").append("#"+channel+""); + + + $("#chan-container").append("
") + $('.menu .item').tab({history:false}); + var chanTab = $("[data-tab=chan-"+ channel +"].chat"); + client.addListener('message#'+channel, function (from, message) { + console.log(from + ' => #'+ channel +': ' + message); + console.log(chanTab); + chanTab.append("

<" + from + "> " + message +"

"); + chanTab.scrollTop(chanTab.prop("scrollHeight")); + }); +} + + const irc = require('irc'); +var channels = ["#wtest", "#wtest2"] const client = new irc.Client('irc.blatech.net', 'wclient', { - channels: ['#wtest'], + channels: channels, userName: ['wclient'] }); -function sendMsg() { - console.log('#wtest: ' + $("#send-message").val()); - client.say("#wtest", $("#send-message").val()); -} - +client.addListener('error', function(message) { + console.log('error: ', message); +}); -client.addListener('message#wtest', function (from, message) { - console.log(from + ' => #wtest: ' + message); - $("#chat").append(from + ' : ' + message + "
"); +client.addListener('registered', function() { + channels.forEach(function(channel) { + joinChannel(channel); + }); }); + + + +// client.addListener('message#wtest', function (from, message) { +// console.log(from + ' => #wtest: ' + message); +// var chanTab = $("[data-tab=chan-wtest].chat"); +// chanTab.append("

<" + from + "> " + message +"

"); +// chanTab.scrollTop(chanTab.prop("scrollHeight")); +// }); +// +// client.addListener('message#jerseyesports', function (from, message) { +// console.log(from + ' => #jerseyesports: ' + message); +// $("[data-tab=chan-jerseyesports].chat").append("

<" + from + "> " + message +"

"); +// }); + +// client.addListener('message#theblueroom', function (from, message) { +// console.log(from + ' => #jerseyesports: ' + message); +// $("[data-tab=chan-theblueroom].chat").append("

<" + from + "> " + message +"

"); +// }); diff --git a/package.json b/package.json index 0ae8985..d3b46e5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { - "name" : "blachat", - "version" : "0.1.0", - "main" : "main.js" + "name": "blachat", + "version": "0.1.0", + "main": "main.js", + "dependencies": { + "semantic-ui": "^2.1.8" + } } - - -- cgit v1.2.3