<commit_before>import { template } from "../template";
import { notify } from "../notify";
import { ng } from "../ng-start";
import { VideoRecorder } from "./VideoRecorder";
import { model } from "../modelDefinitions";
import {appPrefix, devices, deviceType} from '../globals';
import { IObjectGuardDelegate } from "../navigationGuard";
import { Me } from "../me";
import { http } from '../http';
import { idiom as lang } from "../idiom";

class VideoGuardModel implements IObjectGuardDelegate{
    hasRecorded = false;
    guardObjectIsDirty(): boolean{
        return this.hasRecorded;
    }
    guardObjectReset(): void{
        this.hasRecorded = false;
    }
}
interface VideoControllerScope {
    RECORD_MAX_TIME: number;
    template: typeof template
    me: typeof model.me
    recorder: VideoRecorder;
    display: {}
    authorized: boolean
    hasRight:boolean
    videoState: 'idle' | 'starting' | 'ready' | 'recording' | 'recorded' | 'incompatible' | 'uploading'
    videofile: { name?: string }
    action: 'videorecorder'
    notFound: boolean
    currentDuration: number
    recordStartTime: number
    recordTimeInMs: number
    recordTime: string
    recordMaxTime: number
    videoInputDevices: MediaDeviceInfo[]
    selectedVid: MediaDeviceInfo;
    guard: VideoGuardModel;
    isIncompatible(): boolean
    isIncompatibleDevice(): boolean
    isIncompatibleBrowser(): boolean
    startCamera(): void
    stopRecord(pause?: boolean): void
    startRecord(resume?: boolean): Promise<void>
	switchCamera(id): void;
    switchRecording(): void
    redo(): void;
    play(): void;
    upload(): void;
    pad(num: number): string;
    openMainPage(): void
    showActions(): boolean
    isUploading():boolean;
    canPlay():boolean;
    isCameraVisible(): boolean;
    isReady(): boolean
    isRecorded(): boolean;
    isRecording(): boolean;
    isPlaying():boolean;
    website: any;
    selectedWebsite: any;
    $apply: any
    $emit: any
    $on: any;
    $root: any
}

export const VideoController = ng.controller('VideoController', ['$scope', 'model', 'route', '$element',
    ($scope: VideoControllerScope, model, route, $element) => {
        $scope.hasRight = true;
        $scope.guard = new VideoGuardModel();
        $scope.RECORD_MAX_TIME = 3; // MAX TIME OF RECORDING IN MINUTES
        $scope.template = template;
        $scope.me = model.me;
        $scope.recorder = new VideoRecorder(() => {
            return jQuery($element).find('video')[0] as HTMLMediaElement;
        }, (e) => {
            handleDuration(e);
        });
        let isPlaying = false;
        const sub = $scope.recorder.onPlayChanged.subscribe(e=>{
            isPlaying = e.type=='play';
            safeApply();
        })
        $scope.display = {};
        $scope.authorized = false;
        $scope.videoState = 'idle';
        $scope.videofile = {};
        $scope.action = 'videorecorder';
        $scope.notFound = false;
        $scope.currentDuration = 0;
        $scope.recordStartTime = 0;
        $scope.recordTime = '00:00';
        $scope.recordTimeInMs = 0;
        $scope.recordMaxTime = $scope.RECORD_MAX_TIME * 60000;

        const backCameraChoice = {deviceId:"environment", label: lang.translate("video.back.camera"), groupId:'', kind:'videoinput'} as MediaDeviceInfo;
        const frontCameraChoice = {deviceId:"user", label: lang.translate("video.front.camera"), groupId:'', kind:'videoinput'} as MediaDeviceInfo;
        // Enumerate video stream devices
        Promise.resolve().then( () => {
            return navigator.mediaDevices.enumerateDevices();
        })
        // Filter on video inputs only
        .then( devices => { 
            return devices.filter( device => { 
                //console.debug( JSON.stringify(device) );
                return device.kind === "videoinput";
            })
        })
        // Assemble the final cameras list
        .then( videoinputs => {
            switch( deviceType ) {
                case "Mobile":
                case "Tablet":
                    if( videoinputs && videoinputs.length>1 ) {
                        // This mobile/tablet has more than 1 camera 
                        // => we assume at least one is on the front (user) and one is on the back (environment),
                        //    and let the system choose the best for us.
                        $scope.videoInputDevices = [backCameraChoice, frontCameraChoice];
                    } else {
                        // Else we let the system use the only one that exists (or none)
                        $scope.videoInputDevices = [backCameraChoice];
                    }
                    break;
                default: // "Desktop" or other future types => list all cameras without distinction.
                    $scope.videoInputDevices = videoinputs;
                    break;
            }
            $scope.selectedVid = $scope.videoInputDevices[0];
            tryStartStreaming();
        })
        .catch( () => { 
            $scope.videoInputDevices = [backCameraChoice];
            $scope.selectedVid = $scope.videoInputDevices[0];
            tryStartStreaming();
        })<commit_msg>fix(captation): #42233, wait a bit after the user consent was given, before listing available video devices.<commit_after>import { template } from "../template";
import { notify } from "../notify";
import { ng } from "../ng-start";
import { VideoRecorder } from "./VideoRecorder";
import { model } from "../modelDefinitions";
import {appPrefix, devices, deviceType} from '../globals';
import { IObjectGuardDelegate } from "../navigationGuard";
import { Me } from "../me";
import { http } from '../http';
import { idiom as lang } from "../idiom";

class VideoGuardModel implements IObjectGuardDelegate{
    hasRecorded = false;
    guardObjectIsDirty(): boolean{
        return this.hasRecorded;
    }
    guardObjectReset(): void{
        this.hasRecorded = false;
    }
}
interface VideoControllerScope {
    RECORD_MAX_TIME: number;
    template: typeof template
    me: typeof model.me
    recorder: VideoRecorder;
    display: {}
    authorized: boolean
    hasRight:boolean
    videoState: 'idle' | 'starting' | 'ready' | 'recording' | 'recorded' | 'incompatible' | 'uploading'
    videofile: { name?: string }
    action: 'videorecorder'
    notFound: boolean
    currentDuration: number
    recordStartTime: number
    recordTimeInMs: number
    recordTime: string
    recordMaxTime: number
    videoInputDevices: MediaDeviceInfo[]
    selectedVid: MediaDeviceInfo;
    guard: VideoGuardModel;
    isIncompatible(): boolean
    isIncompatibleDevice(): boolean
    isIncompatibleBrowser(): boolean
    startCamera(): void
    stopRecord(pause?: boolean): void
    startRecord(resume?: boolean): Promise<void>
	switchCamera(id): void;
    switchRecording(): void
    redo(): void;
    play(): void;
    upload(): void;
    pad(num: number): string;
    openMainPage(): void
    showActions(): boolean
    isUploading():boolean;
    canPlay():boolean;
    isCameraVisible(): boolean;
    isReady(): boolean
    isRecorded(): boolean;
    isRecording(): boolean;
    isPlaying():boolean;
    website: any;
    selectedWebsite: any;
    $apply: any
    $emit: any
    $on: any;
    $root: any
}

export const VideoController = ng.controller('VideoController', ['$scope', 'model', 'route', '$element',
    ($scope: VideoControllerScope, model, route, $element) => {
        $scope.hasRight = true;
        $scope.guard = new VideoGuardModel();
        $scope.RECORD_MAX_TIME = 3; // MAX TIME OF RECORDING IN MINUTES
        $scope.template = template;
        $scope.me = model.me;
        $scope.recorder = new VideoRecorder(() => {
            return jQuery($element).find('video')[0] as HTMLMediaElement;
        }, (e) => {
            handleDuration(e);
        });
        let isPlaying = false;
        const sub = $scope.recorder.onPlayChanged.subscribe(e=>{
            isPlaying = e.type=='play';
            safeApply();
        })
        $scope.display = {};
        $scope.authorized = false;
        $scope.videoState = 'idle';
        $scope.videofile = {};
        $scope.action = 'videorecorder';
        $scope.notFound = false;
        $scope.currentDuration = 0;
        $scope.recordStartTime = 0;
        $scope.recordTime = '00:00';
        $scope.recordTimeInMs = 0;
        $scope.recordMaxTime = $scope.RECORD_MAX_TIME * 60000;

        const backCameraChoice = {deviceId:"environment", label: lang.translate("video.back.camera"), groupId:'', kind:'videoinput'} as MediaDeviceInfo;
        const frontCameraChoice = {deviceId:"user", label: lang.translate("video.front.camera"), groupId:'', kind:'videoinput'} as MediaDeviceInfo;
        // First call to the API, so that the operating system ask for user's consent, if needed.
        Promise.resolve().then( () => {
            navigator.mediaDevices.enumerateDevices();
        })
        // ...Then enumerate video stream devices,
        .then( () => {
            return navigator.mediaDevices.enumerateDevices();
        })// ...Filter on video inputs only,
        .then( devices => { 
            return devices.filter( device => { 
                //console.debug( JSON.stringify(device) );
                return device.kind === "videoinput";
            })
        })
        // ...Assemble the final cameras list,
        .then( videoinputs => {
            switch( deviceType ) {
                case "Mobile":
                case "Tablet":
                    if( videoinputs && videoinputs.length>1 ) {
                        // This mobile/tablet has more than 1 camera 
                        // => we assume at least one is on the front (user) and one is on the back (environment),
                        //    and let the system choose the best for us.
                        $scope.videoInputDevices = [backCameraChoice, frontCameraChoice];
                    } else {
                        // Else we let the system use the only one that exists (or none)
                        $scope.videoInputDevices = [backCameraChoice];
                    }
                    break;
                default: // "Desktop" or other future types => list all cameras without distinction.
                    $scope.videoInputDevices = videoinputs;
                    break;
            }
            $scope.selectedVid = $scope.videoInputDevices[0];
            tryStartStreaming();
        })
        .catch( () => { 
            $scope.videoInputDevices = [backCameraChoice];
            $scope.selectedVid = $scope.videoInputDevices[0];
            tryStartStreaming();
        })
{'fraction_non_alphanumeric': 0.12286785379568885, 'fraction_numerical': 0.0038425492033739455, 'mean_word_length': 2.2444512009729403, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4380087', 'n_tokens_mistral': 2941, 'n_tokens_neox': 2827, 'n_words': 754}