Skip to content

Commit 0ee3aca

Browse files
[mirotalkc2c] - #21 fix recording truncation by flushing data incrementally via timeslice and guarding track changes
1 parent 2cb8b7b commit 0ee3aca

6 files changed

Lines changed: 46 additions & 7 deletions

File tree

.env.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ====================================================
2-
# MiroTalk C2C v.1.2.75 - Environment Configuration
2+
# MiroTalk C2C v.1.2.76 - Environment Configuration
33
# ====================================================
44

55
# App environment

backend/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @license For private project or commercial purposes contact us at: license.mirotalk@gmail.com or purchase it directly via Code Canyon:
1010
* @license https://codecanyon.net/item/mirotalk-c2c-webrtc-real-time-cam-2-cam-video-conferences-and-screen-sharing/43383005
1111
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
12-
* @version 1.2.75
12+
* @version 1.2.76
1313
*/
1414

1515
require('dotenv').config();

frontend/js/client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @license For private project or commercial purposes contact us at: license.mirotalk@gmail.com or purchase it directly via Code Canyon:
1010
* @license https://codecanyon.net/item/mirotalk-c2c-webrtc-real-time-cam-2-cam-video-conferences-and-screen-sharing/43383005
1111
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
12-
* @version 1.2.75
12+
* @version 1.2.76
1313
*/
1414

1515
const roomId = new URLSearchParams(window.location.search).get('room');
@@ -1231,6 +1231,9 @@ function toggleSettings() {
12311231
}
12321232

12331233
function swapCamera() {
1234+
if (recording && recording.isStreamRecording()) {
1235+
return popupMessage('toast', 'Recording', 'Cannot swap camera while recording', 'top');
1236+
}
12341237
camera = camera == 'user' ? 'environment' : 'user';
12351238
const camVideo = camera == 'user' ? true : { facingMode: { exact: camera } };
12361239
navigator.mediaDevices
@@ -1252,6 +1255,9 @@ function swapCamera() {
12521255
}
12531256

12541257
async function toggleScreenSharing() {
1258+
if (recording && recording.isStreamRecording()) {
1259+
return popupMessage('toast', 'Recording', 'Cannot toggle screen sharing while recording', 'top');
1260+
}
12551261
const constraints = { audio: true, video: true };
12561262
try {
12571263
let newStream;
@@ -1298,6 +1304,9 @@ async function toggleScreenSharing() {
12981304
}
12991305

13001306
function changeCamera(deviceId = false) {
1307+
if (recording && recording.isStreamRecording()) {
1308+
return popupMessage('toast', 'Recording', 'Cannot change camera while recording', 'top');
1309+
}
13011310
const videoConstraints = getVideoConstraints(deviceId);
13021311

13031312
navigator.mediaDevices
@@ -1331,6 +1340,9 @@ function changeCamera(deviceId = false) {
13311340
}
13321341

13331342
function changeMicrophone(deviceId = false) {
1343+
if (recording && recording.isStreamRecording()) {
1344+
return popupMessage('toast', 'Recording', 'Cannot change microphone while recording', 'top');
1345+
}
13341346
const audioConstraints = getAudioConstraints(deviceId);
13351347

13361348
navigator.mediaDevices

frontend/js/recording.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Recording {
1212
this._recordedBlobs = [];
1313
this._recordingStream = false;
1414
this._recStartTs = null;
15+
this._trackEndedListeners = [];
1516
}
1617

1718
start() {
@@ -20,7 +21,8 @@ class Recording {
2021
options = { mimeType: options[0] };
2122
try {
2223
this._mediaRecorder = new MediaRecorder(this._stream, options);
23-
this._mediaRecorder.start();
24+
this._mediaRecorder.start(1000);
25+
this._listenTrackEnded();
2426
this._mediaRecorder.addEventListener('start', (e) => {
2527
playSound('recStart');
2628
console.log('MediaRecorder started', e);
@@ -36,6 +38,7 @@ class Recording {
3638
this._mediaRecorder.addEventListener('stop', (e) => {
3739
this._recordingStream = false;
3840
console.log('MediaRecorder stopped', e);
41+
this._removeTrackEndedListeners();
3942
this.handleElements();
4043
stopRecordingTimer();
4144
this.downloadRecordedStream();
@@ -149,4 +152,28 @@ class Recording {
149152
stop() {
150153
this._mediaRecorder.stop();
151154
}
155+
156+
_listenTrackEnded() {
157+
this._stream.getTracks().forEach((track) => {
158+
const handler = () => {
159+
console.warn('Recording track ended during recording:', track.kind, track.label);
160+
if (this._mediaRecorder && this._mediaRecorder.state === 'recording') {
161+
try {
162+
this._mediaRecorder.requestData();
163+
} catch (e) {
164+
console.warn('requestData after track ended failed:', e);
165+
}
166+
}
167+
};
168+
track.addEventListener('ended', handler);
169+
this._trackEndedListeners.push({ track, handler });
170+
});
171+
}
172+
173+
_removeTrackEndedListeners() {
174+
this._trackEndedListeners.forEach(({ track, handler }) => {
175+
track.removeEventListener('ended', handler);
176+
});
177+
this._trackEndedListeners = [];
178+
}
152179
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mirotalkc2c",
3-
"version": "1.2.75",
3+
"version": "1.2.76",
44
"description": "A free WebRTC Cam-2-Cam browser-based video calls",
55
"main": "server.js",
66
"scripts": {

0 commit comments

Comments
 (0)