Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/selkies/webrtc/rtcconfiguration.py: 97%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

38 statements  

1# This Source Code Form is subject to the terms of the Mozilla Public 

2# License, v. 2.0. If a copy of the MPL was not distributed with this 

3# file, You can obtain one at https://mozilla.org/MPL/2.0/. 

4# 

5# This file incorporates work covered by the following copyright and 

6# permission notice: 

7# 

8# Copyright (c) Jeremy Lainé. 

9# All rights reserved. 

10# 

11# Redistribution and use in source and binary forms, with or without 

12# modification, are permitted provided that the following conditions are met: 

13# 

14# * Redistributions of source code must retain the above copyright notice, 

15# this list of conditions and the following disclaimer. 

16# * Redistributions in binary form must reproduce the above copyright notice, 

17# this list of conditions and the following disclaimer in the documentation 

18# and/or other materials provided with the distribution. 

19# * Neither the name of aiortc nor the names of its contributors may 

20# be used to endorse or promote products derived from this software without 

21# specific prior written permission. 

22# 

23# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 

24# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 

25# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 

26# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 

27# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 

28# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 

29# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 

30# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 

31# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 

32# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

33 

34import enum 

35from dataclasses import dataclass 

36from typing import Any, Optional, Union 

37 

38 

39@dataclass 

40class RTCIceServer: 

41 """ 

42 The :class:`RTCIceServer` dictionary defines how to connect to a single 

43 STUN or TURN server. It includes both the URL and the necessary credentials, 

44 if any, to connect to the server. 

45 """ 

46 

47 urls: Union[str, list[str]] 

48 """ 

49 This required property is either a single string or a list of strings, 

50 each specifying a URL which can be used to connect to the server. 

51 """ 

52 username: Optional[str] = None 

53 "The username to use during authentication (for TURN only)." 

54 credential: Optional[str] = None 

55 "The credential to use during authentication (for TURN only)." 

56 credentialType: str = "password" 

57 

58 

59class RTCBundlePolicy(enum.Enum): 

60 """ 

61 The :class:`RTCBundlePolicy` affects which media tracks are negotiated if 

62 the remote endpoint is not bundle-aware, and what ICE candidates are 

63 gathered. 

64 

65 See https://w3c.github.io/webrtc-pc/#rtcbundlepolicy-enum 

66 """ 

67 

68 BALANCED = "balanced" 

69 """ 

70 Gather ICE candidates for each media type in use (audio, video, and data). 

71 If the remote endpoint is not bundle-aware, negotiate only one audio and 

72 video track on separate transports. 

73 """ 

74 

75 MAX_COMPAT = "max-compat" 

76 """ 

77 Gather ICE candidates for each track. If the remote endpoint is not 

78 bundle-aware, negotiate all media tracks on separate transports. 

79 """ 

80 

81 MAX_BUNDLE = "max-bundle" 

82 """ 

83 Gather ICE candidates for only one track. If the remote endpoint is not 

84 bundle-aware, negotiate only one media track. 

85 """ 

86 

87 

88@dataclass 

89class RTCConfiguration: 

90 """ 

91 The :class:`RTCConfiguration` dictionary is used to provide configuration 

92 options for an :class:`RTCPeerConnection`. 

93 """ 

94 

95 iceServers: Optional[list[RTCIceServer]] = None 

96 "A list of :class:`RTCIceServer` objects to configure STUN / TURN servers." 

97 

98 bundlePolicy: RTCBundlePolicy = RTCBundlePolicy.BALANCED 

99 "The media-bundling policy to use when gathering ICE candidates." 

100 

101 alwaysNegotiateDataChannels: bool = False 

102 "Whether to always negotiate data channels in the SDP." 

103 

104 iceHostPublicIps: Optional[list[str]] = None 

105 "Public IPv4/IPv6 addresses to advertise in host ICE candidates (static 1:1 NAT)." 

106 

107 icePortRange: Optional[tuple[int, int]] = None 

108 "Inclusive UDP port range confining the sockets behind host ICE candidates." 

109 

110 iceUdpMux: Optional[Any] = None 

111 "Shared UDP sockets (`ice.UdpMux`) every peer's host candidates ride, or None for sockets per peer." 

112 

113 iceTcpMux: Optional[Any] = None 

114 "Shared TCP listeners (`ice.TcpMux`) adding a passive ICE-TCP host candidate per address." 

115 

116 iceLite: bool = False 

117 "Gather host candidates only and leave the connectivity checks to the peer (ICE-lite)."