Skip to content

Commit

Permalink
v0.4.2 (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom authored Sep 21, 2023
1 parent 27e0963 commit 15000d5
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 126 deletions.
2 changes: 1 addition & 1 deletion client-sdk-rust
18 changes: 14 additions & 4 deletions examples/publish_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
NUM_CHANNELS = 1


async def publish_frames(source: livekit.AudioSource):
frequency = 440
async def publish_frames(source: livekit.AudioSource, frequency: int):
amplitude = 32767 # for 16-bit audio
samples_per_channel = 480 # 10ms at 48kHz
time = np.arange(samples_per_channel) / SAMPLE_RATE
Expand All @@ -38,9 +37,20 @@ async def publish_frames(source: livekit.AudioSource):


async def main(room: livekit.Room) -> None:

@room.on("participant_disconnected")
def on_participant_disconnect(participant: livekit.Participant, *_):
logging.info("participant disconnected: %s", participant.identity)

logging.info("connecting to %s", URL)
try:
await room.connect(URL, TOKEN)
e2ee_options = livekit.E2EEOptions()
e2ee_options.key_provider_options.shared_key = b"password"

await room.connect(URL, TOKEN, options=livekit.RoomOptions(
auto_subscribe=True,
e2ee=e2ee_options
))
logging.info("connected to room %s", room.name)
except livekit.ConnectError as e:
logging.error("failed to connect to the room: %s", e)
Expand All @@ -54,7 +64,7 @@ async def main(room: livekit.Room) -> None:
publication = await room.local_participant.publish_track(track, options)
logging.info("published track %s", publication.sid)

asyncio.ensure_future(publish_frames(source))
asyncio.ensure_future(publish_frames(source, 440))


if __name__ == "__main__":
Expand Down
104 changes: 52 additions & 52 deletions livekit/_proto/e2ee_pb2.py

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions livekit/_proto/e2ee_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,23 @@ class KeyProviderOptions(google.protobuf.message.Message):
SHARED_KEY_FIELD_NUMBER: builtins.int
RATCHET_WINDOW_SIZE_FIELD_NUMBER: builtins.int
RATCHET_SALT_FIELD_NUMBER: builtins.int
UNCRYPTED_MAGIC_BYTES_FIELD_NUMBER: builtins.int
FAILURE_TOLERANCE_FIELD_NUMBER: builtins.int
shared_key: builtins.bytes
"""Only specify if you want to use a shared_key"""
ratchet_window_size: builtins.int
ratchet_salt: builtins.bytes
uncrypted_magic_bytes: builtins.bytes
failure_tolerance: builtins.int
"""-1 = no tolerence"""
def __init__(
self,
*,
shared_key: builtins.bytes | None = ...,
ratchet_window_size: builtins.int = ...,
ratchet_salt: builtins.bytes = ...,
uncrypted_magic_bytes: builtins.bytes = ...,
failure_tolerance: builtins.int = ...,
) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["_shared_key", b"_shared_key", "shared_key", b"shared_key"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["_shared_key", b"_shared_key", "ratchet_salt", b"ratchet_salt", "ratchet_window_size", b"ratchet_window_size", "shared_key", b"shared_key", "uncrypted_magic_bytes", b"uncrypted_magic_bytes"]) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["_shared_key", b"_shared_key", "failure_tolerance", b"failure_tolerance", "ratchet_salt", b"ratchet_salt", "ratchet_window_size", b"ratchet_window_size", "shared_key", b"shared_key"]) -> None: ...
def WhichOneof(self, oneof_group: typing_extensions.Literal["_shared_key", b"_shared_key"]) -> typing_extensions.Literal["shared_key"] | None: ...

global___KeyProviderOptions = KeyProviderOptions
Expand Down
124 changes: 65 additions & 59 deletions livekit/_proto/room_pb2.py

Large diffs are not rendered by default.

72 changes: 70 additions & 2 deletions livekit/_proto/room_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ else:

DESCRIPTOR: google.protobuf.descriptor.FileDescriptor

class _IceTransportPolicy:
ValueType = typing.NewType("ValueType", builtins.int)
V: typing_extensions.TypeAlias = ValueType

class _IceTransportPolicyEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_IceTransportPolicy.ValueType], builtins.type):
DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor
TRANSPORT_NONE: _IceTransportPolicy.ValueType # 0
TRANSPORT_RELAY: _IceTransportPolicy.ValueType # 1
TRANSPORT_NOHOST: _IceTransportPolicy.ValueType # 2
TRANSPORT_ALL: _IceTransportPolicy.ValueType # 3

class IceTransportPolicy(_IceTransportPolicy, metaclass=_IceTransportPolicyEnumTypeWrapper): ...

TRANSPORT_NONE: IceTransportPolicy.ValueType # 0
TRANSPORT_RELAY: IceTransportPolicy.ValueType # 1
TRANSPORT_NOHOST: IceTransportPolicy.ValueType # 2
TRANSPORT_ALL: IceTransportPolicy.ValueType # 3
global___IceTransportPolicy = IceTransportPolicy

class _ConnectionQuality:
ValueType = typing.NewType("ValueType", builtins.int)
V: typing_extensions.TypeAlias = ValueType
Expand Down Expand Up @@ -521,6 +540,47 @@ class TrackPublishOptions(google.protobuf.message.Message):

global___TrackPublishOptions = TrackPublishOptions

@typing_extensions.final
class IceServer(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

URLS_FIELD_NUMBER: builtins.int
USERNAME_FIELD_NUMBER: builtins.int
CREDENTIAL_FIELD_NUMBER: builtins.int
@property
def urls(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.str]: ...
username: builtins.str
credential: builtins.str
def __init__(
self,
*,
urls: collections.abc.Iterable[builtins.str] | None = ...,
username: builtins.str = ...,
credential: builtins.str = ...,
) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["credential", b"credential", "urls", b"urls", "username", b"username"]) -> None: ...

global___IceServer = IceServer

@typing_extensions.final
class RtcConfig(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor

ICE_TRANSPORT_POLICY_FIELD_NUMBER: builtins.int
ICE_SERVERS_FIELD_NUMBER: builtins.int
ice_transport_policy: global___IceTransportPolicy.ValueType
@property
def ice_servers(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___IceServer]: ...
def __init__(
self,
*,
ice_transport_policy: global___IceTransportPolicy.ValueType = ...,
ice_servers: collections.abc.Iterable[global___IceServer] | None = ...,
) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["ice_servers", b"ice_servers", "ice_transport_policy", b"ice_transport_policy"]) -> None: ...

global___RtcConfig = RtcConfig

@typing_extensions.final
class RoomOptions(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor
Expand All @@ -529,22 +589,30 @@ class RoomOptions(google.protobuf.message.Message):
ADAPTIVE_STREAM_FIELD_NUMBER: builtins.int
DYNACAST_FIELD_NUMBER: builtins.int
E2EE_FIELD_NUMBER: builtins.int
RTC_CONFIG_FIELD_NUMBER: builtins.int
auto_subscribe: builtins.bool
adaptive_stream: builtins.bool
dynacast: builtins.bool
@property
def e2ee(self) -> e2ee_pb2.E2eeOptions: ...
@property
def rtc_config(self) -> global___RtcConfig:
"""allow to setup a custom RtcConfiguration"""
def __init__(
self,
*,
auto_subscribe: builtins.bool = ...,
adaptive_stream: builtins.bool = ...,
dynacast: builtins.bool = ...,
e2ee: e2ee_pb2.E2eeOptions | None = ...,
rtc_config: global___RtcConfig | None = ...,
) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["_e2ee", b"_e2ee", "e2ee", b"e2ee"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["_e2ee", b"_e2ee", "adaptive_stream", b"adaptive_stream", "auto_subscribe", b"auto_subscribe", "dynacast", b"dynacast", "e2ee", b"e2ee"]) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["_e2ee", b"_e2ee", "_rtc_config", b"_rtc_config", "e2ee", b"e2ee", "rtc_config", b"rtc_config"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["_e2ee", b"_e2ee", "_rtc_config", b"_rtc_config", "adaptive_stream", b"adaptive_stream", "auto_subscribe", b"auto_subscribe", "dynacast", b"dynacast", "e2ee", b"e2ee", "rtc_config", b"rtc_config"]) -> None: ...
@typing.overload
def WhichOneof(self, oneof_group: typing_extensions.Literal["_e2ee", b"_e2ee"]) -> typing_extensions.Literal["e2ee"] | None: ...
@typing.overload
def WhichOneof(self, oneof_group: typing_extensions.Literal["_rtc_config", b"_rtc_config"]) -> typing_extensions.Literal["rtc_config"] | None: ...

global___RoomOptions = RoomOptions

Expand Down
4 changes: 2 additions & 2 deletions livekit/e2ee.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
from ._proto import ffi_pb2 as proto_ffi

DEFAULT_RATCHET_SALT = b"LKFrameEncryptionKey"
DEFAULT_MAGIC_BYTES = b"LK-ROCKS"
DEFAULT_RATCHET_WINDOW_SIZE = 16
DEFAULT_FAILURE_TOLERANCE = -1


@dataclass
class KeyProviderOptions:
shared_key: Optional[bytes] = None
ratchet_salt: bytes = DEFAULT_RATCHET_SALT
uncrypted_magic_bytes: bytes = DEFAULT_MAGIC_BYTES
ratchet_window_size: int = DEFAULT_RATCHET_WINDOW_SIZE
failure_tolerance: int = DEFAULT_FAILURE_TOLERANCE


@dataclass
Expand Down
4 changes: 2 additions & 2 deletions livekit/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ async def connect(self,
options.e2ee.key_provider_options.shared_key # type: ignore
req.connect.options.e2ee.key_provider_options.ratchet_salt = \
options.e2ee.key_provider_options.ratchet_salt
req.connect.options.e2ee.key_provider_options.uncrypted_magic_bytes = \
options.e2ee.key_provider_options.uncrypted_magic_bytes
req.connect.options.e2ee.key_provider_options.failure_tolerance = \
options.e2ee.key_provider_options.failure_tolerance
req.connect.options.e2ee.key_provider_options.ratchet_window_size = \
options.e2ee.key_provider_options.ratchet_window_size

Expand Down

0 comments on commit 15000d5

Please sign in to comment.