3
3
from pydantic import validate_call
4
4
from vonage_http_client .http_client import HttpClient
5
5
from vonage_video .models .session import SessionOptions , VideoSession
6
+ from vonage_video .models .signal import SignalData
6
7
from vonage_video .models .stream import StreamInfo , StreamLayoutOptions
7
8
from vonage_video .models .token import TokenOptions
8
9
@@ -44,7 +45,7 @@ def create_session(self, options: SessionOptions = None) -> VideoSession:
44
45
options (SessionOptions): The options for the session.
45
46
46
47
Returns:
47
- VideoSession: The new session.
48
+ VideoSession: The new session ID, plus the config options specified in `options` .
48
49
"""
49
50
50
51
response = self ._http_client .post (
@@ -61,25 +62,6 @@ def create_session(self, options: SessionOptions = None) -> VideoSession:
61
62
62
63
return VideoSession (** session_response )
63
64
64
- @validate_call
65
- def get_stream (self , session_id : str , stream_id : str ) -> StreamInfo :
66
- """Gets a stream from the Vonage Video API.
67
-
68
- Args:
69
- session_id (str): The session ID.
70
- stream_id (str): The stream ID.
71
-
72
- Returns:
73
- StreamInfo: Information about the video stream.
74
- """
75
-
76
- response = self ._http_client .get (
77
- self ._http_client .video_host ,
78
- f'/v2/project/{ self ._http_client .auth .application_id } /session/{ session_id } /stream/{ stream_id } ' ,
79
- )
80
-
81
- return StreamInfo (** response )
82
-
83
65
@validate_call
84
66
def list_streams (self , session_id : str ) -> List [StreamInfo ]:
85
67
"""Lists the streams in a session from the Vonage Video API.
@@ -99,22 +81,6 @@ def list_streams(self, session_id: str) -> List[StreamInfo]:
99
81
return [StreamInfo (** stream ) for stream in response ['items' ]]
100
82
101
83
@validate_call
102
- def change_stream_layout (
103
- self , session_id : str , stream_layout_options : StreamLayoutOptions
104
- ) -> None :
105
- """Changes the layout of a stream in a session in the Vonage Video API.
106
-
107
- Args:
108
- session_id (str): The session ID.
109
- stream_layout_options (StreamLayoutOptions): The options for the stream layout.
110
- """
111
-
112
- self ._http_client .put (
113
- self ._http_client .video_host ,
114
- f'/v2/project/{ self ._http_client .auth .application_id } /session/{ session_id } /stream' ,
115
- stream_layout_options .model_dump (by_alias = True , exclude_none = True ),
116
- )
117
-
118
84
def get_stream (self , session_id : str , stream_id : str ) -> StreamInfo :
119
85
"""Gets a stream from the Vonage Video API.
120
86
@@ -133,35 +99,47 @@ def get_stream(self, session_id: str, stream_id: str) -> StreamInfo:
133
99
134
100
return StreamInfo (** response )
135
101
136
- def list_streams (self , session_id : str ) -> List [StreamInfo ]:
137
- """Lists the streams in a session from the Vonage Video API.
102
+ @validate_call
103
+ def change_stream_layout (
104
+ self , session_id : str , stream_layout_options : StreamLayoutOptions
105
+ ) -> List [StreamInfo ]:
106
+ """Changes the layout of a stream in a session in the Vonage Video API.
138
107
139
108
Args:
140
109
session_id (str): The session ID.
110
+ stream_layout_options (StreamLayoutOptions): The options for the stream layout.
141
111
142
112
Returns:
143
113
List[StreamInfo]: Information about the video streams.
144
114
"""
145
115
146
- response = self ._http_client .get (
116
+ response = self ._http_client .put (
147
117
self ._http_client .video_host ,
148
118
f'/v2/project/{ self ._http_client .auth .application_id } /session/{ session_id } /stream' ,
119
+ stream_layout_options .model_dump (by_alias = True , exclude_none = True ),
149
120
)
150
121
151
122
return [StreamInfo (** stream ) for stream in response ['items' ]]
152
123
153
- def change_stream_layout (
154
- self , session_id : str , stream_layout_options : StreamLayoutOptions
124
+ @validate_call
125
+ def send_signal (
126
+ self , session_id : str , data : SignalData , connection_id : str = None
155
127
) -> None :
156
- """Changes the layout of a stream in a session in the Vonage Video API.
128
+ """Sends a signal to a session in the Vonage Video API. If `connection_id` is not provided,
129
+ the signal will be sent to all connections in the session.
157
130
158
131
Args:
159
132
session_id (str): The session ID.
160
- stream_layout_options (StreamLayoutOptions): The options for the stream layout.
133
+ data (SignalData): The data to send in the signal.
134
+ connection_id (str, Optional): The connection ID to send the signal to.
161
135
"""
162
-
163
- self ._http_client .put (
164
- self ._http_client .video_host ,
165
- f'/v2/project/{ self ._http_client .auth .application_id } /session/{ session_id } /stream' ,
166
- stream_layout_options .model_dump (by_alias = True , exclude_none = True ),
167
- )
136
+ if connection_id is not None :
137
+ url = f'/v2/project/{ self ._http_client .auth .application_id } /session/{ session_id } /connection/{ connection_id } /signal'
138
+ else :
139
+ url = (
140
+ f'/v2/project/{ self ._http_client .auth .application_id } /session/{ session_id } /signal' ,
141
+ )
142
+
143
+ self ._http_client .post (
144
+ self ._http_client .video_host , url , data .model_dump (exclude_none = True )
145
+ )
0 commit comments