Skip to content

Commit

Permalink
Add feature: hls manual track subscription (#19)
Browse files Browse the repository at this point in the history
* Add feature: hls manual track subscription

* Remove recording api
  • Loading branch information
Karolk99 authored Dec 1, 2023
1 parent eec1e67 commit bf9267d
Show file tree
Hide file tree
Showing 11 changed files with 577 additions and 17 deletions.
7 changes: 6 additions & 1 deletion jellyfish/_openapi_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
__version__ = "1.0.0"

# import apis into sdk package
from jellyfish._openapi_client.api.default_api import DefaultApi
from jellyfish._openapi_client.api.hls_api import HlsApi
from jellyfish._openapi_client.api.room_api import RoomApi

# import ApiClient
Expand All @@ -40,6 +40,9 @@
from jellyfish._openapi_client.models.component_metadata_hls import ComponentMetadataHLS
from jellyfish._openapi_client.models.component_options import ComponentOptions
from jellyfish._openapi_client.models.component_options_hls import ComponentOptionsHLS
from jellyfish._openapi_client.models.component_options_hlss3 import (
ComponentOptionsHLSS3,
)
from jellyfish._openapi_client.models.component_options_rtsp import ComponentOptionsRTSP
from jellyfish._openapi_client.models.component_rtsp import ComponentRTSP
from jellyfish._openapi_client.models.error import Error
Expand All @@ -62,3 +65,5 @@
)
from jellyfish._openapi_client.models.room_details_response import RoomDetailsResponse
from jellyfish._openapi_client.models.rooms_listing_response import RoomsListingResponse
from jellyfish._openapi_client.models.s3_credentials import S3Credentials
from jellyfish._openapi_client.models.subscription_config import SubscriptionConfig
2 changes: 1 addition & 1 deletion jellyfish/_openapi_client/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# flake8: noqa

# import apis into api package
from jellyfish._openapi_client.api.default_api import DefaultApi
from jellyfish._openapi_client.api.hls_api import HlsApi
from jellyfish._openapi_client.api.room_api import RoomApi
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from typing import Optional

from jellyfish._openapi_client.models.hls_skip import HlsSkip
from jellyfish._openapi_client.models.subscription_config import SubscriptionConfig

from jellyfish._openapi_client.api_client import ApiClient
from jellyfish._openapi_client.api_response import ApiResponse
Expand All @@ -31,7 +32,7 @@
)


class DefaultApi(object):
class HlsApi(object):
"""NOTE: This class is auto generated by OpenAPI Generator
Ref: https://openapi-generator.tech
Expand All @@ -44,7 +45,7 @@ def __init__(self, api_client=None):
self.api_client = api_client

@validate_arguments
def jellyfish_web_hls_controller_index(
def get_hls_content(
self,
room_id: Annotated[StrictStr, Field(..., description="Room id")],
filename: Annotated[StrictStr, Field(..., description="Name of the file")],
Expand All @@ -64,12 +65,12 @@ def jellyfish_web_hls_controller_index(
] = None,
**kwargs
) -> str: # noqa: E501
"""Send file # noqa: E501
"""Retrieve HLS Content # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.jellyfish_web_hls_controller_index(room_id, filename, range, hls_msn, hls_part, hls_skip, async_req=True)
>>> thread = api.get_hls_content(room_id, filename, range, hls_msn, hls_part, hls_skip, async_req=True)
>>> result = thread.get()
:param room_id: Room id (required)
Expand Down Expand Up @@ -98,14 +99,14 @@ def jellyfish_web_hls_controller_index(
kwargs["_return_http_data_only"] = True
if "_preload_content" in kwargs:
raise ValueError(
"Error! Please call the jellyfish_web_hls_controller_index_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data"
"Error! Please call the get_hls_content_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data"
)
return self.jellyfish_web_hls_controller_index_with_http_info(
return self.get_hls_content_with_http_info(
room_id, filename, range, hls_msn, hls_part, hls_skip, **kwargs
) # noqa: E501

@validate_arguments
def jellyfish_web_hls_controller_index_with_http_info(
def get_hls_content_with_http_info(
self,
room_id: Annotated[StrictStr, Field(..., description="Room id")],
filename: Annotated[StrictStr, Field(..., description="Name of the file")],
Expand All @@ -125,12 +126,12 @@ def jellyfish_web_hls_controller_index_with_http_info(
] = None,
**kwargs
) -> ApiResponse: # noqa: E501
"""Send file # noqa: E501
"""Retrieve HLS Content # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.jellyfish_web_hls_controller_index_with_http_info(room_id, filename, range, hls_msn, hls_part, hls_skip, async_req=True)
>>> thread = api.get_hls_content_with_http_info(room_id, filename, range, hls_msn, hls_part, hls_skip, async_req=True)
>>> result = thread.get()
:param room_id: Room id (required)
Expand Down Expand Up @@ -197,7 +198,7 @@ def jellyfish_web_hls_controller_index_with_http_info(
if _key not in _all_params:
raise ApiTypeError(
"Got an unexpected keyword argument '%s'"
" to method jellyfish_web_hls_controller_index" % _key
" to method get_hls_content" % _key
)
_params[_key] = _val
del _params["kwargs"]
Expand Down Expand Up @@ -264,3 +265,171 @@ def jellyfish_web_hls_controller_index_with_http_info(
collection_formats=_collection_formats,
_request_auth=_params.get("_request_auth"),
)

@validate_arguments
def subscribe_tracks(
self,
room_id: Annotated[StrictStr, Field(..., description="Room ID")],
subscription_config: Annotated[
Optional[SubscriptionConfig], Field(description="Subscribe configuration")
] = None,
**kwargs
) -> None: # noqa: E501
"""Subscribe hls component for tracks # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.subscribe_tracks(room_id, subscription_config, async_req=True)
>>> result = thread.get()
:param room_id: Room ID (required)
:type room_id: str
:param subscription_config: Subscribe configuration
:type subscription_config: SubscriptionConfig
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:return: Returns the result object.
If the method is called asynchronously,
returns the request thread.
:rtype: None
"""
kwargs["_return_http_data_only"] = True
if "_preload_content" in kwargs:
raise ValueError(
"Error! Please call the subscribe_tracks_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data"
)
return self.subscribe_tracks_with_http_info(
room_id, subscription_config, **kwargs
) # noqa: E501

@validate_arguments
def subscribe_tracks_with_http_info(
self,
room_id: Annotated[StrictStr, Field(..., description="Room ID")],
subscription_config: Annotated[
Optional[SubscriptionConfig], Field(description="Subscribe configuration")
] = None,
**kwargs
) -> ApiResponse: # noqa: E501
"""Subscribe hls component for tracks # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.subscribe_tracks_with_http_info(room_id, subscription_config, async_req=True)
>>> result = thread.get()
:param room_id: Room ID (required)
:type room_id: str
:param subscription_config: Subscribe configuration
:type subscription_config: SubscriptionConfig
:param async_req: Whether to execute the request asynchronously.
:type async_req: bool, optional
:param _preload_content: if False, the ApiResponse.data will
be set to none and raw_data will store the
HTTP response body without reading/decoding.
Default is True.
:type _preload_content: bool, optional
:param _return_http_data_only: response data instead of ApiResponse
object with status code, headers, etc
:type _return_http_data_only: bool, optional
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the authentication
in the spec for a single request.
:type _request_auth: dict, optional
:type _content_type: string, optional: force content-type for the request
:return: Returns the result object.
If the method is called asynchronously,
returns the request thread.
:rtype: None
"""

_params = locals()

_all_params = ["room_id", "subscription_config"]
_all_params.extend(
[
"async_req",
"_return_http_data_only",
"_preload_content",
"_request_timeout",
"_request_auth",
"_content_type",
"_headers",
]
)

# validate the arguments
for _key, _val in _params["kwargs"].items():
if _key not in _all_params:
raise ApiTypeError(
"Got an unexpected keyword argument '%s'"
" to method subscribe_tracks" % _key
)
_params[_key] = _val
del _params["kwargs"]

_collection_formats = {}

# process the path parameters
_path_params = {}
if _params["room_id"]:
_path_params["room_id"] = _params["room_id"]

# process the query parameters
_query_params = []
# process the header parameters
_header_params = dict(_params.get("_headers", {}))
# process the form parameters
_form_params = []
_files = {}
# process the body parameter
_body_params = None
if _params["subscription_config"] is not None:
_body_params = _params["subscription_config"]

# set the HTTP header `Accept`
_header_params["Accept"] = self.api_client.select_header_accept(
["application/json"]
) # noqa: E501

# set the HTTP header `Content-Type`
_content_types_list = _params.get(
"_content_type",
self.api_client.select_header_content_type(["application/json"]),
)
if _content_types_list:
_header_params["Content-Type"] = _content_types_list

# authentication setting
_auth_settings = ["authorization"] # noqa: E501

_response_types_map = {}

return self.api_client.call_api(
"/hls/{room_id}/subscribe",
"POST",
_path_params,
_query_params,
_header_params,
body=_body_params,
post_params=_form_params,
files=_files,
response_types_map=_response_types_map,
auth_settings=_auth_settings,
async_req=_params.get("async_req"),
_return_http_data_only=_params.get("_return_http_data_only"), # noqa: E501
_preload_content=_params.get("_preload_content", True),
_request_timeout=_params.get("_request_timeout"),
collection_formats=_collection_formats,
_request_auth=_params.get("_request_auth"),
)
5 changes: 5 additions & 0 deletions jellyfish/_openapi_client/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
from jellyfish._openapi_client.models.component_metadata_hls import ComponentMetadataHLS
from jellyfish._openapi_client.models.component_options import ComponentOptions
from jellyfish._openapi_client.models.component_options_hls import ComponentOptionsHLS
from jellyfish._openapi_client.models.component_options_hlss3 import (
ComponentOptionsHLSS3,
)
from jellyfish._openapi_client.models.component_options_rtsp import ComponentOptionsRTSP
from jellyfish._openapi_client.models.component_rtsp import ComponentRTSP
from jellyfish._openapi_client.models.error import Error
Expand All @@ -44,3 +47,5 @@
)
from jellyfish._openapi_client.models.room_details_response import RoomDetailsResponse
from jellyfish._openapi_client.models.rooms_listing_response import RoomsListingResponse
from jellyfish._openapi_client.models.s3_credentials import S3Credentials
from jellyfish._openapi_client.models.subscription_config import SubscriptionConfig
23 changes: 21 additions & 2 deletions jellyfish/_openapi_client/models/component_metadata_hls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


from typing import Optional
from pydantic import BaseModel, Field, StrictBool, StrictInt
from pydantic import BaseModel, Field, StrictBool, StrictInt, StrictStr, validator


class ComponentMetadataHLS(BaseModel):
Expand All @@ -34,12 +34,30 @@ class ComponentMetadataHLS(BaseModel):
playable: StrictBool = Field(
..., description="Whether the generated HLS playlist is playable"
)
subscribe_mode: StrictStr = Field(
...,
alias="subscribeMode",
description="Whether the HLS component should subscribe to tracks automatically or manually",
)
target_window_duration: Optional[StrictInt] = Field(
...,
alias="targetWindowDuration",
description="Duration of stream available for viewer",
)
__properties = ["lowLatency", "persistent", "playable", "targetWindowDuration"]
__properties = [
"lowLatency",
"persistent",
"playable",
"subscribeMode",
"targetWindowDuration",
]

@validator("subscribe_mode")
def subscribe_mode_validate_enum(cls, value):
"""Validates the enum"""
if value not in ("auto", "manual"):
raise ValueError("must be one of enum values ('auto', 'manual')")
return value

class Config:
"""Pydantic configuration"""
Expand Down Expand Up @@ -87,6 +105,7 @@ def from_dict(cls, obj: dict) -> ComponentMetadataHLS:
"low_latency": obj.get("lowLatency"),
"persistent": obj.get("persistent"),
"playable": obj.get("playable"),
"subscribe_mode": obj.get("subscribeMode"),
"target_window_duration": obj.get("targetWindowDuration"),
}
)
Expand Down
Loading

0 comments on commit bf9267d

Please sign in to comment.