title: socket.io getting error message while using broadcast
body: <p>actually am trying to create chat app using vueJS and socket.io  so here is what i have done so far</p>
  <pre><code>&lt;script&gt;
      import {io} from &quot;socket.io-client&quot;;
      export default {
          data() {
              return {
                  socketInstance: io(&quot;http://localhost:3001&quot;),
              };
          },
          methods: {
            async handleSendMessage(message) {
              const postParams = {
                  ip: this.userData.ip,
                  message: message,
                  user_type: &quot;customer&quot;,
              };
              const {data} = await axios.post(
                  &quot;http://localhost:3001/api/message&quot;,
                  postParams
              );
              this.messages.push(data.message);
              this.socketInstance.broadcast.emit(&quot;new_message&quot;, {
                  message: data.message,
                  socket_id: this.socketInstance.id,
              });
               //HERE AM GETTING ERROR WHILE USING BROADCAST
          }
  },
          
          mounted() {
              this.socketInstance.on(&quot;new_message&quot;, ({message, socket_id}) =&gt; {
                  if (message.ip == this.userData.ip) {
                      this.messages.push(message);
                  }
              });
          },
      };
  &lt;/script&gt;
  </code></pre>
  <p>Basically <strong>handleSendMessage</strong> function is responsible for sending message and emit an event but when I do</p>
  <pre><code>this.socketInstance.emit(&quot;new_message&quot;, {
    message: data.message,
    socket_id: this.socketInstance.id,
   });
  </code></pre>
  <p>then it's works fine but as you know i will get duplicate messages so i used</p>
  <pre><code>this.socketInstance.broadcast.emit(&quot;new_message&quot;, {
    message: data.message,
    socket_id: this.socketInstance.id,
   });
  </code></pre>
  <p>and got following error</p>
  <pre><code>Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'emit')
  </code></pre>
  <p>I don't know why am getting this error.
  Sorry for my bad English.</p>