|
@@ -8,32 +8,30 @@ import recordingXMLUtils from './recordingXMLUtils';
|
8
|
8
|
const logger = getLogger(__filename);
|
9
|
9
|
|
10
|
10
|
/**
|
11
|
|
- * A singleton responsible for starting and stopping recording sessions and
|
12
|
|
- * emitting state updates for them.
|
|
11
|
+ * A class responsible for starting and stopping recording sessions and emitting
|
|
12
|
+ * state updates for them.
|
13
|
13
|
*/
|
14
|
|
-const recordingManager = {
|
|
14
|
+class RecordingManager {
|
15
|
15
|
/**
|
16
|
|
- * All known recording sessions from the current conference.
|
17
|
|
- */
|
18
|
|
- _sessions: {},
|
19
|
|
-
|
20
|
|
- /**
|
21
|
|
- * Initialize recordingManager with other objects that are necessary for
|
22
|
|
- * starting a recording.
|
|
16
|
+ * Initialize {@code RecordingManager} with other objects that are necessary
|
|
17
|
+ * for starting a recording.
|
23
|
18
|
*
|
24
|
|
- * @param {Object} eventEmitter - The eventEmitter to be used for
|
25
|
|
- * broadcasting recording state changes.
|
26
|
|
- * @param {Object} connection - The MUC connection used for sending out
|
27
|
|
- * messages regarding recording.
|
28
|
|
- * @param {string} focusMucJid - The ID of the conference (MUC) the focus
|
29
|
|
- * is in.
|
|
19
|
+ * @param {ChatRoom} chatRoom - The chat room to handle.
|
30
|
20
|
* @returns {void}
|
31
|
21
|
*/
|
32
|
|
- init(eventEmitter, connection, focusMucJid) {
|
33
|
|
- this._eventEmitter = eventEmitter;
|
34
|
|
- this._connection = connection;
|
35
|
|
- this._focusMucJid = focusMucJid;
|
36
|
|
- },
|
|
22
|
+ constructor(chatRoom) {
|
|
23
|
+ /**
|
|
24
|
+ * All known recording sessions from the current conference.
|
|
25
|
+ */
|
|
26
|
+ this._sessions = {};
|
|
27
|
+
|
|
28
|
+ this._chatRoom = chatRoom;
|
|
29
|
+
|
|
30
|
+ this.onPresence = this.onPresence.bind(this);
|
|
31
|
+
|
|
32
|
+ this._chatRoom.eventEmitter.addListener(
|
|
33
|
+ XMPPEvents.PRESENCE_RECEIVED, this.onPresence);
|
|
34
|
+ }
|
37
|
35
|
|
38
|
36
|
/**
|
39
|
37
|
* Finds an existing recording session by session ID.
|
|
@@ -43,38 +41,27 @@ const recordingManager = {
|
43
|
41
|
*/
|
44
|
42
|
getSession(sessionID) {
|
45
|
43
|
return this._sessions[sessionID];
|
46
|
|
- },
|
|
44
|
+ }
|
47
|
45
|
|
48
|
46
|
/**
|
49
|
47
|
* Callback to invoke to parse through a presence update to find recording
|
50
|
48
|
* related updates (from Jibri participant doing the recording and the
|
51
|
49
|
* focus which controls recording).
|
52
|
50
|
*
|
53
|
|
- * @param {Node} presence - An XMPP presence update.
|
54
|
|
- * @param {boolean} isHiddenDomain - Whether or not the presence update
|
55
|
|
- * comes from a participant that is trusted but not visible, as would be the
|
56
|
|
- * case with the Jibri recorder participant.
|
|
51
|
+ * @param {Object} event - The presence data from the pubsub event.
|
|
52
|
+ * @param {Node} event.presence - An XMPP presence update.
|
|
53
|
+ * @param {boolean} event.fromHiddenDomain - Whether or not the update comes
|
|
54
|
+ * from a participant that is trusted but not visible, as would be the case
|
|
55
|
+ * with the Jibri recorder participant.
|
57
|
56
|
* @returns {void}
|
58
|
57
|
*/
|
59
|
|
- onPresence(presence, isHiddenDomain) {
|
|
58
|
+ onPresence({ fromHiddenDomain, presence }) {
|
60
|
59
|
if (recordingXMLUtils.isFromFocus(presence)) {
|
61
|
60
|
this._handleFocusPresence(presence);
|
62
|
|
- } else if (isHiddenDomain) {
|
|
61
|
+ } else if (fromHiddenDomain) {
|
63
|
62
|
this._handleJibriPresence(presence);
|
64
|
63
|
}
|
65
|
|
- },
|
66
|
|
-
|
67
|
|
- /**
|
68
|
|
- * Sets the currently known ID of the conference (MUC). This method exists
|
69
|
|
- * in case the ID is not known at init time.
|
70
|
|
- *
|
71
|
|
- * @param {string} focusMucJid - The ID of the conference (MUC) the focus
|
72
|
|
- * is in.
|
73
|
|
- * @returns {void}
|
74
|
|
- */
|
75
|
|
- setFocusMucJid(focusMucJid) {
|
76
|
|
- this._focusMucJid = focusMucJid;
|
77
|
|
- },
|
|
64
|
+ }
|
78
|
65
|
|
79
|
66
|
/**
|
80
|
67
|
* Start a recording session.
|
|
@@ -93,12 +80,12 @@ const recordingManager = {
|
93
|
80
|
startRecording(options) {
|
94
|
81
|
const session = new JibriSession({
|
95
|
82
|
...options,
|
96
|
|
- connection: this._connection
|
|
83
|
+ connection: this._chatRoom.connection
|
97
|
84
|
});
|
98
|
85
|
|
99
|
86
|
return session.start({
|
100
|
87
|
broadcastId: options.broadcastId,
|
101
|
|
- focusMucJid: this._focusMucJid,
|
|
88
|
+ focusMucJid: this._chatRoom.focusMucJid,
|
102
|
89
|
streamId: options.streamId
|
103
|
90
|
})
|
104
|
91
|
.then(() => {
|
|
@@ -118,7 +105,7 @@ const recordingManager = {
|
118
|
105
|
|
119
|
106
|
return Promise.reject(error);
|
120
|
107
|
});
|
121
|
|
- },
|
|
108
|
+ }
|
122
|
109
|
|
123
|
110
|
/**
|
124
|
111
|
* Stop a recording session.
|
|
@@ -132,11 +119,11 @@ const recordingManager = {
|
132
|
119
|
const session = this.getSession(sessionID);
|
133
|
120
|
|
134
|
121
|
if (session) {
|
135
|
|
- return session.stop({ focusMucJid: this._focusMucJid });
|
|
122
|
+ return session.stop({ focusMucJid: this._chatRoom.focusMucJid });
|
136
|
123
|
}
|
137
|
124
|
|
138
|
125
|
return Promise.reject(new Error('Could not find session'));
|
139
|
|
- },
|
|
126
|
+ }
|
140
|
127
|
|
141
|
128
|
/**
|
142
|
129
|
* Stores a reference to the passed in JibriSession.
|
|
@@ -146,7 +133,7 @@ const recordingManager = {
|
146
|
133
|
*/
|
147
|
134
|
_addSession(session) {
|
148
|
135
|
this._sessions[session.getID()] = session;
|
149
|
|
- },
|
|
136
|
+ }
|
150
|
137
|
|
151
|
138
|
/**
|
152
|
139
|
* Create a new instance of a recording session and stores a reference to
|
|
@@ -159,8 +146,8 @@ const recordingManager = {
|
159
|
146
|
*/
|
160
|
147
|
_createSession(sessionID, status, mode) {
|
161
|
148
|
const session = new JibriSession({
|
162
|
|
- connection: this._connection,
|
163
|
|
- focusMucJid: this._focusMucJid,
|
|
149
|
+ connection: this._chatRoom.connection,
|
|
150
|
+ focusMucJid: this._chatRoom.focusMucJid,
|
164
|
151
|
mode,
|
165
|
152
|
sessionID,
|
166
|
153
|
status
|
|
@@ -169,7 +156,7 @@ const recordingManager = {
|
169
|
156
|
this._addSession(session);
|
170
|
157
|
|
171
|
158
|
return session;
|
172
|
|
- },
|
|
159
|
+ }
|
173
|
160
|
|
174
|
161
|
/**
|
175
|
162
|
* Notifies listeners of an update to a recording session.
|
|
@@ -177,8 +164,9 @@ const recordingManager = {
|
177
|
164
|
* @param {JibriSession} session - The session that has been updated.
|
178
|
165
|
*/
|
179
|
166
|
_emitSessionUpdate(session) {
|
180
|
|
- this._eventEmitter.emit(XMPPEvents.RECORDER_STATE_CHANGED, session);
|
181
|
|
- },
|
|
167
|
+ this._chatRoom.eventEmitter.emit(
|
|
168
|
+ XMPPEvents.RECORDER_STATE_CHANGED, session);
|
|
169
|
+ }
|
182
|
170
|
|
183
|
171
|
/**
|
184
|
172
|
* Parses presence to update an existing JibriSession or to create a new
|
|
@@ -222,7 +210,7 @@ const recordingManager = {
|
222
|
210
|
}
|
223
|
211
|
|
224
|
212
|
this._emitSessionUpdate(session);
|
225
|
|
- },
|
|
213
|
+ }
|
226
|
214
|
|
227
|
215
|
/**
|
228
|
216
|
* Handles updates from the Jibri which can broadcast a YouTube URL that
|
|
@@ -252,6 +240,6 @@ const recordingManager = {
|
252
|
240
|
|
253
|
241
|
this._emitSessionUpdate(session);
|
254
|
242
|
}
|
255
|
|
-};
|
|
243
|
+}
|
256
|
244
|
|
257
|
|
-export default recordingManager;
|
|
245
|
+export default RecordingManager;
|