Skip to content

Commit

Permalink
Merge pull request #47 from apivideo/feat/live-restreaming
Browse files Browse the repository at this point in the history
Feat/live restreaming
  • Loading branch information
bot-api-video authored Jun 28, 2023
2 parents ea5d6cd + 3969c5a commit 0b788cf
Show file tree
Hide file tree
Showing 29 changed files with 276 additions and 25 deletions.
4 changes: 4 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Sources/Models/RawStatisticsListLiveStreamAnalyticsResponse.swift
Sources/Models/RawStatisticsListPlayerSessionEventsResponse.swift
Sources/Models/RawStatisticsListSessionsResponse.swift
Sources/Models/RefreshTokenPayload.swift
Sources/Models/RestreamsRequestObject.swift
Sources/Models/RestreamsResponseObject.swift
Sources/Models/TokenCreationPayload.swift
Sources/Models/TokenListResponse.swift
Sources/Models/UploadToken.swift
Expand Down Expand Up @@ -153,6 +155,8 @@ docs/RawStatisticsListLiveStreamAnalyticsResponse.md
docs/RawStatisticsListPlayerSessionEventsResponse.md
docs/RawStatisticsListSessionsResponse.md
docs/RefreshTokenPayload.md
docs/RestreamsRequestObject.md
docs/RestreamsResponseObject.md
docs/TokenCreationPayload.md
docs/TokenListResponse.md
docs/UploadToken.md
Expand Down
2 changes: 1 addition & 1 deletion .openapi-generator/oas_apivideo.yaml-defaut-cli.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
aae56c93a2e3a6a1d04f6bd5a6ec47ba503646799e98307d3139e8ceb92a730c
3eb2afd3380a2e1194d21245be70de774173595baf3a06fefd0c9c8d1c7f7f58
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog
All changes to this project will be documented in this file.

## [1.2.0] - 2023-06-19
## [1.2.0] - 2023-06-28
- Introducing live streams restream feature
- Introducing new analytics endpoints

## [1.1.1] - 2022-12-09
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ Method | HTTP request | Description
- [RawStatisticsListPlayerSessionEventsResponse](docs/RawStatisticsListPlayerSessionEventsResponse.md)
- [RawStatisticsListSessionsResponse](docs/RawStatisticsListSessionsResponse.md)
- [RefreshTokenPayload](docs/RefreshTokenPayload.md)
- [RestreamsRequestObject](docs/RestreamsRequestObject.md)
- [RestreamsResponseObject](docs/RestreamsResponseObject.md)
- [TokenCreationPayload](docs/TokenCreationPayload.md)
- [TokenListResponse](docs/TokenListResponse.md)
- [UploadToken](docs/UploadToken.md)
Expand Down
7 changes: 6 additions & 1 deletion Sources/Models/LiveStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public struct LiveStream: Codable, Hashable {
public var playerId: String?
/** Whether or not you are broadcasting the live video you recorded for others to see. True means you are broadcasting to viewers, false means you are not. */
public var broadcasting: Bool?
/** Returns the list of RTMP restream destinations. */
public var restreams: [RestreamsResponseObject]
/** When the player was created, presented in ISO-8601 format. */
public var createdAt: Date?
/** When the player was last updated, presented in ISO-8601 format. */
public var updatedAt: Date?

public init(liveStreamId: String, name: String? = nil, streamKey: String? = nil, record: Bool? = nil, _public: Bool? = nil, assets: LiveStreamAssets? = nil, playerId: String? = nil, broadcasting: Bool? = nil, createdAt: Date? = nil, updatedAt: Date? = nil) {
public init(liveStreamId: String, name: String? = nil, streamKey: String? = nil, record: Bool? = nil, _public: Bool? = nil, assets: LiveStreamAssets? = nil, playerId: String? = nil, broadcasting: Bool? = nil, restreams: [RestreamsResponseObject], createdAt: Date? = nil, updatedAt: Date? = nil) {
self.liveStreamId = liveStreamId
self.name = name
self.streamKey = streamKey
Expand All @@ -41,6 +43,7 @@ public struct LiveStream: Codable, Hashable {
self.assets = assets
self.playerId = playerId
self.broadcasting = broadcasting
self.restreams = restreams
self.createdAt = createdAt
self.updatedAt = updatedAt
}
Expand All @@ -54,6 +57,7 @@ public struct LiveStream: Codable, Hashable {
case assets
case playerId
case broadcasting
case restreams
case createdAt
case updatedAt
}
Expand All @@ -70,6 +74,7 @@ public struct LiveStream: Codable, Hashable {
try container.encodeIfPresent(assets, forKey: .assets)
try container.encodeIfPresent(playerId, forKey: .playerId)
try container.encodeIfPresent(broadcasting, forKey: .broadcasting)
try container.encode(restreams, forKey: .restreams)
try container.encodeIfPresent(createdAt, forKey: .createdAt)
try container.encodeIfPresent(updatedAt, forKey: .updatedAt)
}
Expand Down
7 changes: 6 additions & 1 deletion Sources/Models/LiveStreamCreationPayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ public struct LiveStreamCreationPayload: Codable, Hashable {
public var _public: Bool?
/** The unique identifier for the player. */
public var playerId: String?
/** Use this parameter to add, edit, or remove RTMP services where you want to restream a live stream. The list can only contain up to 5 destinations. */
public var restreams: [RestreamsRequestObject]?

public init(name: String, record: Bool? = false, _public: Bool? = nil, playerId: String? = nil) {
public init(name: String, record: Bool? = false, _public: Bool? = nil, playerId: String? = nil, restreams: [RestreamsRequestObject]? = nil) {
self.name = name
self.record = record
self._public = _public
self.playerId = playerId
self.restreams = restreams
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case name
case record
case _public = "public"
case playerId
case restreams
}

// Encodable protocol methods
Expand All @@ -43,6 +47,7 @@ public struct LiveStreamCreationPayload: Codable, Hashable {
try container.encodeIfPresent(record, forKey: .record)
try container.encodeIfPresent(_public, forKey: ._public)
try container.encodeIfPresent(playerId, forKey: .playerId)
try container.encodeIfPresent(restreams, forKey: .restreams)
}
}

7 changes: 6 additions & 1 deletion Sources/Models/LiveStreamUpdatePayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ public struct LiveStreamUpdatePayload: Codable, Hashable {
public var record: Bool?
/** The unique ID for the player associated with a live stream that you want to update. */
public var playerId: String?
/** Use this parameter to add, edit, or remove RTMP services where you want to restream a live stream. The list can only contain up to 5 destinations. This operation updates all restream destinations in the same request. If you do not want to modify an existing restream destination, you need to include it in your request, otherwise it is removed. */
public var restreams: [RestreamsRequestObject]?

public init(name: String? = nil, _public: Bool? = nil, record: Bool? = nil, playerId: String? = nil) {
public init(name: String? = nil, _public: Bool? = nil, record: Bool? = nil, playerId: String? = nil, restreams: [RestreamsRequestObject]? = nil) {
self.name = name
self._public = _public
self.record = record
self.playerId = playerId
self.restreams = restreams
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case name
case _public = "public"
case record
case playerId
case restreams
}

// Encodable protocol methods
Expand All @@ -43,6 +47,7 @@ public struct LiveStreamUpdatePayload: Codable, Hashable {
try container.encodeIfPresent(_public, forKey: ._public)
try container.encodeIfPresent(record, forKey: .record)
try container.encodeIfPresent(playerId, forKey: .playerId)
try container.encodeIfPresent(restreams, forKey: .restreams)
}
}

44 changes: 44 additions & 0 deletions Sources/Models/RestreamsRequestObject.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// RestreamsRequestObject.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//

import Foundation
#if canImport(AnyCodable)
import AnyCodable
#endif

/** Adding restream destinations is optional. However, if you set a restream destination, you must provide all attributes for each destination. */
public struct RestreamsRequestObject: Codable, Hashable {

/** Use this parameter to define a name for the restream destination. */
public var name: String
/** Use this parameter to set the RTMP URL of the restream destination. */
public var serverUrl: String
/** Use this parameter to provide the unique key of the live stream that you want to restream. */
public var streamKey: String

public init(name: String, serverUrl: String, streamKey: String) {
self.name = name
self.serverUrl = serverUrl
self.streamKey = streamKey
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case name
case serverUrl
case streamKey
}

// Encodable protocol methods

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(name, forKey: .name)
try container.encode(serverUrl, forKey: .serverUrl)
try container.encode(streamKey, forKey: .streamKey)
}
}

43 changes: 43 additions & 0 deletions Sources/Models/RestreamsResponseObject.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// RestreamsResponseObject.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//

import Foundation
#if canImport(AnyCodable)
import AnyCodable
#endif

public struct RestreamsResponseObject: Codable, Hashable {

/** Returns the name of a restream destination. */
public var name: String?
/** Returns the RTMP URL of a restream destination. */
public var serverUrl: String?
/** Returns the unique key of the live stream that is set up for restreaming. */
public var streamKey: String?

public init(name: String? = nil, serverUrl: String? = nil, streamKey: String? = nil) {
self.name = name
self.serverUrl = serverUrl
self.streamKey = streamKey
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case name
case serverUrl
case streamKey
}

// Encodable protocol methods

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(name, forKey: .name)
try container.encodeIfPresent(serverUrl, forKey: .serverUrl)
try container.encodeIfPresent(streamKey, forKey: .streamKey)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
"createdAt" : "2020-07-29T10:45:35.000Z",
"updatedAt" : "2020-07-29T10:45:35.000Z",
"streamKey" : "cc1b4df0-d1c5-4064-a8f9-9f0368385135",
"restreams" : [ {
"name" : "YouTube",
"serverUrl" : "rtmp://youtube.broadcast.example.com",
"streamKey" : "cc1b4df0-d1c5-4064-a8f9-9f0368385135"
}, {
"name" : "Twitch",
"serverUrl" : "rtmp://twitch.broadcast.example.com",
"streamKey" : "cc1b4df0-d1c5-4064-a8f9-9f0368385135"
} ],
"name" : "Live From New York",
"public" : true,
"record" : true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type" : "https://docs.api.video/reference/invalid-attribute",
"title" : "An attribute is invalid.",
"status" : 400,
"detail" : "This value should not be blank.",
"name" : "restreams[0][name]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type" : "https://docs.api.video/reference/invalid-attribute",
"title" : "An attribute is invalid.",
"status" : 400,
"detail" : "Missing app name: rtmp://[host]/[app name].",
"name" : "restreams[0][serverUrl]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type" : "https://docs.api.video/reference/invalid-attribute",
"title" : "An attribute is invalid.",
"status" : 400,
"detail" : "RTMP URL should have the following format: rtmp://[host]/[app name].",
"name" : "restreams[0][serverUrl]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type" : "https://docs.api.video/reference/invalid-attribute",
"title" : "An attribute is invalid.",
"status" : 400,
"detail" : "This collection should contain 5 elements or less.",
"name" : "restreams"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type" : "https://docs.api.video/reference/invalid-attribute",
"title" : "An attribute is invalid.",
"status" : 400,
"detail" : "This value should not be null.",
"name" : "restreams[0][name]"
}
27 changes: 18 additions & 9 deletions Tests/TestResources/payloads/livestreams/get/responses/200.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
{
"liveStreamId" : "li400mYKSgQ6xs7taUeSaEKr",
"createdAt" : "2020-01-31T10:17:47.000Z",
"updatedAt" : "2020-03-09T13:19:43.000Z",
"streamKey" : "30087931-229e-42cf-b5f9-e91bcc1f7332",
"name" : "Live Stream From the browser",
"liveStreamId" : "li4pqNqGUkhKfWcBGpZVLRY5",
"createdAt" : "2020-07-29T10:45:35.000Z",
"updatedAt" : "2020-07-29T10:45:35.000Z",
"streamKey" : "cc1b4df0-d1c5-4064-a8f9-9f0368385135",
"restreams" : [ {
"name" : "YouTube",
"serverUrl" : "rtmp://youtube.broadcast.example.com",
"streamKey" : "cc1b4df0-d1c5-4064-a8f9-9f0368385135"
}, {
"name" : "Twitch",
"serverUrl" : "rtmp://twitch.broadcast.example.com",
"streamKey" : "cc1b4df0-d1c5-4064-a8f9-9f0368385135"
} ],
"name" : "Live From New York",
"public" : true,
"record" : true,
"broadcasting" : false,
"assets" : {
"iframe" : "<iframe src=\"https://embed.api.video/live/li400mYKSgQ6xs7taUeSaEKr\" width=\"100%\" height=\"100%\" frameborder=\"0\" scrolling=\"no\" allowfullscreen=\"\"></iframe>",
"player" : "https://embed.api.video/live/li400mYKSgQ6xs7taUeSaEKr",
"hls" : "https://live.api.video/li400mYKSgQ6xs7taUeSaEKr.m3u8",
"thumbnail" : "https://cdn.api.video/live/li400mYKSgQ6xs7taUeSaEKr/thumbnail.jpg"
"iframe" : "<iframe src=\"https://embed.api.video/live/li4pqNqGUkhKfWcBGpZVLRY5\" width=\"100%\" height=\"100%\" frameborder=\"0\" scrolling=\"no\" allowfullscreen=\"\"></iframe>",
"player" : "https://embed.api.video/live/li4pqNqGUkhKfWcBGpZVLRY5",
"hls" : "https://live.api.video/li4pqNqGUkhKfWcBGpZVLRY5.m3u8",
"thumbnail" : "https://cdn.api.video/live/li4pqNqGUkhKfWcBGpZVLRY5/thumbnail.jpg"
}
}
18 changes: 18 additions & 0 deletions Tests/TestResources/payloads/livestreams/list/responses/200.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
"createdAt" : "2020-01-31T10:17:47.000Z",
"updatedAt" : "2020-03-09T13:19:43.000Z",
"streamKey" : "30087931-229e-42cf-b5f9-e91bcc1f7332",
"restreams" : [ {
"name" : "YouTube",
"serverUrl" : "rtmp://youtube.broadcast.example.com",
"streamKey" : "cc1b4df0-d1c5-4064-a8f9-9f0368385188"
}, {
"name" : "Twitch",
"serverUrl" : "rtmp://twitch.broadcast.example.com",
"streamKey" : "cc1b4df0-d1c5-4064-a8f9-9f0368385188"
} ],
"name" : "Live Stream From the browser",
"public" : true,
"record" : true,
Expand All @@ -19,6 +28,15 @@
"createdAt" : "2020-07-29T10:45:35.000Z",
"updatedAt" : "2020-07-29T10:45:35.000Z",
"streamKey" : "cc1b4df0-d1c5-4064-a8f9-9f0368385135",
"restreams" : [ {
"name" : "YouTube",
"serverUrl" : "rtmp://youtube.broadcast.example.com",
"streamKey" : "cc1b4df0-d1c5-4064-a8f9-9f0368385135"
}, {
"name" : "Twitch",
"serverUrl" : "rtmp://twitch.broadcast.example.com",
"streamKey" : "cc1b4df0-d1c5-4064-a8f9-9f0368385135"
} ],
"name" : "Live From New York",
"public" : true,
"record" : true,
Expand Down
Loading

0 comments on commit 0b788cf

Please sign in to comment.