Skip to content

Commit 9b98b44

Browse files
authored
Merge pull request #196 from opentok/selective_stream
Adding selective stream
2 parents 79acad6 + e40ed76 commit 9b98b44

File tree

13 files changed

+565
-28
lines changed

13 files changed

+565
-28
lines changed

.bumpversion.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[bumpversion]
2-
current_version = 3.1.0
2+
current_version = 3.2.0
33
commit = True
44
tag = False
55

6-
[bumpversion:file:opentok/version.py]
6+
[bumpversion:file:opentok/version.py]

.github/workflows/ot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: [3.5, 3.6, 3.7, 3.8.8, 3.9]
11+
python-version: [3.6, 3.7, 3.8.8, 3.9]
1212

1313
steps:
1414
- uses: actions/checkout@v2

opentok/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .opentok import OpenTok, Client, Roles, MediaModes, ArchiveModes
22
from .session import Session
3-
from .archives import Archive, ArchiveList, OutputModes
3+
from .archives import Archive, ArchiveList, OutputModes, StreamModes
44
from .exceptions import (
55
OpenTokException,
66
AuthError,
@@ -13,4 +13,4 @@
1313
from .stream import Stream
1414
from .streamlist import StreamList
1515
from .sip_call import SipCall
16-
from .broadcast import Broadcast
16+
from .broadcast import Broadcast, BroadcastStreamModes

opentok/archives.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ class OutputModes(Enum):
2626
individual = u("individual")
2727
"""Each stream in the archive is recorded to an individual file."""
2828

29+
class StreamModes(Enum):
30+
""""List of valid settings for the stream_mode parameter of the OpenTok.start_archive()
31+
method."""
32+
33+
auto = u("auto")
34+
"""Streams are automatically added to the archive."""
35+
manual = u("manual")
36+
"""Streams are included in the archive based on calls to the OpenTok.add_archive_stream()
37+
and OpenTok.remove_archive_stream() methods."""
2938

3039
class Archive(object):
3140
"""Represents an archive of an OpenTok session.
@@ -55,6 +64,14 @@ class Archive(object):
5564
Whether all streams in the archive are recorded to a single file
5665
(OutputModes.composed) or to individual files (OutputModes.individual).
5766
67+
:ivar streamMode:
68+
Whether streams included in the archive are selected automatically
69+
("auto", the default) or manually ("manual").
70+
71+
:ivar streams:
72+
A list of streams currently being archived. This is only set for an archive with
73+
the status set to "started" and the stream_Mode set to "manual".
74+
5875
:ivar partner_id:
5976
The API key associated with the archive.
6077
@@ -113,6 +130,8 @@ def __init__(self, sdk, values):
113130
self.has_audio = values.get("hasAudio")
114131
self.has_video = values.get("hasVideo")
115132
self.output_mode = OutputModes[values.get("outputMode", "composed")]
133+
self.stream_mode = values.get("streamMode", StreamModes.auto)
134+
self.streams = values.get("streams")
116135
self.url = values.get("url")
117136
self.resolution = values.get("resolution")
118137

opentok/broadcast.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import json
2+
from enum import Enum
3+
from six import iteritems, u
24

35

46
class Broadcast(object):
57
"""
6-
Represents a live streaming broadcast
8+
Represents a live streaming broadcast.
9+
10+
:ivar streamMode:
11+
Whether streams included in the broadcast are selected automatically
12+
("auto", the default) or manually ("manual").
13+
14+
:ivar streams:
15+
A list of streams currently being broadcast. This is only set for a broadcast with
16+
the status set to "started" and the stream_Mode set to "manual".
717
"""
818

919
def __init__(self, kwargs):
@@ -15,9 +25,21 @@ def __init__(self, kwargs):
1525
self.resolution = kwargs.get("resolution")
1626
self.status = kwargs.get("status")
1727
self.broadcastUrls = kwargs.get("broadcastUrls")
28+
self.stream_mode = kwargs.get("streamMode", BroadcastStreamModes.auto)
29+
self.streams = kwargs.get("streams")
1830

1931
def json(self):
2032
"""
2133
Returns a JSON representation of the broadcast
2234
"""
2335
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)
36+
37+
class BroadcastStreamModes(Enum):
38+
""""List of valid settings for the stream_mode parameter of the OpenTok.start_broadcast()
39+
method."""
40+
41+
auto = u("auto")
42+
"""Streams are automatically added to the broadcast."""
43+
manual = u("manual")
44+
"""Streams are included in the broadcast based on calls to the OpenTok.add_broadcast_stream()
45+
and OpenTok.remove_broadcast_stream() methods."""

opentok/endpoints.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,24 @@ def get_broadcast_url(self, broadcast_id=None, stop=False, layout=False):
132132
url = url + "/layout"
133133
return url
134134

135-
def get_mute_all_url(self, session_id):
136-
""" this method returns the urls for muting every stream in a session """
135+
def get_archive_stream(self, archive_id=None):
136+
""" this method returns urls for working with streamModes in archives """
137137
url = (
138-
self.api_url
139-
+ "/v2/project/"
138+
self.api_url
139+
+ "/v2/project/"
140140
+ self.api_key
141-
+ "/session/"
142-
+ session_id
143-
+ "/mute"
141+
+ "archive/"
142+
+ archive_id
143+
+ "/streams"
144+
)
144145

145-
)
146+
def get_broadcast_stream(self, broadcast_id=None):
147+
""" this method returns urls for working with streamModes in broadcasts """
148+
url = (
149+
self.api_url
150+
+ "/v2/partner/"
151+
+ self.api_key
152+
+ "broadcast/"
153+
+ broadcast_id
154+
+ "/streams"
155+
)

opentok/exceptions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,18 @@ class BroadcastError(OpenTokException):
8888
"""
8989

9090
pass
91+
92+
class ArchiveStreamModeError(OpenTokException):
93+
"""
94+
Indicates that the archive is configured with a streamMode that does not support stream manipulation.
95+
"""
96+
97+
pass
98+
99+
100+
class BroadcastStreamModeError(OpenTokException):
101+
"""
102+
Indicates that the broadcast is configured with a streamMode that does not support stream manipulation.
103+
"""
104+
105+
pass

0 commit comments

Comments
 (0)