5 p(v-for="chat in chats" :class="classObject(chat)" v-html="chat.msg")
6 input#inputChat(type="text" :placeholder="st.tr['Type here']"
7 @keyup.enter="sendChat")
8 button#sendChatBtn(@click="sendChat") {{ st.tr["Send"] }}
12 import { store } from "@/store";
20 chats: [], //chat messages after human game
24 const curMsgListener = this.st.conn.onmessage; //from Game or Hall
25 const socketMessageListener = msg => {
27 const data = JSON.parse(msg.data);
28 if (data.code == "newchat") //only event at this level
30 this.chats.push({msg:data.msg,
31 name:data.name || "@nonymous", sid:data.from});
34 const socketCloseListener = () => {
35 store.socketCloseListener(); //reinitialize connexion (in store.js)
36 this.st.conn.addEventListener('message', socketMessageListener);
37 this.st.conn.addEventListener('close', socketCloseListener);
39 this.st.conn.onmessage = socketMessageListener;
40 this.st.conn.onclose = socketCloseListener;
43 classObject: function(chat) {
45 "my-chatmsg": chat.sid == this.st.user.sid,
46 "opp-chatmsg": this.players.some(
47 p => p.sid == chat.sid && p.sid != this.st.user.sid)
50 sendChat: function() {
51 let chatInput = document.getElementById("inputChat");
52 const chatTxt = chatInput.value;
54 const chat = {msg:chatTxt, name: this.st.user.name || "@nonymous",
55 sid:this.st.user.sid};
56 this.chats.push(chat);
57 this.st.conn.send(JSON.stringify({
58 code:"newchat", msg:chatTxt, name:chat.name}));