saltcorn icon indicating copy to clipboard operation
saltcorn copied to clipboard

Real-Time Chat Room Example

Open serge402 opened this issue 1 year ago • 31 comments

Does anyone have a working example of a Real-Time Chat Room that they could share?

I tried to follow the WiKi but I'm stuck at an error "insert or update on table "Participants" violates foreign key constraint "Participants_room_id_fkey"".

Thanks.

serge402 avatar Jun 28 '23 22:06 serge402

I can help with that. Give me a day or so

christianhugoch avatar Sep 04 '23 07:09 christianhugoch

@christianhugoch Thank you!

serge402 avatar Sep 06 '23 14:09 serge402

In our unit tests, we're using this model for the chat: data_modell

With that, you can create a room view with this configuration: rooms_view_cfg

Message show view is used to show each message, so you can use a single textfield for the content.

New message form view is an edit view. You'll see it at the bottom, under the messages.

To create a room you can use an edit view for 'rooms'.

And you have to be a participant in that room. For that, you can create an edit view for participants with selects for user and room. Let me know if it does not work

christianhugoch avatar Sep 11 '23 06:09 christianhugoch

@christianhugoch Thanks for that.

I think I have it working. However messages are NOT in Real-time! And a refresh of the room view webpage is required for new messages to appear.

Are you able to test if that is the case for you? If not, maybe I have done something wrong and you could share your backup file?

And what does the "Participant max read id field" do? If I try to use it I just get a error when loading Room view webpage. image

serge402 avatar Sep 18 '23 01:09 serge402

Hi, could it be that you're behind a nginx or so. The chat uses websockets and I believe the default nginx config isn't ready for that. Can you open your browser console and see if there are any errors like 'unable to connect to ...' ?

I'll take a look at the Participant max read id field

christianhugoch avatar Sep 18 '23 08:09 christianhugoch

@christianhugoch I am not using nginx or or anything. I just have a local VM running as a test bed for development.

However! I do get an error. image

Does this help identify the problem?

serge402 avatar Sep 18 '23 10:09 serge402

No, I think that's another problem. Are you using the chat with different users, or is it at both sides the same?

christianhugoch avatar Sep 18 '23 11:09 christianhugoch

Different user, I even tried to use Chrome on a different device (for different user), but was same result.

serge402 avatar Sep 18 '23 20:09 serge402

Hm, can you open the NetworkMonitor and send me a screenshot of it after you load the page and after sending a message.

christianhugoch avatar Sep 19 '23 15:09 christianhugoch

@christianhugoch I hope this is the NetworkMonitor you were talking about. Before Message image

After MEssage image image

Hope this helps.

Did you want me to send you the backup file?

serge402 avatar Sep 20 '23 00:09 serge402

Yes, could you send me the file? I've just tested the unit test setup on my device, and I believe your screenshots are looking good, too.

christianhugoch avatar Sep 20 '23 10:09 christianhugoch

@christianhugoch I've emailed you the backup file to your Gmail address.

Let me know how you go.

serge402 avatar Sep 22 '23 00:09 serge402

Hi, I've tested it between firefox and chrome and it worked. Let think about it what else could be wrong here.

christianhugoch avatar Sep 25 '23 14:09 christianhugoch

@christianhugoch Hmm interesting. Thanks for letting me know.

I have now tried it with two different VM's (with update), between different browsers (Chrome Firefox), different computers and still the same problem, no live update.

How are you running (hosting Saltcorn)? What version of Saltcorn are you running? I'm currently running VM's (Ubuntu 20.04) using Hyper-V.

I am getting this error in Chrome: image

Is there some Firewall rule preventing Websockets?

Any suggestions on what else it could be?

serge402 avatar Sep 26 '23 03:09 serge402

I'm running saltcorn on my host os with the cli command: saltcorn serve

I would like to see if your process has logs. You are propably using a systemctl service, right? Can you do

systemctl status saltcorn

christianhugoch avatar Sep 27 '23 12:09 christianhugoch

@christianhugoch Yes I'm using systemctl service.

This is what I get. image

serge402 avatar Sep 28 '23 11:09 serge402

Can you go to 'About application / development'

and enable 'Log SQL to stdout', 'Log client errors'?

Perhaps we have to add more debug logs to see what's going on.

christianhugoch avatar Sep 28 '23 14:09 christianhugoch

@christianhugoch I don't know enough about Linux to understand what you mean there or how to do that.

Are you able to provide actual Linux console commands? or more detailed instruction on how to enable logs?

serge402 avatar Sep 29 '23 05:09 serge402

That's not a Linux cfg, it's just a tab on the dashboard.

Click 'About application', then next to 'Mobile App' is the 'Development' tab.

Here you can activate Log SQL to stdout and Log client errors

Then use the chat and do systemctl status saltcorn or perhaps try journalctl -u saltcorn

I'm just fishing, but do you have some special extensions installed in your browser?

christianhugoch avatar Sep 30 '23 12:09 christianhugoch

@christianhugoch Ah! got it! No. I'm not running any extensions etc, got a fresh install of Firefox and event tried with Chrome incognito mode.

Ok, here is the result for systemctl status saltcorn after enabling Log SQL to stdout and Log client errors in saltcorn settings. image

And journalctl -u saltcorn image

Hope this helps.

serge402 avatar Oct 03 '23 05:10 serge402

@christianhugoch I have now tested the Chat feature with the Mobile App!

And I got the same result as with using the Browser, New messages don't load unless I reload (leave and join the chat room again).

Are you able to test Chat in a Ubuntu VM? Because I'm totally lost why it doesn't work for me. I even reinstalled a fresh VM and Ubuntu 22.04 with all updates etc, and still no go.

On the Upside, with the new version 0.8.9 and the new Toasts: notification system that has been redesigned. The "Welcome to Saltcorn" pop up that happens when App first opened is no longer an issue and it doesn't cause the page content to shift in the mobile App. However it still says "Welcome to Saltcorn!" with no way of changing it. So I will raise a feature request for that.

serge402 avatar Oct 03 '23 06:10 serge402

Hi, I overlooked your screenshot (from last week) with the Websocket connection to ... failed error.

The problem has to be there, I'll try to re-create

christianhugoch avatar Oct 04 '23 08:10 christianhugoch

@christianhugoch Here is the interesting thing.

After I created a fresh new VM with Ubuntu 22.04, I no longer get ANY Errors in Chrome.

However, I still a warning while testing in Firefox. image

Hope that helps, additionally could there be any Firewall setting in Ubuntu preventing Websocket's connection?

serge402 avatar Oct 04 '23 12:10 serge402

Okay, I can replicate a problem. When I run the VM with a Network Bridge then it does not update on my host. Not sure if this is the same problem but I can look further into it.

christianhugoch avatar Oct 09 '23 13:10 christianhugoch

@christianhugoch Yes! I use a network Bridge with my Hyper-V.

I will try some other VM software without a bridge and see how it will go.

serge402 avatar Oct 10 '23 13:10 serge402

@christianhugoch I have now tried using a VM in VirtualBox with Bridge and NAT and in both cases I could not make Live Chat work, no matter which ports I forwarded. Even tried Disabling Ubuntu Firewall.

The closes solution I could find was this: https://stackoverflow.com/questions/45894011/virtualbox-socket-hangup But I don't know how to change the Websocket address in Saltcorn.

I am going to try using a VM on a Type 1 Hypervisor (Proxmox) next.

serge402 avatar Oct 12 '23 09:10 serge402

Okay, sorry I haven't yet looked deeper into it, but I definitely saw it working with a DigitalOcean droplet on the web and in the app version.

christianhugoch avatar Oct 12 '23 11:10 christianhugoch

@christianhugoch I have now tried Live chat without ANY VM, just bear metal Ubuntu install with Saltcorn on an old PC.

And still live chat does not work...

Could Live Chat feature be gated unless SSL certificate is used??

Is there a way for me to get Saltcron to run as HTTPS? without using SSL certificate from Let's Encrypt?

serge402 avatar Oct 28 '23 10:10 serge402

Apologies for letting you wait.

I think you could set up a nginx server with your own certificate and a DNS server so that you don't have to use an IP. But that's probably way too much effort.

Socket.io doesn't insist on HTTPS, you can test it on the localhost with HTTP, but when I open the page via an IP with HTTP on the VM, then I get a warning that the connection is not secure. I believe this is why the server can't send a notification to your browser. I debugged the server a bit on the VM, and he does all the right things, only the message doesn't arrive at the browser.

I believe this is just a problem you get in a local test environment with a VM that you have to access via IP. So in a production environment where all is set up, this shouldn't happen, and I think this is more importan. But I'm still trying to find a workaround or something.

christianhugoch avatar Nov 06 '23 13:11 christianhugoch

@christianhugoch Apologies for late reply.

Thank you for letting me know, I will try nginx server with my own certificate or maybe ill try with Cloudflare for a more production ready example.

Will let you know.

serge402 avatar Nov 30 '23 03:11 serge402