channel.py 606 B

1234567891011121314151617181920212223
  1. # Copyright: (c) OpenSpug Organization. https://github.com/openspug/spug
  2. # Copyright: (c) <spug.dev@gmail.com>
  3. # Released under the AGPL-3.0 License.
  4. from channels.layers import get_channel_layer
  5. from asgiref.sync import async_to_sync
  6. import uuid
  7. layer = get_channel_layer()
  8. class Channel:
  9. @staticmethod
  10. def get_token():
  11. return uuid.uuid4().hex
  12. @staticmethod
  13. def send_notify(title, content):
  14. message = {
  15. 'type': 'notify.message',
  16. 'title': title,
  17. 'content': content
  18. }
  19. async_to_sync(layer.group_send)('notify', message)