1 import {Socket} from 'socket.io-client';
2 import {Message} from '../shared/message';
4 // disable chat temporarily to test widgetbot
6 function $<T>(selector: string, root: any = document): T {
7 return root.querySelector(selector) as T;
10 function $$<T>(selector: string, root: any = document): T[] {
11 return Array.from(root.querySelectorAll(selector)) as T[];
14 function renderChatMessage(msg: Message) {
15 $<HTMLElement>('#chat-messages').innerHTML += `<div class="chat-message" title="${new Date(parseInt(msg.sentAt))}" id="${msg.id}">
16 <span class="from">${msg.from}</span>
17 <span class="message">${msg.msg}</span>
19 $<HTMLElement>('#chat-messages').scrollTop = $<HTMLElement>('#chat-messages').scrollHeight;
22 function configureStandardChat() {
23 socket.on('chat', renderChatMessage);
26 export function configureChat(_socket: Socket) {
27 // disable chat temporarily to test discord chat
30 configureStandardChat();
32 console.log('Chat Configured');