2022-05-12 03:56:52 +00:00
|
|
|
import json
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
|
|
|
|
class ClientSimulator:
|
2022-08-24 11:54:46 +00:00
|
|
|
INITIAL_DATA = {"rooms": []}
|
2022-05-12 03:56:52 +00:00
|
|
|
|
|
|
|
def __init__(self, data: str = json.dumps(INITIAL_DATA)):
|
|
|
|
try:
|
|
|
|
self.data = json.loads(data)
|
|
|
|
except (json.JSONDecodeError, TypeError):
|
|
|
|
self.data = self.INITIAL_DATA
|
|
|
|
|
|
|
|
def export(self) -> str:
|
|
|
|
return json.dumps(self.data)
|
|
|
|
|
|
|
|
def join(self, room_id: str):
|
2022-08-24 11:54:46 +00:00
|
|
|
self.data["rooms"].append(room_id)
|
2022-05-12 03:56:52 +00:00
|
|
|
|
|
|
|
def get_joined_rooms(self) -> List[str]:
|
2022-08-24 11:54:46 +00:00
|
|
|
return self.data["rooms"]
|