use less promises to process logs and statistics

pull/294/head
Taner Sener 4 years ago
parent b8ff0d5995
commit 41b3df6fa8
  1. 43
      react-native/src/index.js

@ -20,18 +20,11 @@ export const LogRedirectionStrategy = {
}
export const SessionState = {
CREATED: 0,
RUNNING: 1,
FAILED: 2,
COMPLETED: 3
CREATED: 0, RUNNING: 1, FAILED: 2, COMPLETED: 3
}
export const Signal = {
SIGINT: 2,
SIGQUIT: 3,
SIGPIPE: 13,
SIGTERM: 15,
SIGXCPU: 24
SIGINT: 2, SIGQUIT: 3, SIGPIPE: 13, SIGTERM: 15, SIGXCPU: 24
}
class FFmpegKitReactNativeEventEmitter extends NativeEventEmitter {
@ -1424,16 +1417,7 @@ class FFmpegKitFactory {
static mapToStatistics(statisticsMap) {
if (statisticsMap !== undefined) {
return new Statistics(
statisticsMap.sessionId,
statisticsMap.videoFrameNumber,
statisticsMap.videoFps,
statisticsMap.videoQuality,
statisticsMap.size,
statisticsMap.time,
statisticsMap.bitrate,
statisticsMap.speed
);
return new Statistics(statisticsMap.sessionId, statisticsMap.videoFrameNumber, statisticsMap.videoFps, statisticsMap.videoQuality, statisticsMap.size, statisticsMap.time, statisticsMap.bitrate, statisticsMap.speed);
} else {
return undefined;
}
@ -1571,15 +1555,16 @@ class FFmpegKitInitializer {
return;
}
FFmpegKitConfig.getSession(sessionId).then(session => {
activeLogRedirectionStrategy = session.getLogRedirectionStrategy();
if (session.getLogCallback() !== undefined) {
if (FFmpegKitFactory.getLogRedirectionStrategy(sessionId) !== undefined) {
activeLogRedirectionStrategy = FFmpegKitFactory.getLogRedirectionStrategy(sessionId);
}
let activeLogCallback = FFmpegKitFactory.getLogCallback(sessionId);
if (activeLogCallback !== undefined) {
sessionCallbackDefined = true;
try {
// NOTIFY SESSION CALLBACK DEFINED
session.getLogCallback()(log);
activeLogCallback(log);
} catch (err) {
console.log("Exception thrown inside session LogCallback block.", err.stack);
}
@ -1635,24 +1620,21 @@ class FFmpegKitInitializer {
console.log(text);
}
}
});
}
static processStatisticsCallbackEvent(event) {
let statistics = FFmpegKitFactory.mapToStatistics(event);
let sessionId = event.sessionId;
FFmpegKitConfig.getSession(sessionId).then(session => {
if (session.isFFmpeg()) {
if (session.getStatisticsCallback() !== undefined) {
let activeStatisticsCallback = FFmpegKitFactory.getStatisticsCallback(sessionId);
if (activeStatisticsCallback !== undefined) {
try {
// NOTIFY SESSION CALLBACK DEFINED
session.getStatisticsCallback()(statistics);
activeStatisticsCallback(statistics);
} catch (err) {
console.log("Exception thrown inside session StatisticsCallback block.", err.stack);
}
}
}
let globalStatisticsCallbackFunction = FFmpegKitFactory.getGlobalStatisticsCallback();
if (globalStatisticsCallbackFunction !== undefined) {
@ -1663,7 +1645,6 @@ class FFmpegKitInitializer {
console.log("Exception thrown inside global StatisticsCallback block.", err.stack);
}
}
});
}
static processExecuteCallbackEvent(event) {

Loading…
Cancel
Save