- 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"});
- 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);
- };
- this.st.conn.onmessage = socketMessageListener;
- this.st.conn.onclose = socketCloseListener;
+ watch: {
+ newChat: function(chat) {
+ if (chat.msg != "")
+ this.chats.unshift({msg:chat.msg, name:chat.name || "@nonymous"});
+ },