11

I would like to implement a very simple chat in a website, with private messages between 2 registered and logged-in users (and possibly even group messages between logged-in users).
Take Whatsup as an example, but of course I won't have that many users.

Resources: Symfony2 + WebsocketBundle
https://github.com/GeniusesOfSymfony/WebSocketBundle

Two questions:
1- What database schema would you suggest?
2- How would I manage the "topics"? (After reading WebsocketBundle tutorial, I understand how to subscribe/unsubscribe/broadcast to a topic. But I don't know how to manage the relationship between users and topics, how to protect the conversations etc etc...
I just need some information (no code) about the logic of the application... what information to save and where.)

For example, how do I manage the name of the channel (will it change everytime, or do I store it in the database and somehow re-use it the next time the user logs in)?

session.subscribe("acme/channel/id/12345", function(uri, payload){
    console.log("Received message", payload.msg);
});

P.s. I've already tried searching on SO and Google but couldn't find any useful information.

Igor Carmagna
  • 957
  • 1
  • 10
  • 34
  • After so long, do you found any solution? I am looking at this too. – overshadow Oct 10 '17 at 07:34
  • Nope, I put on hold that project (because the WebsocketBundle developer a few years back told me that after completing the bundle he would release a functioning sample app). I haven't checked the GOS Github page in a few years, but I definetly plan on resuming my project. What's the status now? Is there a sample app which can provide us some insight? – Igor Carmagna Oct 13 '17 at 13:57

1 Answers1

1

WebsocketBundle provides you just a mechanism to write less for communication through the socket. For chat/group chat setup you have number of options. The first option can be to use some messaging bundle and modifying that according to the needs. I found this bundle (https://github.com/FriendsOfSymfony/FOSMessageBundle) very flexible.

But if you want to develop your own here is the schema inspired from the schema of FOSMessageBundle with some customization. Attaching a schema with tables and it's column names. One can easily identify primary and foreign keys from it.

enter image description here

The rest of things are pretty straight forward other than one field in Thread table which is thread_group_hash. Actually the purpose of this field is unique hash/key for each thread. Where thread means one to one chat or many to many chat. Whichever is the case whenever someone adds people to the chat the users have associated IDs with them. I sort the added user's IDs in ascending or descending order and generate md5/sha1 key and store it here.

This can also be used as topic in WebSocketBundle because that is using the topic for the same purpose which we are trying to achieve here. Whenever same group of people are added to the conversation from either of the party, the communication will go to the same thread. But remember before inserting the thread/message details you need to identify using this hash that where it belongs to or it's a new thread :)

Imran Zahoor
  • 2,521
  • 1
  • 28
  • 38
  • I would suggest you using Pusher or similar 3rd party service which will save you lots of headache – venimus May 27 '15 at 10:10
  • @venimus It's up to personal taste and fulfillment of the requirements, at times I enjoy writing my own. As this way I can have more control over the code :) – Imran Zahoor May 27 '15 at 11:30
  • Of course it is quite personal choice :) Actually I was proposing it to Igor. However such service does not save you the programming of your service, just the server part between the clients which is stright forward communcation but has some boring catchase and is already build bugfree. Of course for home project it is not very good because it is a paid service, but for bigger ones it will save you a lot: time, traffic, server resources which costs more money. – venimus Jun 01 '15 at 09:57