This commit is contained in:
Nuwan 2025-04-16 23:47:24 +05:30
parent 0f074b1e37
commit ce5bb82fb5
1 changed files with 112 additions and 0 deletions

View File

@ -463,17 +463,129 @@
return { isRecording: isRecording, recordingClientId: recordingClientId };
}
async function getCurrentRecordingState() {
var recording = null;
var recordingId = await context.jamClient.GetCurrentRecordingId();
if (recordingId && recordingId != "") {
recording = await rest.getRecordingPromise({ id: recordingId })
}
return {
isRecording: recording !== null,
recordingOwnerId: recording ? recording.owner.id : null,
}
}
function handleRecordingStarted(recordingId, result, clientId) {
var success = result.success;
var reason = result.reason;
var detail = result.detail;
// in this scenario, we don't know all the tracks of the user.
// we need to ask sessionModel to populate us with the recording data ASAP
currentRecording = rest.getRecordingPromise({ id: recordingId })
currentRecording
.then(function (recording) {
currentRecordingId = recording.id;
currentOrLastRecordingId = recording.id;
})
.catch(function () {
abortRecording(recordingId, 'populate-recording-info', app.clientId);
});
var details = { recordingId: recordingId, isRecording: false }
$self.triggerHandler('startingRecording', details);
context.RecordingActions.startingRecording(details)
currentlyRecording = true;
details = { clientId: clientId, recordingId: recordingId, isRecording: true }
$self.triggerHandler('startedRecording', details);
context.RecordingActions.startedRecording(details)
}
function handleRecordingStopped(recordingId, result) {
var session = context.SessionStore.getCurrentOrLastSession();
if (!session) {
logger.debug("no session, so no recording");
return;
}
context.SessionStore.updateSessionInfo(session)
getCurrentRecordingState().then(function (recordingState) {
if (recordingState.isRecording) {
// we are still recording, so don't transition to stopped
logger.debug("recording is still running, so don't transition to stopped");
return;
}
if (recordingId == "video") {
// comes from VideoRecordingStopped
return;
}
logger.debug("handleRecordingStopped " + recordingId, result)
var success = result.success;
var reason = result.reason;
var detail = result.detail;
var details = { recordingId: recordingId, reason: reason, detail: detail, isRecording: true }
$self.triggerHandler('stoppingRecording', details);
context.RecordingActions.stoppingRecording(details)
// the backend says the recording must be stopped.
// tell the server to stop it too
rest.stopRecording({
id: recordingId
})
.always(function () {
transitionToStopped();
})
.fail(function (jqXHR, textStatus, errorMessage) {
if (jqXHR.status == 422) {
logger.debug("recording already stopped %o", arguments);
var details = { recordingId: recordingId, reason: reason, detail: detail, isRecording: false }
$self.triggerHandler('stoppedRecording', details);
context.RecordingActions.stoppedRecording(details)
}
else if (jqXHR.status == 404) {
logger.debug("recording is already deleted %o", arguments);
var details = { recordingId: recordingId, reason: reason, detail: detail, isRecording: false }
$self.triggerHandler('stoppedRecording', details);
context.RecordingActions.stoppedRecording(details)
}
else {
var details = { recordingId: recordingId, reason: textStatus, detail: errorMessage, isRecording: false }
$self.triggerHandler('stoppedRecording', details);
context.RecordingActions.stoppedRecording(details)
}
})
.done(function () {
var details = { recordingId: recordingId, reason: reason, detail: detail, isRecording: false }
$self.triggerHandler('stoppedRecording', details);
context.RecordingActions.stoppedRecording(details)
})
}).catch(function (error) {
console.error("Error reading recording state:", error);
});
}
this.initialize = function() {
};
this.startRecording = startRecording;
this.stopRecording = stopRecording;
this.onServerStopRecording = onServerStopRecording;
this.onServerStartRecording = onServerStartRecording;
this.isRecording = isRecording;
this.reset = reset;
this.stopRecordingIfNeeded = stopRecordingIfNeeded;
this.currentOrLastRecordingId = function () { return currentOrLastRecordingId; };
this.getRecordingState = getRecordingState;
this.getCurrentRecordingState = getCurrentRecordingState;
context.JK.HandleRecordingStartResult = handleRecordingStartResult;
context.JK.HandleRecordingStopResult = handleRecordingStopResult;