Closed omdxp closed 2 years ago
Hi Omar,
The EmitTo method requires the UUID string of a specific client as a first parameter. From what I can see there you are sending the message to "orders" that is not a UUID
Store the UUID of the specific client in a list, and then use EmitTo with that UUID
I see also that you're listening for the "orders" event in the client, and this will not happen. Ikisocket allow you to handle your events at server level, not on the client level. This means that your
ws.on("orders") will not work, because orders is not a client event
Hope this will help
Hey @antoniodipinto thanks for the clarification, I thought that EmitTo
is meant to send to data to custom event.
In that case is there any way to send data on custom event?
One idea that comes to my mind is to do it here:
ws.on("message", (data) => {
console.log("message received". data);
data = Buffer.from(data).toString();
console.log(data);
});
app.Post("/orders", func(c *fiber.Ctx) error {
ikisocket.Emit(c.Body(), ikisocket.TextMessage)
return c.SendString("orders")
})
If you want to add more possibilities, you can send back to the client an JSON object like this:
{
"event":"<event_name_here>",
"data":"<your_data_here>"
}
So then you can check which kind of event you have
Yeah seems doable, I hope you can add this functionality to emit to specific events. Kinda like socketio
@Omar-Belghaouti from what I know you can do that in Socket.io only if you use the socket.io client https://github.com/socketio/socket.io-client not the standard WS class in JS. Right not I'm not thinking of developing also a client version for ikisocket, but maybe in the future, who knows :)
Thank you for your feedback! I'll close this issue
Describe the bug It seems only
Broadcast()
andEmit()
are working but only forikisocket.EventMessage
. But when usingEmitTo()
there is nothing.To Reproduce Steps to reproduce the behavior:
import ( "fmt"
)
func main() { app := fiber.New()
}
Emit()
orBroadcast()
. Not getting anything fromEmitTo()
Expected behavior
EmitTo()
should work for predefined events as well as custom events.