Skip to content

Conversation

@NoahShomette
Copy link
Collaborator

@NoahShomette NoahShomette commented Oct 9, 2024

fixes #15 .

Adds custom serialization which allows users to supply custom serialization functions for messages to utilize different serialization formats with minimal change to current user ergonomics.

Changes

  • Network is now a system param, Network was changed to NetworkInstance. Users need to interact with the network through the Network system param now.
  • Sending messages now utilizes observers to enable different serialization functions for each message type.
  • recv_loop and send_loop now take a hashmap of serialization functions to enable serialization and deserialization of messages according to different settings.
  • messages must be registered on BOTH the sender and the receiver
  • listen_for_message is now register_message
  • listen_for_request_message is now register_receive_request_message
  • listen_for_response_message is now register_send_request_message

Custom Serialization

See BEMW JSON for an example. Recommend making a trait to help with registration. You need a generic serialization and deserialization function each and then one each for serializing and deserializing network packets. See BEMW for an example of how it should be implemented.

Limitations

  • Crate only supports sending Text or Binary over the network.
  • Mixing different serialization methods works rn on native but between wasm and native is intermittently working (Might be more of a BEMW issue but its weird enough that it might be on eventworks side messing up registrations for messages or something).

Todo

  • Cleanup
  • Add docs to serialization
  • Make sure Readme and stuff is updated to new format
  • Fix different serialization methods not working on Wasm
  • I accidentally made this branch off an older 0.13 branch :( (I need to update everything so it matches main or rebase it. Probably override main since I'm allergic to rebasing.)

…ypes::Text, make it possible to utilize different serialization methods over the wire and assign certain network messages specific serialization methods. Update examples to include a network request message to make sure it works
@NoahShomette
Copy link
Collaborator Author

BEMW branch: https://github.com/NoahShomette/bevy_eventwork_mod_websockets/tree/serialization

@davi4046 If you are still using this and the custom serialization can you test if this works for you?

@mraof I saw you forked the custom serialization repos also so can you test this and see if it works for you as well?

@davi4046
Copy link

davi4046 commented Oct 9, 2024

I will try to have a look at it tommorow👍

@davi4046
Copy link

I have two errors when attempting to make this work.

Firstly, bevy::tasks::TaskPool is said to not implement bevy_eventwork:Runtime.

example-1

Secondly, the registration functions are not available on App in the example you provided. I guess it's because at the point of implementation, the app has not had the necessary plugins added yet.

example-2

Let me know if I'm doing anything wrong and I'll try again.

@NoahShomette
Copy link
Collaborator Author

Just to make sure are you on bevy 0.14? I forgot you were working from 0.13 so that might be a pain for you to test sorry :(

I have two errors when attempting to make this work.

Firstly, bevy::tasks::TaskPool is said to not implement bevy_eventwork:Runtime.

example-1

Secondly, the registration functions are not available on App in the example you provided. I guess it's because at the point of implementation, the app has not had the necessary plugins added yet.

example-2

Let me know if I'm doing anything wrong and I'll try again.

@davi4046
Copy link

davi4046 commented Oct 11, 2024

Ah, I totally forgot about the bevy version. Compilation errors are gone now, thanks!

Unfortunately I get bevy_eventwork_mod_websockets::native_websocket: Failed to decode network packet. No deserialization fn found when sending a message to the server.

Server to client seems to work fine, although I had to change how the client handles received messages.

I might still be doing something wrong, sorry. You can have a look at the repo: https://github.com/davi4046/bevy_eventwork_websocket_json_demo

@NoahShomette
Copy link
Collaborator Author

Thanks for the link to the repo that is very helpful! It's unfortunately running into some issues that I couldn't resolve over the weekend so theres definitely a good amount of more work to fix this pr up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sending messages from JavaScript

2 participants