br41nslug / directus-websocket-subscribe

An extension to subscribe to directus updates over a websocket.
MIT License
106 stars 13 forks source link

Collection is required for custom handlers #8

Closed Nisthar closed 2 years ago

Nisthar commented 2 years ago

It checks for a collection key for custom handlers. I think this is the code that throws the error

https://github.com/br41nslug/directus-websocket-subscribe/blob/623db0cfe560380b6454e8f54e3a9c9535cd7b34/src/util.ts#L16

Maybe give priority to custom handlers might fix it. But i am not sure.

br41nslug commented 2 years ago

Made it optional as enforcing that for custom handlers makes no sense 😄

Nisthar commented 2 years ago

Made it optional as enforcing that for custom handlers makes no sense 😄

also when sending custom events, it omits all the other data. It would be nice if you could keep the custom data for custom events.

Nisthar commented 2 years ago

@br41nslug why am i getting Error: Invalid message type! Either get, post, patch, delete or subscribe expected? can't i pass custom type?

br41nslug commented 2 years ago

@ Hmmm seems i've not documented that properly. It is expecting your handler's parseMessage function to return a non-false result to pass the the onMessageHandler It is expecting your handler to have the onMessage function because if not it will mark the incoming message as "unhandled" and throw that error 😓 https://github.com/br41nslug/directus-websocket-subscribe/blob/e8df409dd190e579400ae94451165ef46dce9f60/src/server.ts#L78 I think the whole message handling might be due a bit of a refactor considering proper extensibility

Nisthar commented 2 years ago

I had some false value in my handler. Its working fine now.

br41nslug commented 2 years ago

sorry i realized my mistake and updated my message @Nisthar

br41nslug commented 2 years ago

I do see there's very much room for improvement here so any PRs/issues/discussions after playing around with it will be appreciated 😄