Skip to content

Commit ff03147

Browse files
committed
add individual streams option to Dial API, add missing methods and values
1 parent e942db6 commit ff03147

File tree

3 files changed

+32
-54
lines changed

3 files changed

+32
-54
lines changed

README.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ Your application server can disconnect a client from an OpenTok session by calli
386386
Working with SIP Interconnect
387387
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
388388

389-
You can connect your SIP platform to an OpenTok session, the audio from your end of the SIP call is added to the OpenTok session as an audio-only stream. The OpenTok Media Router mixes audio from other streams in the session and sends the mixed audio to your SIP endpoint.
389+
You can connect your SIP platform to an OpenTok session, the audio from your end of the SIP call is added to the OpenTok session as an audio-only stream.
390+
The OpenTok Media Router mixes audio from other streams in the session and sends the mixed audio to your SIP endpoint.
390391

391392
.. code:: python
392393
@@ -397,8 +398,7 @@ You can connect your SIP platform to an OpenTok session, the audio from your end
397398
# call the method with the required parameters
398399
sip_call = opentok.dial(session_id, token, sip_uri)
399400
400-
# the method also support aditional options to establish the sip call
401-
401+
# the method also supports aditional options to establish the sip call
402402
options = {
403403
'from': '[email protected]',
404404
'headers': {
@@ -408,7 +408,10 @@ You can connect your SIP platform to an OpenTok session, the audio from your end
408408
'username': 'username',
409409
'password': 'password'
410410
},
411-
'secure': True
411+
'secure': True,
412+
'video': True,
413+
'observeForceMute': True,
414+
'streams': ['stream-id-1', 'stream-id-2']
412415
}
413416
414417
# call the method with aditional options

opentok/opentok.py

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ def set_archive_layout(self, archive_id, layout_type, stylesheet=None, screensha
11411141
else:
11421142
raise RequestError("OpenTok server error.", response.status_code)
11431143

1144-
def dial(self, session_id, token, sip_uri, options=[]):
1144+
def dial(self, session_id, token, sip_uri, options={}):
11451145
"""
11461146
Use this method to connect a SIP platform to an OpenTok session. The audio from the end
11471147
of the SIP call is added to the OpenTok session as an audio-only stream. The OpenTok Media
@@ -1184,27 +1184,30 @@ def dial(self, session_id, token, sip_uri, options=[]):
11841184
in the OpenTok stream that is sent to the OpenTok session. The SIP client will receive a single
11851185
composed video of the published streams in the OpenTok session.
11861186
1187-
This is an example of what the payload POST data body could look like:
1187+
List 'streams': An array of stream IDs for streams to include in the SIP call.
1188+
If you do not set this property, all streams in the session are included in the call.
1189+
1190+
This is an example of what the payload POST data dictionary could look like:
11881191
11891192
{
11901193
"sessionId": "Your OpenTok session ID",
11911194
"token": "Your valid OpenTok token",
11921195
"sip": {
1193-
"uri": "sip:[email protected];transport=tls",
1194-
"from": "[email protected]",
1195-
"headers": {
1196-
"headerKey": "headerValue"
1197-
},
1196+
"uri": "sip:[email protected];transport=tls",
1197+
"from": "[email protected]",
1198+
"headers": {
1199+
"headerKey": "headerValue"
1200+
},
11981201
"auth": {
11991202
"username": "username",
12001203
"password": "password"
12011204
},
1202-
"secure": true|false,
1203-
"observeForceMute": true|false,
1204-
"video": true|false
1205-
}
1205+
"secure": True,
1206+
"video": True,
1207+
"observeForceMute": True,
1208+
"streams": ["stream-id-1", "stream-id-2"]
12061209
}
1207-
1210+
}
12081211
12091212
:rtype: A SipCall object, which contains data of the SIP call: id, connectionId and streamId.
12101213
This is what the response body should look like after returning with a status code of 200:
@@ -1217,29 +1220,9 @@ def dial(self, session_id, token, sip_uri, options=[]):
12171220
12181221
Note: Your response will have a different: id, connectionId and streamId
12191222
"""
1220-
payload = {"sessionId": session_id, "token": token, "sip": {"uri": sip_uri}}
1221-
observeForceMute = False
1222-
video = False
1223-
1224-
if "from" in options:
1225-
payload["sip"]["from"] = options["from"]
1226-
1227-
if "headers" in options:
1228-
payload["sip"]["headers"] = options["headers"]
12291223

1230-
if "auth" in options:
1231-
payload["sip"]["auth"] = options["auth"]
1232-
1233-
if "secure" in options:
1234-
payload["sip"]["secure"] = options["secure"]
1235-
1236-
if "observeForceMute" in options:
1237-
observeForceMute = True
1238-
payload["sip"]["observeForceMute"] = options["observeForceMute"]
1239-
1240-
if "video" in options:
1241-
video = True
1242-
payload["sip"]["video"] = options["video"]
1224+
payload = {"sessionId": session_id, "token": token, "sip": {"uri": sip_uri}}
1225+
payload.update(options)
12431226

12441227
endpoint = self.endpoints.dial_url()
12451228

tests/test_sip_call.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,10 @@ def test_sip_call_with_required_parameters(self):
5555
expect(httpretty.last_request().headers[u("user-agent")]).to(
5656
contain(u("OpenTok-Python-SDK/") + __version__)
5757
)
58-
expect(httpretty.last_request().headers[u("content-type")]).to(
59-
equal(u("application/json"))
60-
)
58+
expect(httpretty.last_request().headers[u("content-type")]).to(equal(u("application/json")))
6159
expect(sip_call_response).to(be_an(SipCall))
6260
expect(sip_call_response).to(have_property(u("id"), sip_call.id))
63-
expect(sip_call_response).to(
64-
have_property(u("connectionId"), sip_call.connectionId)
65-
)
61+
expect(sip_call_response).to(have_property(u("connectionId"), sip_call.connectionId))
6662
expect(sip_call_response).to(have_property(u("streamId"), sip_call.streamId))
6763

6864
@httpretty.activate
@@ -103,22 +99,18 @@ def test_sip_call_with_aditional_options(self):
10399
"auth": {"username": "username", "password": "password"},
104100
"secure": True,
105101
"observeForceMute": True,
106-
"video": True
102+
"video": True,
103+
"streams": ["stream-id-1", "stream-id-2"],
107104
}
108105

109-
sip_call_response = self.opentok.dial(
110-
self.session_id, self.token, self.sip_uri, options
111-
)
106+
sip_call_response = self.opentok.dial(self.session_id, self.token, self.sip_uri, options)
112107
validate_jwt_header(self, httpretty.last_request().headers[u("x-opentok-auth")])
113108
expect(httpretty.last_request().headers[u("user-agent")]).to(
114109
contain(u("OpenTok-Python-SDK/") + __version__)
115110
)
116-
expect(httpretty.last_request().headers[u("content-type")]).to(
117-
equal(u("application/json"))
118-
)
111+
expect(httpretty.last_request().headers[u("content-type")]).to(equal(u("application/json")))
119112
expect(sip_call_response).to(be_an(SipCall))
120113
expect(sip_call_response).to(have_property(u("id"), sip_call.id))
121-
expect(sip_call_response).to(
122-
have_property(u("connectionId"), sip_call.connectionId)
123-
)
114+
expect(sip_call_response).to(have_property(u("connectionId"), sip_call.connectionId))
124115
expect(sip_call_response).to(have_property(u("streamId"), sip_call.streamId))
116+
assert b'"streams": ["stream-id-1", "stream-id-2"]}' in httpretty.last_request().body

0 commit comments

Comments
 (0)