2023-12-23 12:30:45 -05:00
|
|
|
from channels.generic.websocket import WebsocketConsumer
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
2023-12-23 12:11:30 -05:00
|
|
|
class AbstractRoomMember:
|
|
|
|
|
|
|
|
def __init__(self, user_id: int, socket: WebsocketConsumer):
|
|
|
|
self.user_id: int = user_id
|
|
|
|
self.socket: WebsocketConsumer = socket
|
|
|
|
|
|
|
|
def send(self, detail: str, data: dict = {}):
|
|
|
|
raw_data: dict = {"detail": detail}
|
|
|
|
raw_data.update(data)
|
|
|
|
self.socket.send(text_data=json.dumps(raw_data))
|
|
|
|
|
|
|
|
def accept(self):
|
|
|
|
self.socket.accept()
|
|
|
|
|
2023-12-23 12:47:16 -05:00
|
|
|
def disconnect(self, code: int = 1000):
|
|
|
|
self.socket.disconnect(code)
|