-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
247 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from asgiref.sync import async_to_sync | ||
from channels.generic.websocket import WebsocketConsumer | ||
|
||
from .main import handle_rohrpost_message | ||
|
||
|
||
class SyncRohrpostConsumer(WebsocketConsumer): | ||
def connect(self): | ||
self.accept() | ||
|
||
def disconnect(self, close_code): | ||
pass | ||
|
||
def receive(self, text_data: str) -> None: | ||
handle_rohrpost_message(consumer=self, text_data=text_data) | ||
|
||
def add_to_group(self, group_name) -> None: | ||
async_to_sync(self.channel_layer.group_add)(group_name, self.channel_name) | ||
|
||
def remove_from_group(self, group_name) -> None: | ||
async_to_sync(self.channel_layer.group_discard)(group_name, self.channel_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
import json | ||
|
||
|
||
class ReplyChannel: | ||
class Consumer: | ||
def __init__(self): | ||
self.data = [] | ||
self.closed = False | ||
|
||
def send(self, message_dict): | ||
def send(self, message: str): | ||
if not self.closed: | ||
self.data.append(json.loads(message_dict.get("text"))) | ||
self.closed = message_dict.get("close", False) | ||
self.data.append(json.loads(message)) | ||
|
||
|
||
class Message: | ||
def __init__(self): | ||
self.reply_channel = ReplyChannel() | ||
def close(self): | ||
self.closed = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.