ladymalie
ladymalie

Reputation: 168

Emitting events to self on the client for socket.io-client

In the old versions of Socket.IO (version <1.0), the namespace of the socket.io-client includes the $emit function to its prototype. I am yet to understand this properly but with this, events from the client can be emitted to the same client locally.

However, in the latest version of Socket.IO, an emit function is not accessible outside of the Socket module.

The question is: is there still a way to emit an event from the client to itself?

Upvotes: 0

Views: 1337

Answers (1)

jfriend00
jfriend00

Reputation: 708026

I will make my comment into an answer since it appears to have helped you solve the issue.

If you want access to the original .emit() method, you can get it from EventEmitter.prototype.emit() and use .call() to call it on the appropriate object that has appropriate event handlers on it.

EventEmitter.prototype.emit.call(someObj, "myMsg", mydata);

Upvotes: 1

Related Questions