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

Loading…
Cancel
Save