Back

[SOLVED] How to Manually use Realtime API

  • 0
  • Realtime
MrT2010
26 Feb, 2023, 22:34

Hello, I'd like to subscribe to the realtime channel "documents" to get all change events. I am using this C# call:

await socket.ConnectAsync(new Uri("wss://[HOST]/v1/realtime?project=[PROJECT-ID]&channels[]=documents"), CancellationToken.None);

The connection is opened but I receive this error from the appwrite server:

{"type":"connected","data":{"channels":["documents"],"user":null}} {"type":"error","data":{"code":1003,"message":"Message format is not valid."}}

Can please someone tell me what am I missing? I used this rfc to figure out how to communicate with the websocket endpoint: https://github.com/appwrite/rfc/blob/main/014-realtime-api.md

TL;DR
User is attempting to use the Realtime API in a C# client application (WinForms). They are able to establish a connection but receive an error message from the server stating that the message format is not valid. They are requesting assistance in resolving this issue. Solution: The user should refer to the provided link for a code example in JavaScript that demonstrates how to manually use the Realtime API. They should also check if their authentication session can be used for the websocket connection.
Drake
26 Feb, 2023, 22:38

Realtime with c#? What are you trying to do?

Also, maybe using the sdks as reference might be best. Are you able to read JavaScript? Or maybe dart?

MrT2010
26 Feb, 2023, 22:42

I am using C# for a client application (WinForms). Unfortunatelly there is no C# Client SDK available. For the REST part I use the client sdk created by the swagger code generator. This works so far for me. Now I try to get events everytime a document has changed, done by other instances of the client application, so that I can update the view.

Drake
26 Feb, 2023, 22:54

I see I see. So are you comfortable with reading JavaScript or dart?

Drake
26 Feb, 2023, 22:55

How to Manually use Realtime API

MrT2010
27 Feb, 2023, 00:23

Yes, reading JavaScript would be no Problem.

Currently I managed at least, that I receive events for documents with the access type "Any". As in the response after connect can be seen, user is set to null.

{"type":"connected","data":{"channels":["documents"],"user":null}}

I authenticate using Email authentication. Is there a way to use this session also for the websocket connection?

Drake
27 Feb, 2023, 00:24

Perhaps you can implement this in your c# code: https://github.com/appwrite/sdk-for-web/blob/1dde5c7bc91b18bfc1f4e2a80b0ba77017db66fe/src/client.ts#L262.

After getting connected, the client needs to send an authentication message.

MrT2010
27 Feb, 2023, 00:56

Thank you very much, it's working now. 🙂

Drake
27 Feb, 2023, 00:57

[SOLVED] How to Manually use Realtime API

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more