Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/room_manager/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import logging

from flask import Flask
from flask_cors import CORS

from .arguments import parse_arguments
from .room_service import RoomService
from .routes import setup_routes

app = Flask(__name__)
CORS(app)
app.logger.setLevel(logging.INFO)


Expand Down
16 changes: 13 additions & 3 deletions examples/room_manager/room_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import betterproto

from fishjam import FishjamClient, PeerOptions, Room, RoomOptions
from fishjam._openapi_client.models import RoomConfigRoomType
from fishjam.events import ServerMessagePeerCrashed as PeerCrashed
from fishjam.events import ServerMessagePeerDeleted as PeerDeleted
from fishjam.events import ServerMessageRoomCrashed as RoomCrashed
Expand Down Expand Up @@ -38,8 +39,13 @@ def __init__(self, args: Namespace, logger: Logger):
self.logger = logger
self.config = args

def get_peer_access(self, room_name: str, username: str) -> PeerAccess:
room = self.__find_or_create_room(room_name)
def get_peer_access(
self,
room_name: str,
username: str,
room_type: RoomConfigRoomType | None,
) -> PeerAccess:
room = self.__find_or_create_room(room_name, room_type)
peer_access = self.peer_name_to_access.get(username)
peer_in_room = self.__is_in_room(room, peer_access)

Expand All @@ -63,7 +69,9 @@ def handle_notification(self, notification: betterproto.Message):
case _:
pass

def __find_or_create_room(self, room_name: str) -> Room:
def __find_or_create_room(
self, room_name: str, room_type: RoomConfigRoomType | None
) -> Room:
if room_name in self.room_name_to_room_id:
self.logger.info("Room %s, already exists in the Fishjam", room_name)

Expand All @@ -74,7 +82,9 @@ def __find_or_create_room(self, room_name: str) -> Room:
max_peers=self.config.max_peers,
webhook_url=self.config.webhook_url,
peerless_purge_timeout=self.config.peerless_purge_timeout,
room_type=room_type.value if room_type else "full_feature",
)

new_room = self.fishjam_client.create_room(options=options)

self.room_name_to_room_id[room_name] = new_room.id
Expand Down
17 changes: 15 additions & 2 deletions examples/room_manager/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from flask import Flask, abort, jsonify, request

from fishjam import receive_binary
from fishjam.room import RoomConfigRoomType

from .room_service import RoomService

Expand All @@ -15,7 +16,13 @@ def health_check():

@app.get("/api/rooms/<room_name>/users/<peer_name>")
def get_room_params(room_name, peer_name):
access_data = room_service.get_peer_access(room_name, peer_name)
raw_room_type = request.args.get("roomType")
try:
room_type = RoomConfigRoomType(raw_room_type) if raw_room_type else None
except ValueError:
return abort(400)

access_data = room_service.get_peer_access(room_name, peer_name, room_type)
response = asdict(access_data)

response["peerToken"] = response.pop("peer_token")
Expand All @@ -25,12 +32,18 @@ def get_room_params(room_name, peer_name):
@app.get("/api/rooms")
def get_room_query():
room_name = request.args.get("roomName")
raw_room_type = request.args.get("roomType")
peer_name = request.args.get("peerName")

if not room_name or not peer_name:
return abort(400)

access_data = room_service.get_peer_access(room_name, peer_name)
try:
room_type = RoomConfigRoomType(raw_room_type) if raw_room_type else None
except ValueError:
return abort(400)

access_data = room_service.get_peer_access(room_name, peer_name, room_type)
response = asdict(access_data)

response["peerToken"] = response.pop("peer_token")
Expand Down
Empty file.
127 changes: 127 additions & 0 deletions fishjam/_openapi_client/api/default/drain_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
from http import HTTPStatus
from typing import Any, Dict, Optional, Union, cast

import httpx

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.error import Error
from ...types import Response


def _get_kwargs() -> Dict[str, Any]:
return {
"method": "post",
"url": "/admin/shutdown/drain",
}


def _parse_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Optional[Union[Any, Error]]:
if response.status_code == HTTPStatus.OK:
response_200 = cast(Any, None)
return response_200
if response.status_code == HTTPStatus.UNAUTHORIZED:
response_401 = Error.from_dict(response.json())

return response_401
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Response[Union[Any, Error]]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
*,
client: AuthenticatedClient,
) -> Response[Union[Any, Error]]:
"""Marks node as draining, making it the last in the load balancing order.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Union[Any, Error]]
"""

kwargs = _get_kwargs()

response = client.get_httpx_client().request(
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
*,
client: AuthenticatedClient,
) -> Optional[Union[Any, Error]]:
"""Marks node as draining, making it the last in the load balancing order.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Union[Any, Error]
"""

return sync_detailed(
client=client,
).parsed


async def asyncio_detailed(
*,
client: AuthenticatedClient,
) -> Response[Union[Any, Error]]:
"""Marks node as draining, making it the last in the load balancing order.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Union[Any, Error]]
"""

kwargs = _get_kwargs()

response = await client.get_async_httpx_client().request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
*,
client: AuthenticatedClient,
) -> Optional[Union[Any, Error]]:
"""Marks node as draining, making it the last in the load balancing order.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Union[Any, Error]
"""

return (
await asyncio_detailed(
client=client,
)
).parsed
129 changes: 129 additions & 0 deletions fishjam/_openapi_client/api/default/shutdown_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
from http import HTTPStatus
from typing import Any, Dict, Optional, Union

import httpx

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.error import Error
from ...models.shutdown_status_response import ShutdownStatusResponse
from ...types import Response


def _get_kwargs() -> Dict[str, Any]:
return {
"method": "get",
"url": "/admin/shutdown/status",
}


def _parse_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Optional[Union[Error, ShutdownStatusResponse]]:
if response.status_code == HTTPStatus.OK:
response_200 = ShutdownStatusResponse.from_dict(response.json())

return response_200
if response.status_code == HTTPStatus.UNAUTHORIZED:
response_401 = Error.from_dict(response.json())

return response_401
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Response[Union[Error, ShutdownStatusResponse]]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
*,
client: AuthenticatedClient,
) -> Response[Union[Error, ShutdownStatusResponse]]:
"""Returns status information for the shutdown process of Fishjam.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Union[Error, ShutdownStatusResponse]]
"""

kwargs = _get_kwargs()

response = client.get_httpx_client().request(
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
*,
client: AuthenticatedClient,
) -> Optional[Union[Error, ShutdownStatusResponse]]:
"""Returns status information for the shutdown process of Fishjam.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Union[Error, ShutdownStatusResponse]
"""

return sync_detailed(
client=client,
).parsed


async def asyncio_detailed(
*,
client: AuthenticatedClient,
) -> Response[Union[Error, ShutdownStatusResponse]]:
"""Returns status information for the shutdown process of Fishjam.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Union[Error, ShutdownStatusResponse]]
"""

kwargs = _get_kwargs()

response = await client.get_async_httpx_client().request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
*,
client: AuthenticatedClient,
) -> Optional[Union[Error, ShutdownStatusResponse]]:
"""Returns status information for the shutdown process of Fishjam.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Union[Error, ShutdownStatusResponse]
"""

return (
await asyncio_detailed(
client=client,
)
).parsed
Empty file.
Loading