Writing a simple chat app in ocsigen

I’m trying to write a simple real-time chat app in ocsigen, along the lines of this phoenix tutorial. i’ve read through the tutorials on client/server reactive elements and broadcasting over Eliom_bus but I’m having trouble putting the pieces together. Could someone give me a very simple example of a reactive list that is synced across all connected clients?

Hi,

Taking as example Graffiti tutorial, you should be able to implement a chat with Eliom_bus, indeed.
Every client writes its own new messages on the bus, and everyone listen on the bus and displays the message in the page. For updating the page on client side, appendChild should be enough (or Manip.append_child).

If you want to play with reactive lists, it is a little bit trickier. You should first try with reactive lists I think and then change your code (ask again if you need). You can find a good example of reactive lists here.
source code of this example

A few hints on how we implemented the chat in the besport app:
Instead of a bus, we are using module Os_notif (which is a version of
Eliom_notif with user support).

When a user opens a chatroom, it registers on this chatroom id with function listen.
To send a message to other listening clients, call notify.

A basic code example of Os_notif is given in Ocsigen Start here. Warning: it works only if you are connected.
source code of this example

3 Likes

thanks vincent, somehow i managed to miss the reply notification! i’ll take your advice and play around with Manip rather than reactive lists.

1 Like