thoov / mock-socket

Javascript mocking library for WebSockets and Socket.IO
MIT License
797 stars 118 forks source link

it would be nice to mention socket.dispatchEvent in docs #309

Open keremciu opened 3 years ago

keremciu commented 3 years ago

I'm using mock-socket in new version of my game. I wanted to add some test coverage.

I have a test case that one user is already created a game then second user can join. Somehow I found some ugly solutions but I I couldn't find any example when I need to broadcast to players who joined the game.

I assumed mockServer.emit could be the solution but I couldn't say specifally, just send message for players who joined the game.

I implemented a solution this way: https://github.com/keremciu/house-of-decks/blob/ws-implement/client/src/utils/server-mock.js#L32-L42

I asummed people who wants to play with mockServer.clients() would like to see an example, it would be nice to mention there's dispatchEvent to send something to client because my original server code uses client.send to reach same functionality. It can cause conflict for many people.

https://github.com/keremciu/house-of-decks/blob/ws-implement/server/index.js#L62

dfree commented 3 years ago

@keremciu Thank you so much for these links! Your implementation helped me to understand the whole thing better! And huge shout out to @thoov as well making it even possible! All the best for you fellas! ;)