Class: OpenTok::Archives
- Inherits:
-
Object
- Object
- OpenTok::Archives
- Defined in:
- lib/opentok/archives.rb
Overview
A class for working with OpenTok archives.
Instance Method Summary collapse
-
#add_stream(archive_id, stream_id, options) ⇒ Object
Adds a stream to currently running composed archive that was started with the streamMode set to “manual”.
-
#all(options = {}) ⇒ ArchiveList
Returns an ArchiveList, which is an array of archives that are completed and in-progress, for your API key.
-
#create(session_id, options = {}) ⇒ Archive
Starts archiving an OpenTok session.
-
#delete_by_id(archive_id) ⇒ Object
Deletes an OpenTok archive.
-
#find(archive_id) ⇒ Archive
Gets an Archive object for the given archive ID.
-
#layout(archive_id, options = {}) ⇒ Object
Sets the layout type for a composed archive.
-
#remove_stream(archive_id, stream_id) ⇒ Object
Removes a stream from a currently running composed archive that was started with the streamMode set to “manual”.
-
#stop_by_id(archive_id) ⇒ Archive
Stops an OpenTok archive that is being recorded.
Instance Method Details
#add_stream(archive_id, stream_id, options) ⇒ Object
Adds a stream to currently running composed archive that was started with the streamMode set to “manual”. For a description of the feature, see https://tokbox.com/developer/rest/#selecting-archive-streams.
You can call the method repeatedly with add_stream set to the same stream ID, to toggle the stream’s audio or video in the archive. If you set both has_audio and has_video to false, you will get error response.
286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/opentok/archives.rb', line 286 def add_stream(archive_id, stream_id, ) raise ArgumentError, "archive_id not provided" if archive_id.to_s.empty? raise ArgumentError, "stream_id not provided" if stream_id.to_s.empty? if .has_key?(:has_audio) && .has_key?(:has_video) has_audio = [:has_audio] has_video = [:has_video] raise ArgumentError, "has_audio and has_video can't both be false" if (has_audio, has_video) end ['add_stream'] = stream_id @client.select_streams_for_archive(archive_id, ) end |
#all(options = {}) ⇒ ArchiveList
Returns an ArchiveList, which is an array of archives that are completed and in-progress, for your API key.
149 150 151 152 153 |
# File 'lib/opentok/archives.rb', line 149 def all( = {}) raise ArgumentError, "Limit is invalid" unless [:count].nil? or (0..1000).include? [:count] archive_list_json = @client.list_archives([:offset], [:count], [:sessionId]) ArchiveList.new self, archive_list_json end |
#create(session_id, options = {}) ⇒ Archive
Starts archiving an OpenTok session.
Clients must be actively connected to the OpenTok session for you to successfully start recording an archive.
You can only record one archive at a time for a given session. You can only record archives of sessions that use the OpenTok Media Router (sessions with the media mode set to routed); you cannot archive sessions with the media mode set to relayed.
For more information on archiving, see the OpenTok archiving programming guide.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/opentok/archives.rb', line 94 def create(session_id, = {}) raise ArgumentError, "session_id not provided" if session_id.to_s.empty? raise ArgumentError, "Resolution cannot be supplied for individual output mode" if .key?(:resolution) and [:output_mode] == :individual # normalize opts so all keys are symbols and only include valid_opts valid_opts = [ :name, :has_audio, :has_video, :output_mode, :resolution, :layout, :multi_archive_tag, :stream_mode ] opts = .inject({}) do |m,(k,v)| if valid_opts.include? k.to_sym m[k.to_sym] = v end m end archive_json = @client.start_archive(session_id, opts) Archive.new self, archive_json end |
#delete_by_id(archive_id) ⇒ Object
Deletes an OpenTok archive.
You can only delete an archive which has a status of “available”, “uploaded”, or “deleted”. Deleting an archive removes its record from the list of archives. For an “available” archive, it also removes the archive file, making it unavailable for download. For a “deleted” archive, the archive remains deleted.
189 190 191 192 193 |
# File 'lib/opentok/archives.rb', line 189 def delete_by_id(archive_id) raise ArgumentError, "archive_id not provided" if archive_id.to_s.empty? response = @client.delete_archive(archive_id) (200..300).include? response.code end |
#find(archive_id) ⇒ Archive
Gets an Archive object for the given archive ID.
130 131 132 133 134 |
# File 'lib/opentok/archives.rb', line 130 def find(archive_id) raise ArgumentError, "archive_id not provided" if archive_id.to_s.empty? archive_json = @client.get_archive(archive_id.to_s) Archive.new self, archive_json end |
#layout(archive_id, options = {}) ⇒ Object
Sets the layout type for a composed archive. For a description of layout types, see Customizing the video layout for composed archives.
240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/opentok/archives.rb', line 240 def layout(archive_id, = {}) raise ArgumentError, "option parameter is empty" if .empty? raise ArgumentError, "archive_id not provided" if archive_id.to_s.empty? type = [:type] raise ArgumentError, "custom type must have a stylesheet" if (type.eql? "custom") && (!.key? :stylesheet) valid_non_custom_layouts = ["bestFit","horizontalPresentation","pip", "verticalPresentation", ""] valid_non_custom_type = valid_non_custom_layouts.include? type raise ArgumentError, "type is not valid" if !valid_non_custom_type && !(type.eql? "custom") raise ArgumentError, "type is not valid or stylesheet not needed" if valid_non_custom_type and .key? :stylesheet raise ArgumentError, "screenshare_type is not valid" if [:screenshare_type] && !valid_non_custom_layouts.include?([:screenshare_type]) raise ArgumentError, "type must be set to 'bestFit' if screenshare_type is defined" if [:screenshare_type] && type != 'bestFit' response = @client.layout_archive(archive_id, ) (200..300).include? response.code end |
#remove_stream(archive_id, stream_id) ⇒ Object
Removes a stream from a currently running composed archive that was started with the streamMode set to “manual”. For a description of the feature, see https://tokbox.com/developer/rest/#selecting-archive-streams.
315 316 317 318 319 320 321 322 |
# File 'lib/opentok/archives.rb', line 315 def remove_stream(archive_id, stream_id) raise ArgumentError, "archive_id not provided" if archive_id.to_s.empty? raise ArgumentError, "stream_id not provided" if stream_id.to_s.empty? = {} ['remove_stream'] = stream_id @client.select_streams_for_archive(archive_id, ) end |
#stop_by_id(archive_id) ⇒ Archive
Stops an OpenTok archive that is being recorded.
Archives automatically stop recording after 120 minutes or when all clients have disconnected from the session being archived.
170 171 172 173 174 |
# File 'lib/opentok/archives.rb', line 170 def stop_by_id(archive_id) raise ArgumentError, "archive_id not provided" if archive_id.to_s.empty? archive_json = @client.stop_archive(archive_id) Archive.new self, archive_json end |