20 lines
509 B
Python
20 lines
509 B
Python
from channels.generic.websocket import WebsocketConsumer
|
|
|
|
import json
|
|
|
|
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()
|
|
|
|
def disconnect(self, code: int = 1000):
|
|
self.socket.disconnect(code) |