diff --git a/data/index.html b/data/index.html index 34223a0..e0578da 100644 --- a/data/index.html +++ b/data/index.html @@ -73,8 +73,10 @@

NeoPixel

-

MQTT

-
+ +

IRC

+
diff --git a/data/script.js b/data/script.js index d7dcdb0..b2f0c68 100644 --- a/data/script.js +++ b/data/script.js @@ -12268,8 +12268,11 @@ class Chat extends __WEBPACK_IMPORTED_MODULE_2__core_Component__["a" /* default super(ctx, node, template || __WEBPACK_IMPORTED_MODULE_1__Chat_html___default.a); this.render(this.config); this.ctx.mediator.on(this.config.topic, this.onMessage.bind(this)); + this.ctx.mediator.on("chat/connected", this.connected.bind(this)); + //this.ctx.mediator.on("irc/configValid", this.configValid.bind(this)); this.node.delegate('input.msg', 'keypress', this.onInput.bind(this)); - this.node.delegate('button', 'click', this.send.bind(this)); + this.node.delegate('button.send', 'click', this.send.bind(this)); + this.node.delegate('button.join', 'click', this.join.bind(this)); } templates() { @@ -12279,17 +12282,43 @@ class Chat extends __WEBPACK_IMPORTED_MODULE_2__core_Component__["a" /* default ${user} ${msg} + `, + serverMessage: (msg) => ` +
  • + ${msg} +
  • ` }; } + configValid() { + this.node.text("Please configure first"); + } + + join(evt) { + evt.preventDefault(); + let message = JSON.stringify({ + topic: 'irc/join', + payload: this.sanitizeInput(this.node.find('.channel').val()) + }); + this.ctx.ws.send(message); + this.node.find('.controls').show(); + //this.node.find('button.join').hide(); + } + connected() { + this.node.find('.controls').show(); + this.node.find('button.connect').hide(); + } + onMessage(msg) { let payload = msg.payload; //.replace(/<.+?>/g, ''); //console.log('onMsg: ' + msg); let msgParts = payload.split(':'); let messages = this.node.find('.messages'); messages.append( - this.templates().message(msgParts[0], msgParts[1] ? msgParts[1] : '') + msgParts.length == 2 ? + this.templates().message(msgParts[0], this.sanitizeInput(msgParts[1])) + : this.templates().serverMessage(this.sanitizeInput(payload)) ); this.node.find('.message-container').animate({ scrollTop: messages[0].scrollHeight @@ -12300,12 +12329,11 @@ class Chat extends __WEBPACK_IMPORTED_MODULE_2__core_Component__["a" /* default } send(evt) { evt.preventDefault(); - let username = this.node.find('input.username'); let msg = this.node.find('input.msg'); - if (username.length > 0 && message.length > 0) { + if (msg.length > 0) { let message = JSON.stringify({ topic: this.sanitizeInput(this.config.topic), - payload: this.sanitizeInput(username.val() + ':' + msg.val()) + payload: this.sanitizeInput(msg.val()) }); this.ctx.ws.send(message); msg.val(''); @@ -12325,7 +12353,7 @@ class Chat extends __WEBPACK_IMPORTED_MODULE_2__core_Component__["a" /* default /* 31 */ /***/ (function(module, exports) { -module.exports = "
    \n \n
    \n
      \n
      \n \n \n
      " +module.exports = "
      \n \n
      \n
        \n
        \n \n
        " /***/ }) /******/ ]); \ No newline at end of file diff --git a/src/app/components/Chat/Chat.html b/src/app/components/Chat/Chat.html index 916219b..34225ba 100644 --- a/src/app/components/Chat/Chat.html +++ b/src/app/components/Chat/Chat.html @@ -1,18 +1,20 @@
          -
          \ No newline at end of file diff --git a/src/app/components/Chat/Chat.js b/src/app/components/Chat/Chat.js index 2456736..eb2e97e 100644 --- a/src/app/components/Chat/Chat.js +++ b/src/app/components/Chat/Chat.js @@ -8,8 +8,11 @@ export default class Chat extends Component { super(ctx, node, template || markup); this.render(this.config); this.ctx.mediator.on(this.config.topic, this.onMessage.bind(this)); + this.ctx.mediator.on("chat/connected", this.connected.bind(this)); + //this.ctx.mediator.on("irc/configValid", this.configValid.bind(this)); this.node.delegate('input.msg', 'keypress', this.onInput.bind(this)); - this.node.delegate('button', 'click', this.send.bind(this)); + this.node.delegate('button.send', 'click', this.send.bind(this)); + this.node.delegate('button.join', 'click', this.join.bind(this)); } templates() { @@ -19,17 +22,43 @@ export default class Chat extends Component { ${user} ${msg} + `, + serverMessage: (msg) => ` +
        • + ${msg} +
        • ` }; } + configValid() { + this.node.text("Please configure first"); + } + + join(evt) { + evt.preventDefault(); + let message = JSON.stringify({ + topic: 'irc/join', + payload: this.sanitizeInput(this.node.find('.channel').val()) + }); + this.ctx.ws.send(message); + this.node.find('.controls').show(); + //this.node.find('button.join').hide(); + } + connected() { + this.node.find('.controls').show(); + this.node.find('button.connect').hide(); + } + onMessage(msg) { let payload = msg.payload; //.replace(/<.+?>/g, ''); //console.log('onMsg: ' + msg); let msgParts = payload.split(':'); let messages = this.node.find('.messages'); messages.append( - this.templates().message(msgParts[0], msgParts[1] ? msgParts[1] : '') + msgParts.length == 2 ? + this.templates().message(msgParts[0], this.sanitizeInput(msgParts[1])) + : this.templates().serverMessage(this.sanitizeInput(payload)) ); this.node.find('.message-container').animate({ scrollTop: messages[0].scrollHeight @@ -40,12 +69,11 @@ export default class Chat extends Component { } send(evt) { evt.preventDefault(); - let username = this.node.find('input.username'); let msg = this.node.find('input.msg'); - if (username.length > 0 && message.length > 0) { + if (msg.length > 0) { let message = JSON.stringify({ topic: this.sanitizeInput(this.config.topic), - payload: this.sanitizeInput(username.val() + ':' + msg.val()) + payload: this.sanitizeInput(msg.val()) }); this.ctx.ws.send(message); msg.val(''); diff --git a/src/pages/index.html b/src/pages/index.html index 34223a0..e0578da 100644 --- a/src/pages/index.html +++ b/src/pages/index.html @@ -73,8 +73,10 @@

          NeoPixel

          -

          MQTT

          -
          + +

          IRC

          +