Skip to content

Commit 64e8c42

Browse files
[wip]
1 parent 08a80a2 commit 64e8c42

File tree

4 files changed

+36
-31
lines changed

4 files changed

+36
-31
lines changed

src/models/ffmpeg.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ export class FFMPEG extends EventEmitter {
1515
super();
1616
this.rtp = rtp;
1717
this.id = currentId++;
18-
logger.trace(`creating FFMPEG for ${this.id} on ${this.rtp.type}`);
18+
logger.verbose(`creating FFMPEG for ${this.id} on ${this.rtp.type}`);
1919
this._init();
2020
}
2121

2222
close() {
2323
this._isClosed = true;
24+
this.emit("close", this.id); // maybe different event if fail/saved properly
2425
this._cleanup();
2526
}
2627

@@ -30,7 +31,8 @@ export class FFMPEG extends EventEmitter {
3031
this._cleanup();
3132
return;
3233
}
33-
logger.trace(`FFMPEG ${this.id} is ready for ${this.rtp.type}`);
34+
logger.trace(`To implement: FFMPEG start process ${this.id} for ${this.rtp.type}`);
35+
// build FFMPEG params with rtp properties, start the process
3436
}
3537

3638
private _cleanup() {

src/models/recorder.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ export class Recorder extends EventEmitter {
4949
**/
5050
isTranscribing: boolean = false;
5151
state: RECORDER_STATE = RECORDER_STATE.STOPPED;
52-
private folder?: Folder;
52+
private _folder?: Folder;
5353
private readonly channel: Channel; // TODO rename with private prefix
54-
private readonly tasks = new Map<SessionId, RecordingTask>();
54+
private readonly _tasks = new Map<SessionId, RecordingTask>();
5555
/** Path to which the final recording will be uploaded to */
56-
private readonly metaData: Metadata = {
56+
private readonly _metaData: Metadata = {
5757
uploadAddress: "",
5858
timeStamps: {}
5959
};
@@ -67,7 +67,7 @@ export class Recorder extends EventEmitter {
6767
this._onSessionJoin = this._onSessionJoin.bind(this);
6868
this._onSessionLeave = this._onSessionLeave.bind(this);
6969
this.channel = channel;
70-
this.metaData.uploadAddress = recordingAddress;
70+
this._metaData.uploadAddress = recordingAddress;
7171
}
7272

7373
async start() {
@@ -122,15 +122,15 @@ export class Recorder extends EventEmitter {
122122
logger.warn("recording failed at saving files"); // TODO more info
123123
}
124124
if (save && !hasFailure) {
125-
await this.folder?.add("metadata.json", JSON.stringify(this.metaData));
126-
await this.folder?.seal(
125+
await this._folder?.add("metadata.json", JSON.stringify(this._metaData));
126+
await this._folder?.seal(
127127
path.join(recording.directory, `${this.channel.name}_${Date.now()}`)
128128
);
129129
} else {
130-
await this.folder?.delete();
130+
await this._folder?.delete();
131131
}
132-
this.folder = undefined;
133-
this.metaData.timeStamps = {};
132+
this._folder = undefined;
133+
this._metaData.timeStamps = {};
134134
this.state = RECORDER_STATE.STOPPED;
135135
}
136136

@@ -139,21 +139,21 @@ export class Recorder extends EventEmitter {
139139
if (!session) {
140140
return;
141141
}
142-
this.tasks.set(session.id, new RecordingTask(session, this._getTaskParameters()));
142+
this._tasks.set(session.id, new RecordingTask(session, this._getTaskParameters()));
143143
}
144144

145145
private _onSessionLeave(id: SessionId) {
146-
const task = this.tasks.get(id);
146+
const task = this._tasks.get(id);
147147
if (task) {
148148
task.stop();
149-
this.tasks.delete(id);
149+
this._tasks.delete(id);
150150
}
151151
}
152152

153153
private _mark(tag: TIME_TAG) {
154-
const events = this.metaData.timeStamps[Date.now()] || [];
154+
const events = this._metaData.timeStamps[Date.now()] || [];
155155
events.push(tag);
156-
this.metaData.timeStamps[Date.now()] = events;
156+
this._metaData.timeStamps[Date.now()] = events;
157157
}
158158

159159
private async _refreshConfiguration() {
@@ -177,28 +177,28 @@ export class Recorder extends EventEmitter {
177177

178178
private async _update() {
179179
const params = this._getTaskParameters();
180-
for (const task of this.tasks.values()) {
180+
for (const task of this._tasks.values()) {
181181
Object.assign(task, params);
182182
}
183183
}
184184

185185
private async _init() {
186186
this.state = RECORDER_STATE.STARTED;
187-
this.folder = await getFolder();
187+
this._folder = await getFolder();
188188
logger.trace(`TO IMPLEMENT: recording channel ${this.channel.name}`);
189189
for (const [sessionId, session] of this.channel.sessions) {
190-
this.tasks.set(sessionId, new RecordingTask(session, this._getTaskParameters()));
190+
this._tasks.set(sessionId, new RecordingTask(session, this._getTaskParameters()));
191191
}
192192
this.channel.on("sessionJoin", this._onSessionJoin);
193193
this.channel.on("sessionLeave", this._onSessionLeave);
194194
}
195195

196196
private async _stopTasks() {
197197
const proms = [];
198-
for (const task of this.tasks.values()) {
198+
for (const task of this._tasks.values()) {
199199
proms.push(task.stop());
200200
}
201-
this.tasks.clear();
201+
this._tasks.clear();
202202
return Promise.allSettled(proms);
203203
}
204204

src/models/recording_task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { EventEmitter } from "node:events";
33

44
import { RTP } from "#src/models/rtp.ts";
5-
import { Producer } from "mediasoup/node/lib/types";
5+
import type { Producer } from "mediasoup/node/lib/types";
66

77
import { Session } from "#src/models/session.ts";
88
import { Logger } from "#src/utils/utils.ts";

src/models/rtp.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import type { Router, Producer, Consumer, PlainTransport } from "mediasoup/node/lib/types";
1+
import type {
2+
Router,
3+
Producer,
4+
Consumer,
5+
PlainTransport,
6+
MediaKind
7+
} from "mediasoup/node/lib/types";
28
import { getPort, type DynamicPort } from "#src/services/resources.ts";
39
import { rtc } from "#src/config.ts";
410
import { Deferred } from "#src/utils/utils.ts";
@@ -9,6 +15,7 @@ export class RTP {
915
payloadType?: number;
1016
clockRate?: number;
1117
codec?: string;
18+
kind?: MediaKind;
1219
channels?: number;
1320
type: STREAM_TYPE;
1421
private _router: Router;
@@ -59,20 +66,16 @@ export class RTP {
5966
paused: true
6067
});
6168
if (this._isClosed) {
62-
// may be closed by the time the consume is created
69+
// may be closed by the time the consumer is created
6370
this._cleanup();
6471
return;
6572
}
66-
// TODO may want to use producer.getStats() to get the codec info
67-
// for val of producer.getStats().values() { if val.type === "codec": val.minetype, val.clockRate,... }
68-
//const codecData = this._channel.router.rtpCapabilities.codecs.find(
69-
// (codec) => codec.kind === producer.kind
70-
//);
7173
const codecData = this._producer.rtpParameters.codecs[0];
74+
this.kind = this._producer.kind;
7275
this.payloadType = codecData.payloadType;
7376
this.clockRate = codecData.clockRate;
74-
this.codec = codecData.mimeType.replace(`${this._producer.kind}`, "");
75-
this.channels = this._producer.kind === "audio" ? codecData.channels : undefined;
77+
this.codec = codecData.mimeType.replace(`${this.kind}`, "");
78+
this.channels = this.kind === "audio" ? codecData.channels : undefined;
7679
this.isReady.resolve();
7780
} catch {
7881
this.close();

0 commit comments

Comments
 (0)