@@ -34,11 +34,11 @@ class WebRTCCodec:
34
34
"""Codec for WebRTC protocol (empty protocol with no value)."""
35
35
SIZE = 0
36
36
IS_PATH = False
37
-
37
+
38
38
@staticmethod
39
39
def to_bytes (proto : Any , s : str ) -> bytes :
40
40
return b""
41
-
41
+
42
42
@staticmethod
43
43
def to_string (proto : Any , b : bytes ) -> str :
44
44
return ""
@@ -48,11 +48,11 @@ class WebRTCDirectCodec:
48
48
"""Codec for WebRTC-Direct protocol (empty protocol with no value)."""
49
49
SIZE = 0
50
50
IS_PATH = False
51
-
51
+
52
52
@staticmethod
53
53
def to_bytes (proto : Any , s : str ) -> bytes :
54
54
return b""
55
-
55
+
56
56
@staticmethod
57
57
def to_string (proto : Any , b : bytes ) -> str :
58
58
return ""
@@ -63,7 +63,7 @@ class CerthashCodec:
63
63
SIZE = - 1 # Variable size protocol
64
64
LENGTH_PREFIXED_VAR_SIZE = - 1
65
65
IS_PATH = False
66
-
66
+
67
67
@staticmethod
68
68
def to_bytes (proto : Any , s : str ) -> bytes :
69
69
if not s :
@@ -84,7 +84,7 @@ def to_bytes(proto: Any, s: str) -> bytes:
84
84
return base64 .urlsafe_b64decode (s_bytes )
85
85
except Exception :
86
86
return s .encode ('utf-8' )
87
-
87
+
88
88
@staticmethod
89
89
def to_string (proto : Any , b : bytes ) -> str :
90
90
if not b :
@@ -96,55 +96,55 @@ def to_string(proto: Any, b: bytes) -> str:
96
96
97
97
# Register WebRTC protocols with multiaddr
98
98
try :
99
-
99
+
100
100
# Create codec instances
101
101
webrtc_codec = WebRTCCodec ()
102
102
webrtc_direct_codec = WebRTCDirectCodec ()
103
103
certhash_codec = CerthashCodec ()
104
-
104
+
105
105
# Register codec modules for multiaddr
106
106
sys .modules ['multiaddr.codecs.webrtc' ] = webrtc_codec # type: ignore
107
107
sys .modules ['multiaddr.codecs.webrtc_direct' ] = webrtc_direct_codec # type: ignore
108
108
sys .modules ['multiaddr.codecs.certhash' ] = certhash_codec # type: ignore
109
-
109
+
110
110
setattr (codecs , 'webrtc' , webrtc_codec )
111
111
setattr (codecs , 'webrtc_direct' , webrtc_direct_codec )
112
112
setattr (codecs , 'certhash' , certhash_codec )
113
-
113
+
114
114
# Create Protocol objects with string codec names
115
115
webrtc_protocol = Protocol (
116
116
code = CODEC_WEBRTC ,
117
117
name = PROTOCOL_WEBRTC ,
118
- codec = "webrtc"
118
+ codec = "webrtc"
119
119
)
120
-
120
+
121
121
webrtc_direct_protocol = Protocol (
122
122
code = CODEC_WEBRTC_DIRECT ,
123
123
name = PROTOCOL_WEBRTC_DIRECT ,
124
- codec = "webrtc_direct"
124
+ codec = "webrtc_direct"
125
125
)
126
-
126
+
127
127
certhash_protocol = Protocol (
128
128
code = CODEC_CERTHASH ,
129
129
name = PROTOCOL_CERTHASH ,
130
- codec = "certhash"
130
+ codec = "certhash"
131
131
)
132
-
132
+
133
133
# Register protocols using the add_protocol function
134
134
protocols .add_protocol (webrtc_protocol )
135
135
protocols .add_protocol (webrtc_direct_protocol )
136
136
protocols .add_protocol (certhash_protocol )
137
-
137
+
138
138
print ("✅ WebRTC protocols registered with multiaddr" )
139
-
139
+
140
140
except ImportError as e :
141
141
print (f"⚠️ Failed to register WebRTC protocols: { e } " )
142
142
except Exception as e :
143
143
print (f"⚠️ Error registering WebRTC protocols: { e } " )
144
144
145
145
__all__ = [
146
146
"WebRTCTransport" ,
147
- "WebRTCDirectTransport" ,
147
+ "WebRTCDirectTransport" ,
148
148
"DEFAULT_ICE_SERVERS" ,
149
149
"SIGNALING_PROTOCOL" ,
150
150
"MUXER_PROTOCOL" ,
@@ -159,11 +159,11 @@ def to_string(proto: Any, b: bytes) -> str:
159
159
]
160
160
161
161
162
- def webrtc (config : Dict [str , Any ] | None = None ) -> WebRTCTransport :
162
+ def webrtc (config : dict [str , Any ] | None = None ) -> WebRTCTransport :
163
163
"""Create a WebRTC transport instance (private-to-private)."""
164
164
return WebRTCTransport (config )
165
165
166
166
167
- def webrtc_direct (config : Dict [str , Any ] | None = None ) -> WebRTCDirectTransport :
167
+ def webrtc_direct (config : dict [str , Any ] | None = None ) -> WebRTCDirectTransport :
168
168
"""Create a WebRTC-Direct transport instance (private-to-public)."""
169
- return WebRTCDirectTransport (config )
169
+ return WebRTCDirectTransport (config )
0 commit comments