Skip to content

Commit

Permalink
xxx
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmajoor committed Mar 26, 2024
1 parent 9e8bd20 commit 8b25c6b
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions binder/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,24 @@ def list_rooms_for_user(self, user):

return rooms

channel = Noneq
def get_websocket_channel():
import pika
from pika import BlockingConnection
global channel
if channel and channel.is_open:
return channel
connection_credentials = pika.PlainCredentials(settings.HIGH_TEMPLAR['rabbitmq']['username'],
settings.HIGH_TEMPLAR['rabbitmq']['password'])
connection_parameters = pika.ConnectionParameters(settings.HIGH_TEMPLAR['rabbitmq']['host'],
credentials=connection_credentials)
connection = BlockingConnection(parameters=connection_parameters)
channel = connection.channel()
return channel

def trigger(data, rooms):
if 'rabbitmq' in getattr(settings, 'HIGH_TEMPLAR', {}):
import pika
from pika import BlockingConnection

connection_credentials = pika.PlainCredentials(settings.HIGH_TEMPLAR['rabbitmq']['username'],
settings.HIGH_TEMPLAR['rabbitmq']['password'])
connection_parameters = pika.ConnectionParameters(settings.HIGH_TEMPLAR['rabbitmq']['host'],
credentials=connection_credentials)
connection = BlockingConnection(parameters=connection_parameters)
channel = connection.channel()

channel = get_websocket_channel()
channel.basic_publish('hightemplar', routing_key='*', body=jsondumps({
'data': data,
'rooms': rooms,
Expand Down

0 comments on commit 8b25c6b

Please sign in to comment.