forked from pjebs/tokbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive.go
147 lines (129 loc) · 4.51 KB
/
archive.go
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package tokbox
import (
"encoding/json"
"fmt"
)
/*
TODO safari
To include video from streams published from Safari clients, you must use a Safari OpenTok project. Otherwise, streams published from Safari show up as audio-only.
https://tokbox.com/developer/guides/archiving/#individual-stream-and-composed-archives
TODO
The recommended maximum number of streams in an archive is five. You can record up to nine streams; however, in a composed archive quality may degrade if you record more than five streams. If more than nine streams are published to the session, they are not recorded. Also, archive recordings are limited to 120 minutes in length.
https://tokbox.com/developer/guides/archiving/
*/
const (
archiveBaseUrl = "https://api.opentok.com/v2/project/%s/archive" // api_key
)
type ArchiveService interface {
Start(ArchiveReq) (resp *Archive, err error)
Stop(archiveId string) (resp *Archive, err error)
List(interface{}) (resp *ArchiveResponse, error error)
Get(archiveId string) (resp *Archive, err error)
Delete(archiveId string) error
}
type ArchiveServiceOp struct {
client *Tokbox
}
func (this *ArchiveServiceOp) Start(data ArchiveReq) (resp *Archive, err error) {
path := fmt.Sprintf(archiveBaseUrl, this.client.apiKey)
resource := new(Archive)
err = this.client.Post(path, data, resource)
return resource, err
}
func (this *ArchiveServiceOp) Stop(archiveId string) (resp *Archive, err error) {
path := fmt.Sprintf(archiveBaseUrl+"/%s/stop", this.client.apiKey, archiveId)
resource := new(Archive)
err = this.client.Post(path, nil, resource)
return resource, err
}
func (this *ArchiveServiceOp) List(options interface{}) (resp *ArchiveResponse, err error) {
path := fmt.Sprintf(archiveBaseUrl, this.client.apiKey)
resource := new(ArchiveResponse)
err = this.client.Get(path, resource, options)
return resource, err
}
func (this *ArchiveServiceOp) Get(archiveId string) (resp *Archive, err error) {
path := fmt.Sprintf(archiveBaseUrl+"/%s", this.client.apiKey, archiveId)
resource := new(Archive)
err = this.client.Get(path, resource, nil)
return resource, err
}
func (this *ArchiveServiceOp) Delete(archiveId string) (err error) {
path := fmt.Sprintf(archiveBaseUrl+"/%s", this.client.apiKey, archiveId)
err = this.client.Delete(path, nil, nil)
return err
}
// url query options
type ArchiveOptions struct {
Offset int `url:"offset,omitempty"` // default 0
Count int `url:"count,omitempty"` // default 50
SessionId string `url:"session_id,omitempty"` // default null, get all archive list
}
// request body
type ArchiveReq struct {
SessionID string `json:"sessionId"`
HasAudio bool `json:"hasAudio"`
HasVideo bool `json:"hasVideo"`
Layout Layout `json:"layout"`
Name string `json:"name"` // (Optional) The name of the archive (for your own identification)
OutputMode string `json:"outputMode"` // composed (default) | individual
Resolution string `json:"resolution"` // 640x480 (default) | 1280x720
}
type Layout struct {
Type string `json:"type" ` // bestFit | custom | horizontalPresentation | pip | verticalPresentation
Stylesheet string `json:"stylesheet,omitempty"` // only used with type == custom
}
func DefaultArchiveReq(sessionId, name string) ArchiveReq {
return ArchiveReq{
SessionID: sessionId,
HasAudio: true,
HasVideo: true,
Layout: Layout{
Type: "bestFit",
},
Name: name,
OutputMode: "composed",
Resolution: "640x480",
}
}
// response
type ArchiveResponse struct {
Count int `json:"count"`
Items []Archive `json:"items"`
}
func (this *ArchiveResponse) Json() string {
b, err := json.MarshalIndent(this, "", " ")
if err != nil {
return ""
}
return string(b)
}
type Archive struct {
CreatedAt int64 `json:"createdAt"`
Duration int `json:"duration"`
HasAudio bool `json:"hasAudio"`
HasVideo bool `json:"hasVideo"`
ID string `json:"id"` // archive id
Name string `json:"name"`
OutputMode string `json:"outputMode"`
ProjectID int `json:"projectId"`
Reason string `json:"reason"`
Resolution string `json:"resolution"`
SessionID string `json:"sessionId"`
Size int `json:"size"`
Status string `json:"status"`
URL interface{} `json:"url"`
}
func (this *Archive) GetUrl() string {
if this.URL == nil {
return ""
}
return fmt.Sprintf("%v", this.URL)
}
func (this *Archive) Json() string {
b, err := json.MarshalIndent(this, "", " ")
if err != nil {
return ""
}
return string(b)
}