- chats: [], //chat messages after human game
- };
- },
- created: function() {
- const curMsgListener = this.st.conn.onmessage; //from Game or Hall
- const socketMessageListener = msg => {
- curMsgListener(msg);
- const data = JSON.parse(msg.data);
- if (data.code == "newchat") //only event at this level
- {
- this.chats.unshift({msg:data.msg,
- name:data.name || "@nonymous", sid:data.from});
- this.$emit("newchat-received"); //data not required here
- }
- };
- const socketCloseListener = () => {
- store.socketCloseListener(); //reinitialize connexion (in store.js)
- this.st.conn.addEventListener('message', socketMessageListener);
- this.st.conn.addEventListener('close', socketCloseListener);