diff --git a/livekit/api/__init__.py b/livekit/api/__init__.py new file mode 100644 index 00000000..8b77afc7 --- /dev/null +++ b/livekit/api/__init__.py @@ -0,0 +1,18 @@ +# Copyright 2023 LiveKit, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""LiveKit Server SDK +""" + +from .version import __version__ diff --git a/livekit/api/access_token.py b/livekit/api/access_token.py new file mode 100644 index 00000000..96f117e9 --- /dev/null +++ b/livekit/api/access_token.py @@ -0,0 +1,112 @@ +# Copyright 2023 LiveKit, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import calendar +import dataclasses +import datetime + +import jwt + +DEFAULT_TTL = datetime.timedelta(hours=6) + + +@dataclasses.dataclass +class VideoGrants: + # actions on rooms + room_create: bool = False + room_list: bool = False + room_record: bool = False + + # actions on a particular room + room_admin: bool = False + room_join: bool = False + room: str = "" + + # permissions within a room + can_publish: bool = True + can_subscribe: bool = True + can_publish_data: bool = True + + # TrackSource types that a participant may publish. + # When set, it supercedes CanPublish. Only sources explicitly set here can be + # published + can_publish_sources: list[str] = [] # keys keep track of each source + + # by default, a participant is not allowed to update its own metadata + can_update_own_metadata: bool = False + + # actions on ingresses + ingress_admin: bool = False # applies to all ingress + + # participant is not visible to other participants (useful when making bots) + hidden: bool = False + + # indicates to the room that current participant is a recorder + recorder: bool = False + + +@dataclasses.dataclass +class Claims: + name: str = "" + video: VideoGrants = dataclasses.field(default_factory=VideoGrants) + metadata: str = "" + sha256: str = "" + + +class AccessToken: + def __init__(self, api_key: str, api_secret: str): + self.api_key = api_key # iss + self.api_secret = api_secret + self.claims = Claims() + + # default jwt claims + self.identity = "" # sub + self.ttl = DEFAULT_TTL # exp + + def with_ttl(self, ttl: datetime.timedelta) -> 'AccessToken': + self.ttl = ttl + return self + + def with_grants(self, grants: VideoGrants) -> 'AccessToken': + self.claims.video = grants + return self + + def with_identity(self, identity: str) -> 'AccessToken': + self.identity = identity + return self + + def with_name(self, name: str) -> 'AccessToken': + self.claims.name = name + return self + + def with_metadata(self, metadata: str) -> 'AccessToken': + self.claims.metadata = metadata + return self + + def with_sha256(self, sha256: str) -> 'AccessToken': + self.claims.sha256 = sha256 + return self + + def to_jwt(self) -> str: + claims = { + 'sub': self.identity, + "iss": self.api_key, + "nbf": calendar.timegm(datetime.datetime.utcnow().utctimetuple()), + "exp": calendar.timegm( + (datetime.datetime.utcnow() + self.ttl).utctimetuple() + ), + } + + claims.update(dataclasses.asdict(self.claims)) + return jwt.encode(claims, self.api_secret, algorithm='HS256') diff --git a/livekit/api/version.py b/livekit/api/version.py new file mode 100644 index 00000000..f102a9ca --- /dev/null +++ b/livekit/api/version.py @@ -0,0 +1 @@ +__version__ = "0.0.1" diff --git a/livekit/__init__.py b/livekit/rtc/__init__.py similarity index 100% rename from livekit/__init__.py rename to livekit/rtc/__init__.py diff --git a/livekit/_ffi_client.py b/livekit/rtc/_ffi_client.py similarity index 100% rename from livekit/_ffi_client.py rename to livekit/rtc/_ffi_client.py diff --git a/livekit/_proto/__init__.py b/livekit/rtc/_proto/__init__.py similarity index 100% rename from livekit/_proto/__init__.py rename to livekit/rtc/_proto/__init__.py diff --git a/livekit/_proto/audio_frame_pb2.py b/livekit/rtc/_proto/audio_frame_pb2.py similarity index 100% rename from livekit/_proto/audio_frame_pb2.py rename to livekit/rtc/_proto/audio_frame_pb2.py diff --git a/livekit/_proto/audio_frame_pb2.pyi b/livekit/rtc/_proto/audio_frame_pb2.pyi similarity index 100% rename from livekit/_proto/audio_frame_pb2.pyi rename to livekit/rtc/_proto/audio_frame_pb2.pyi diff --git a/livekit/_proto/e2ee_pb2.py b/livekit/rtc/_proto/e2ee_pb2.py similarity index 100% rename from livekit/_proto/e2ee_pb2.py rename to livekit/rtc/_proto/e2ee_pb2.py diff --git a/livekit/_proto/e2ee_pb2.pyi b/livekit/rtc/_proto/e2ee_pb2.pyi similarity index 100% rename from livekit/_proto/e2ee_pb2.pyi rename to livekit/rtc/_proto/e2ee_pb2.pyi diff --git a/livekit/_proto/ffi_pb2.py b/livekit/rtc/_proto/ffi_pb2.py similarity index 100% rename from livekit/_proto/ffi_pb2.py rename to livekit/rtc/_proto/ffi_pb2.py diff --git a/livekit/_proto/ffi_pb2.pyi b/livekit/rtc/_proto/ffi_pb2.pyi similarity index 100% rename from livekit/_proto/ffi_pb2.pyi rename to livekit/rtc/_proto/ffi_pb2.pyi diff --git a/livekit/_proto/handle_pb2.py b/livekit/rtc/_proto/handle_pb2.py similarity index 100% rename from livekit/_proto/handle_pb2.py rename to livekit/rtc/_proto/handle_pb2.py diff --git a/livekit/_proto/handle_pb2.pyi b/livekit/rtc/_proto/handle_pb2.pyi similarity index 100% rename from livekit/_proto/handle_pb2.pyi rename to livekit/rtc/_proto/handle_pb2.pyi diff --git a/livekit/_proto/participant_pb2.py b/livekit/rtc/_proto/participant_pb2.py similarity index 100% rename from livekit/_proto/participant_pb2.py rename to livekit/rtc/_proto/participant_pb2.py diff --git a/livekit/_proto/participant_pb2.pyi b/livekit/rtc/_proto/participant_pb2.pyi similarity index 100% rename from livekit/_proto/participant_pb2.pyi rename to livekit/rtc/_proto/participant_pb2.pyi diff --git a/livekit/_proto/room_pb2.py b/livekit/rtc/_proto/room_pb2.py similarity index 100% rename from livekit/_proto/room_pb2.py rename to livekit/rtc/_proto/room_pb2.py diff --git a/livekit/_proto/room_pb2.pyi b/livekit/rtc/_proto/room_pb2.pyi similarity index 100% rename from livekit/_proto/room_pb2.pyi rename to livekit/rtc/_proto/room_pb2.pyi diff --git a/livekit/_proto/track_pb2.py b/livekit/rtc/_proto/track_pb2.py similarity index 100% rename from livekit/_proto/track_pb2.py rename to livekit/rtc/_proto/track_pb2.py diff --git a/livekit/_proto/track_pb2.pyi b/livekit/rtc/_proto/track_pb2.pyi similarity index 100% rename from livekit/_proto/track_pb2.pyi rename to livekit/rtc/_proto/track_pb2.pyi diff --git a/livekit/_proto/video_frame_pb2.py b/livekit/rtc/_proto/video_frame_pb2.py similarity index 100% rename from livekit/_proto/video_frame_pb2.py rename to livekit/rtc/_proto/video_frame_pb2.py diff --git a/livekit/_proto/video_frame_pb2.pyi b/livekit/rtc/_proto/video_frame_pb2.pyi similarity index 100% rename from livekit/_proto/video_frame_pb2.pyi rename to livekit/rtc/_proto/video_frame_pb2.pyi diff --git a/livekit/_utils.py b/livekit/rtc/_utils.py similarity index 100% rename from livekit/_utils.py rename to livekit/rtc/_utils.py diff --git a/livekit/audio_frame.py b/livekit/rtc/audio_frame.py similarity index 100% rename from livekit/audio_frame.py rename to livekit/rtc/audio_frame.py diff --git a/livekit/audio_source.py b/livekit/rtc/audio_source.py similarity index 100% rename from livekit/audio_source.py rename to livekit/rtc/audio_source.py diff --git a/livekit/audio_stream.py b/livekit/rtc/audio_stream.py similarity index 100% rename from livekit/audio_stream.py rename to livekit/rtc/audio_stream.py diff --git a/livekit/e2ee.py b/livekit/rtc/e2ee.py similarity index 100% rename from livekit/e2ee.py rename to livekit/rtc/e2ee.py diff --git a/livekit/participant.py b/livekit/rtc/participant.py similarity index 100% rename from livekit/participant.py rename to livekit/rtc/participant.py diff --git a/livekit/resources/.gitignore b/livekit/rtc/resources/.gitignore similarity index 100% rename from livekit/resources/.gitignore rename to livekit/rtc/resources/.gitignore diff --git a/livekit/room.py b/livekit/rtc/room.py similarity index 100% rename from livekit/room.py rename to livekit/rtc/room.py diff --git a/livekit/track.py b/livekit/rtc/track.py similarity index 100% rename from livekit/track.py rename to livekit/rtc/track.py diff --git a/livekit/track_publication.py b/livekit/rtc/track_publication.py similarity index 97% rename from livekit/track_publication.py rename to livekit/rtc/track_publication.py index 0ff344f5..4306794c 100644 --- a/livekit/track_publication.py +++ b/livekit/rtc/track_publication.py @@ -14,11 +14,10 @@ from typing import Optional -from livekit._proto import track_pb2 as proto_track - from ._ffi_client import FfiHandle, ffi_client from ._proto import e2ee_pb2 as proto_e2ee from ._proto import ffi_pb2 as proto_ffi +from ._proto import track_pb2 as proto_track from .track import Track diff --git a/livekit/version.py b/livekit/rtc/version.py similarity index 100% rename from livekit/version.py rename to livekit/rtc/version.py diff --git a/livekit/video_frame.py b/livekit/rtc/video_frame.py similarity index 100% rename from livekit/video_frame.py rename to livekit/rtc/video_frame.py diff --git a/livekit/video_source.py b/livekit/rtc/video_source.py similarity index 100% rename from livekit/video_source.py rename to livekit/rtc/video_source.py diff --git a/livekit/video_stream.py b/livekit/rtc/video_stream.py similarity index 100% rename from livekit/video_stream.py rename to livekit/rtc/video_stream.py diff --git a/setup_api.py b/setup_api.py new file mode 100644 index 00000000..f86cf14f --- /dev/null +++ b/setup_api.py @@ -0,0 +1,58 @@ +# Copyright 2023 LiveKit, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import pathlib + +import setuptools + +here = pathlib.Path(__file__).parent.resolve() +about = {} +with open(os.path.join(here, 'livekit', 'api', 'version.py'), 'r') as f: + exec(f.read(), about) + + +setuptools.setup( + name="livekit-api", + version=about['__version__'], + description="LiveKit Python Server for LiveKit", + long_description=(here / "README.md").read_text(encoding="utf-8"), + long_description_content_type="text/markdown", + url="https://github.com/livekit/client-sdk-python", + classifiers=[ + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Topic :: Multimedia :: Sound/Audio", + "Topic :: Multimedia :: Video", + "Topic :: Scientific/Engineering :: Artificial Intelligence", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3 :: Only", + ], + keywords=["webrtc", "realtime", "audio", "video", "livekit"], + license="Apache-2.0", + packages=["livekit"], + python_requires=">=3.7.0", + install_requires=["pyjwt>=2.0.0", + "protobuf>=3.1.0", + "types-protobuf>=3.1.0"], + project_urls={ + "Documentation": "https://docs.livekit.io", + "Website": "https://livekit.io/", + "Source": "https://github.com/livekit/client-sdk-python/", + }, +) diff --git a/setup.py b/setup_rtc.py similarity index 100% rename from setup.py rename to setup_rtc.py