JavaScript Rails - Sinatra real time notifications

I am trying to build a real time notifications module that functions in a similar manner to facebook's realtime notifications for example if a user requests friendship of another user a push notification is sent to the second one where I have the following constraints: 1- notifications are sent to a specific user's all browser instances 2- user need to be logged in to subscribe him to notifications 3- not to use pooling because of performance issues 4- it obviously need to be secure

I did a quick research and I found out that the options I have are web sockets or server-sent events. server-sent events handles reconnecting automatically and quite fits the functionality I needed so I decided to go with it.

I built a sinatra event driven server where whenever a user requests friendship of another user the notification should be pushed through it to the second user but there appeared to be several problems where my solutions to it convinced me that I am going in the wrong direction.

How do I bind an eventsource to a specific user and at the same time maintain security. What is the proper way I can create an eventsource if and only if a user is logged in.

I also need general helpful guidelines to address this task

Answer:1

Usually you don't need to have "exactly real time" and you can use setTimeout(simulate_realtime, 5000); that checks if there is new data on the server each 5 seconds.

You can also checkout https://github.com/rails/actioncable that will be in Rails 5, which will be release a stable this fall. You can bet on it, it is the next main component that will be added to rails.

Answer:2

Probably you need eventmachine(https://github.com/eventmachine/eventmachine/tree/master/examples/guides/getting_started). Look at the chat example

Answer:3

I provide some additional services to websites that add my script to their site. Technically my script does not interact with actual functionality of the site, the most is does is read some ...

I provide some additional services to websites that add my script to their site. Technically my script does not interact with actual functionality of the site, the most is does is read some ...

I use jQuery & PDO to dynamic a pagination When I create some button which have id = xx Then use jQuery try get one of button id , It isn't work This is my code: $records = $...

I use jQuery & PDO to dynamic a pagination When I create some button which have id = xx Then use jQuery try get one of button id , It isn't work This is my code: $records = $...

I have the following data structure { "advisors" : { "0ea9bab6-415e-4900-8698-ac03a1ef4518" : { "description" : "", "price" : 0, "title" : "" }, "cc31c353-ca6a-440d-...

I have the following data structure { "advisors" : { "0ea9bab6-415e-4900-8698-ac03a1ef4518" : { "description" : "", "price" : 0, "title" : "" }, "cc31c353-ca6a-440d-...

  1. query data with python
  2. query data with transact sql
  3. query data with database functions
  4. query data with sql
  5. query data with pandas
  6. query data with mongodb
  7. query data with
  8. query data with mysql
  9. data query with firebase
  10. query data in excel
  11. query data in s3
  12. query data from elasticsearch
  13. query data from dynamodb
  14. query data in r
  15. query data in access
  16. query data from influxdb
  17. query data in power bi
  18. query data from two tables sql
  19. query data in redis
  20. query data from google analytics

I want to display jquery yearly calendar as shown in image. now I displayed only monthly calendar JSFiddle $(function () { $("#datepicker").datepicker({ changeMonth: true, ...

I want to display jquery yearly calendar as shown in image. now I displayed only monthly calendar JSFiddle $(function () { $("#datepicker").datepicker({ changeMonth: true, ...