-
Notifications
You must be signed in to change notification settings - Fork 703
/
Copy pathstreaming.ts
155 lines (140 loc) · 3.9 KB
/
streaming.ts
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
148
149
150
151
152
153
154
155
import { StreamingService as InternalStreamingService } from 'services/streaming';
import { Inject } from 'services/core/injector';
import { Fallback, Singleton } from 'services/api/external-api';
import { Observable } from 'rxjs';
import { ISerializable } from 'services/api/rpc-api';
/**
* Possible streaming states.
*/
enum EStreamingState {
Offline = 'offline',
Starting = 'starting',
Live = 'live',
Ending = 'ending',
Reconnecting = 'reconnecting',
}
/**
* Possible recording states.
*/
enum ERecordingState {
Offline = 'offline',
Starting = 'starting',
Recording = 'recording',
Stopping = 'stopping',
Start = 'start',
Wrote = 'wrote',
}
/**
* Possible replay buffer states.
*/
enum EReplayBufferState {
Running = 'running',
Stopping = 'stopping',
Offline = 'offline',
Saving = 'saving',
Wrote = 'wrote',
}
/**
* Serialized representation of {@link StreamingService}. Includes
* streaming, recording and replay buffer state representation.
*/
interface IStreamingState {
streamingStatus: EStreamingState;
verticalStreamingStatus: EStreamingState;
streamingStatusTime: string;
verticalStreamingStatusTime: string;
recordingStatus: ERecordingState;
verticalRecordingStatus: ERecordingState;
recordingStatusTime: string;
verticalRecordingStatusTime: string;
replayBufferStatus: EReplayBufferState;
replayBufferStatusTime: string;
streamErrorCreated?: string;
}
/**
* API for streaming, recording and replay buffer management. Provides
* operations like starting and stopping streaming and recording and allows
* watching for streaming status.
*/
@Singleton()
export class StreamingService implements ISerializable {
@Fallback()
@Inject()
protected streamingService: InternalStreamingService;
/**
* Observable event that is triggered whenever the the streaming state changes.
* The observed value determines the current streaming state and is represented
* by {@link EStreamingState}.
*
* @see EStreamingState
*/
get streamingStatusChange(): Observable<EStreamingState> {
return this.streamingService.streamingStatusChange;
}
/**
* Observable event that is triggered whenever the the recording state changes.
* The observed value determines the current recording state and is represented
* by {@link ERecordingState}.
*
* @see ERecordingState
*/
get recordingStatusChange(): Observable<ERecordingState> {
return this.streamingService.recordingStatusChange;
}
/**
* Observable event that is triggered whenever the the replay buffer state
* changes. The observed value determines the current replay buffer state and
* is represented by {@link EReplayBufferState}.
*
* @see EReplayBufferState
*/
get replayBufferStatusChange(): Observable<EReplayBufferState> {
return this.streamingService.replayBufferStatusChange;
}
/**
* Observable event that is triggered whenever a stream error occurs when
* attempting to go live.
*/
get streamErrorCreated(): Observable<string> {
return this.streamingService.streamErrorCreated;
}
/**
* Returns The current streaming, recording and replay buffer state
* represented.
*
* @returns A serialized representation of {@link StreamingService}
*/
getModel(): IStreamingState {
return this.streamingService.getModel();
}
/**
* Toggles recording.
*/
toggleRecording(): void {
return this.streamingService.toggleRecording();
}
/**
* Toggles streaming.
*/
toggleStreaming(): Promise<never> | Promise<void> {
return this.streamingService.toggleStreaming();
}
/**
* Starts replay buffer.
*/
startReplayBuffer(): void {
return this.streamingService.startReplayBuffer();
}
/**
* Stops replay buffer.
*/
stopReplayBuffer(): void {
return this.streamingService.stopReplayBuffer();
}
/**
* Saves replay.
*/
saveReplay(): void {
return this.streamingService.saveReplay();
}
}