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)" v-html="chat.msg")
10 import { store } from "@/store";
18 chats: [], //chat messages after human game
22 const curMsgListener = this.st.conn.onmessage; //from Game or Hall
23 const socketMessageListener = msg => {
25 const data = JSON.parse(msg.data);
26 if (data.code == "newchat") //only event at this level
28 this.chats.unshift({msg:data.msg,
29 name:data.name || "@nonymous", sid:data.from});
32 const socketCloseListener = () => {
33 store.socketCloseListener(); //reinitialize connexion (in store.js)
34 this.st.conn.addEventListener('message', socketMessageListener);
35 this.st.conn.addEventListener('close', socketCloseListener);
37 this.st.conn.onmessage = socketMessageListener;
38 this.st.conn.onclose = socketCloseListener;
41 classObject: function(chat) {
43 "my-chatmsg": chat.sid == this.st.user.sid,
44 "opp-chatmsg": this.players.some(
45 p => p.sid == chat.sid && p.sid != this.st.user.sid)
48 sendChat: function() {
49 let chatInput = document.getElementById("inputChat");
50 const chatTxt = chatInput.value;
52 const chat = {msg:chatTxt, name: this.st.user.name || "@nonymous",
53 sid:this.st.user.sid};
54 this.$emit("newchat", chat); //useful for corr games
55 this.chats.unshift(chat);
56 this.st.conn.send(JSON.stringify({
57 code:"newchat", msg:chatTxt, name:chat.name}));
63 <style lang="sass" scoped>