-
Notifications
You must be signed in to change notification settings - Fork 41
Adding websocket functionality
Websockets have been implemented using the channels with with Redis backend. When a page is loaded we create a socket connection between the client and the server, by subscribing to a group. The group is named after the user's unique ID (Remember the group name should only contain alphanumerics, hyphen and period hence use websocket_group_name function before assigning the unique ID as the group name).
This is a 3 step process:
-
Create a sqlalchemy ORM Mapper event. Mapper events provide hooks into critical sections of the mapper, including those related to object instrumentation, object loading, and object persistence. Here is an example of a hook for OwnerNotification models's after_create method.
-
Within these hook, add a call to send_message function. This function has 3 arguments:
- group_name: the unique ID (email ID) of the user
- type: type of communication/message. e.g. type=notification for sending notification over websockets This will be used to identify the message on the client side
- message: message in JSON format
-
Add code (here) to handle this new type of message on client side.