3 input#inputChat(type="text" :placeholder="st.tr['Type here']"
4 @keyup.enter="sendChat")
5 button#sendChatBtn(@click="sendChat") {{ st.tr["Send"] }}
6 p(v-for="chat in chats" :class="classObject(chat)"
7 v-html="chat.name + ': ' + chat.msg")
8 p(v-for="chat in pastChats" :class="classObject(chat)"
9 v-html="chat.name + ': ' + chat.msg")
13 import { store } from "@/store";
17 // Prop 'pastChats' for corr games where chats are on server
18 props: ["players","pastChats"],
22 chats: [], //chat messages after human game
26 const curMsgListener = this.st.conn.onmessage; //from Game or Hall
27 const socketMessageListener = msg => {
29 const data = JSON.parse(msg.data);
30 if (data.code == "newchat") //only event at this level
32 this.chats.unshift({msg:data.msg, name:data.name || "@nonymous"});
33 this.$emit("newchat-received"); //data not required here
36 const socketCloseListener = () => {
37 store.socketCloseListener(); //reinitialize connexion (in store.js)
38 this.st.conn.addEventListener('message', socketMessageListener);
39 this.st.conn.addEventListener('close', socketCloseListener);
41 this.st.conn.onmessage = socketMessageListener;
42 this.st.conn.onclose = socketCloseListener;
45 classObject: function(chat) {
47 "my-chatmsg": chat.name == this.st.user.name,
48 "opp-chatmsg": this.players.some(
49 p => p.name == chat.name && p.name != this.st.user.name)
52 sendChat: function() {
53 let chatInput = document.getElementById("inputChat");
54 const chatTxt = chatInput.value.trim();
56 return; //nothing to send
58 const chat = {msg:chatTxt, name: this.st.user.name || "@nonymous"};
59 this.$emit("newchat-sent", chat); //useful for corr games
60 this.chats.unshift(chat);
61 this.st.conn.send(JSON.stringify({
62 code:"newchat", msg:chatTxt, name:chat.name}));
68 <style lang="sass" scoped>