3 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
4 // TODO: Chat modal sur petit écran, dans la page pour grand écran
7 p(v-for="chat in chats" :class="classObject(chat)" v-html="chat.msg")
8 input#inputChat(type="text" :placeholder="st.tr['Type here']"
9 @keyup.enter="sendChat")
10 button#sendChatBtn(@click="sendChat") {{ st.tr["Send"] }}
14 import { store } from "@/store";
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.push({msg:data.msg,
33 name:data.name || "@nonymous", sid:data.from});
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.sid == this.st.user.sid,
48 "opp-chatmsg": this.players.some(
49 p => p.sid == chat.sid && p.sid != this.st.user.sid)
52 sendChat: function() {
53 let chatInput = document.getElementById("inputChat");
54 const chatTxt = chatInput.value;
56 const chat = {msg:chatTxt, name: this.st.user.name || "@nonymous",
57 sid:this.st.user.sid};
58 this.chats.push(chat);
59 this.st.conn.send(JSON.stringify({
60 code:"newchat", msg:chatTxt, name:chat.name}));