-
-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: handle onMessage by message type #315
Comments
I personally welcome this change: I had to write my own wrapper to do this, and I believe many others have had to do similar. Having it be baked in would save people from needing to have varied approaches to doing this (which ultimately all accomplish the same thing). |
Hi @endel , my 2 cents from a newbie dev point of view. This:
And this:
Feels really forcing clients to do stuff we sometimes don't need, I understand it could have good impact related to typed code, but if in some cases we just need to send one value, like: Also I'm guessing that would impact on the "traffic" and the amount of data sent? On the other hand, manage schema classes like this:
It looks so much better! You would probably save me so many conditions checking if the message is coming with some specific value to run an action. |
It definitely means this can be typed more strongly, which is good- you can force a message of a type to have certain values, which is good for developers, and sanity. Additionally, if you are doing something like The real bandwidth saves don't come from cutting a small |
Regarding the number of bytes being sent, |
Thanks for the clarification @seiyria , in the commented case the client could know what to do depending on the attribute sent, |
I'll better be mentally preparing for another full refactor on my app 😅 |
That'll sure be breaking change for me, but I'll accept it. I'm sending "type" values with every event anyway :) |
I like this change. |
So let's say I have a lot of these around my application, presumably at the moment ALL callback functions are called for every message. Could this mean an optimisation where the callback fires only when that message type is received? |
I'm already kind of doing this manually in my game, so having an "official" way to handle message types would be nice. It should probably be optional for those who want to send very small efficient messages though... Also bonus point if it can be a number so we can use enums to reduce bandwidth usage, otherwise including a string type on every message increases the size of the message. |
cool😁 |
It sounds like an amazing change, and I would more like to use Schema instead of Fossil Delta. Why I choose Fossil Delta but not Schema? Because the schema code generator is not customable. Would you consider to implement the generator by template mechanism? |
Hi @zgz682000, you mind elaborating the "template mechanism" on a new issue? Cheers! |
i also support the change :) maybe the old public interface can be kept? it can just call the new stuff where ever possible so not everything has to be refactored ? |
of cause, I will write my advice in the schema repository after have a research of it |
Can you consider adding a one-time request method? //Current implementation methods
//client side
function JustDoOnce(){
client.send(getSysCfg,{});
client.onMessage(getSysCfg, (message) => {
client.removeListener(getSysCfg);
//dosomething
});
}
//My suggestion
//client side
function JustDoOnce(){
client.send(getSysCfg,{}).then(data=>{
//dosomething
})
} Can I do this?😁 |
* wip restructuring onMessage * refactoring onMessage and Transport for better message type support. #315 * refactoring protocol messages, client.send(), and client.raw() * refactoring Protocol's send / getMessageBytes #48 * refactoring room.broadcast() and serializers to use client.raw() * fixes integration tests #315 * fixes WebSocketClient tests. #315 * bump alpha version * use enqueueRaw for client.send * improve onMessage tests #315 * enhancement: swap old Client 'ref' after re-connection is successful * bump 0.13.0-alpha.4 * feat: allow send/receive messages by type without payload. #315 * update test name #315 * feat: generateId() not accepts optional 'length' argument. * enhancement: expose different error codes for internal errors. export ServerError. #317 * fix silly mistake during refactoring * fix: force onCreate to be implemented by end user. #319 * revert abstract onCreate. fixes strict usage on .define() method. #319 * lobby: add LobbyRoom and .enableRealtimeListing() feature. * add 'name' to player on RelayRoom. forward messages in array format * new alpha version * bump 0.13.0
* fixed source style of WebSocket, added forst working message queue * rewriting OnMessage to support messages by type * use casting on Action<> to return typed value colyseus/colyseus#315 * initial version for typed room.OnMessage(). refactor error codes. #113 * implement Send() and OnMessage(). closes #113 * fixes for webgl build * remove deprecated 'enqueuedCalls' for Connection. fixes conditional compilation for WEBGL * fix: allow receiving messages without payload * avoid re-allocating bytes when decoding msgpack objects Co-authored-by: AJ <aj.3dev@gmail.com>
0.13.x seems not implement the usage like this |
Hi @zgz682000, only the client-side is able to listen to The client-side is not allowed to send |
Thank you for response immediately. may it be used as a optional way of listening message, even if temporarily provide for JS/TS ? |
although I don't know why I hope this, maybe just for looks cool... or... comfortable... |
This would be a big breaking change, I'd like to know your thoughts and opinions about this. Will it be valuable/worth doing? Feedback is highly appreciated!
Server-side
client.send()
to replacethis.send()
+ messagetype
:client.send()
a schema-encoded messageBroadcast with type + data
onMessage
to handle messages sent from the clientsClient-side
Allow sending the type of a message along with its data:
Allow sending a Schema structure from the client-side (this will be specially useful for strongly-typed languages, such as C#, C++, etc.)
Receiving messages by
type
:As always suggestions are welcome.
The text was updated successfully, but these errors were encountered: