# Source: EyeToneAnalyzer.js

    export class EyeToneAnalyzer {
        static async Create(modulesManager, onProgress) {
            const bsc = modulesManager.modules.visage.module;
            const bscAnalyzer = bsc.GetEyeToneAnalysis();

            return new EyeToneAnalyzer(bscAnalyzer, bsc);
        }

        constructor(bscAnalyzer, bsc) {
            this.bscAnalyzer = bscAnalyzer;
            this.bsc = bsc;
        }

        promise = null;

        /**
         *@callback EyeToneCallback
         *@param {Object} EyeToneAnalyzerResult - Analyzed eye shape
         *@param {EyeToneEstimates} EyeToneAnalyzerResult.estimates - Object containing estimates for hue, saturation and lightness.
         *@param {number} EyeToneAnalyzerResult.frameIndex -  Index of the frame that has been analyzed.
         *@param { "OFF"|"OK"|"RECOVERING"|"INIT" } EyeShapeAnalyzerResult.status - Indicates tracking status.
         */

        /**
         * Initiates the eye shape analysis. When a frame has been analyzed a call to the {@link EyeToneCallback}
         * function is issued, with the analysis results passed as the argument.
         * <br/>
         * @param {EyeToneCallback} EyeToneCallback - callback which will be called every time a new frame is analyzed
         */
        StartAnalysis(EyeToneCallback) {
            const convert = (result) => {
                const status_mapping = new Map([
                    [this.bsc.TrackStatus.off, "OFF"],
                    [this.bsc.TrackStatus.init, "INIT"],
                    [this.bsc.TrackStatus.recovering, "RECOVERING"],
                    [this.bsc.TrackStatus.ok, "OK"],
                ]);

                let res = {
                    frameIndex: result.frameIndex,
                    estimates: result.estimates,
                    status: status_mapping.get(result.status),
                };
                result.delete();

                return res;
            };

            const convertThenCall = (result) => {
                EyeToneCallback(convert(result));
            };

            this.bscAnalyzer.SetCallback(convertThenCall);
            this.bscAnalyzer.StartAnalysis();
        }

        /**
         * Stops the eye tone analysis and stops issuing calls to the callback given as a argument to the
         * {@link StartAnalysis} function.
         * <br/>
         */
        StopAnalysis() {
            this.bscAnalyzer.StopAnalysis();
        }

        /**
         * Resets the internal state of the eye tone analyzer. This is useful when switching between frames of different people.
         */
        Reset() {
            this.bscAnalyzer.Reset();
        }
    }