1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
120
121
122
123
124
125
126
127
128
129
130
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(warnings)]
pub mod api;
pub mod data;
pub mod errors;
pub mod live;
pub mod tests;
pub mod user;
pub mod utils;
pub mod vod;
pub mod accesscontrol;
#[derive(Debug, Clone)]
pub enum LivepeerEnv {
Dev,
Stg,
Prod,
Origin,
Test,
}
#[derive(Debug, Clone)]
pub struct LivepeerClient {
pub config: LivepeerConfig,
}
#[derive(Debug, Clone)]
pub struct LivepeerConfig {
host: &'static str,
api_token: String,
rtmp_endpoint: &'static str,
}
#[derive(Debug, Clone)]
pub struct Livepeer {
_client: LivepeerClient,
_env: LivepeerEnv,
pub asset: vod::api::VodApi,
pub access_control: accesscontrol::api::AccessControlApi,
pub task: vod::task::TaskApi,
pub user_api: user::UserApi,
pub rtmp: live::rtmp::Rtmp,
pub stream: live::stream::Stream,
pub user: user::User,
}
impl LivepeerClient {
fn new(api_token: String, env: Option<LivepeerEnv>) -> Self {
let host = match env {
Some(LivepeerEnv::Dev) => "http://localhost:3004",
Some(LivepeerEnv::Stg) => "https://livepeer.monster",
Some(LivepeerEnv::Prod) => "https://livepeer.com",
Some(LivepeerEnv::Origin) => "https://origin.livepeer.com",
Some(LivepeerEnv::Test) => "https://origin.livepeer.com",
None => "https://livepeer.monster",
};
let rtmp_endpoint = match env {
Some(LivepeerEnv::Dev) => "rtmp://127.0.0.1:1935/live",
Some(LivepeerEnv::Stg) => "rtmp://rtmp.livepeer.monster:11935/live",
Some(LivepeerEnv::Prod) => "rtmp://rtmp.livepeer.com/live",
Some(LivepeerEnv::Origin) => "rtmp://rtmp.livepeer.com/live",
Some(LivepeerEnv::Test) => "rtmp://prg-playback.lp-playback.studio/live",
None => "rtmp://rtmp.livepeer.monster:11935/live",
};
let config = LivepeerConfig {
host: host,
api_token: api_token,
rtmp_endpoint: rtmp_endpoint,
};
LivepeerClient { config: config }
}
}
impl Livepeer {
pub fn new(api_token: Option<String>, env: Option<LivepeerEnv>) -> Result<Livepeer, String> {
let mut _api_token = String::new();
if api_token.is_some() {
_api_token = api_token.unwrap();
} else {
_api_token = std::env::var("LIVEPEER_API_TOKEN").unwrap_or_default();
}
let client = LivepeerClient::new(_api_token.clone(), env.clone());
let user_info = user::User::new(&client);
if user_info.is_err() {
return Err(user_info.err().unwrap());
}
Ok(Livepeer {
_client: client.clone(),
_env: env.clone().unwrap_or(LivepeerEnv::Dev),
asset: vod::api::VodApi::new(&client),
task: vod::task::TaskApi::new(&client),
user_api: user::UserApi::new(&client),
access_control: accesscontrol::api::AccessControlApi::new(&client),
stream: live::stream::Stream::new(&client),
rtmp: live::rtmp::Rtmp {
client: client.clone(),
},
user: user_info.unwrap(),
})
}
}