{"version":3,"file":"dlg_devicesettings.min.js","sources":["../src/dlg_devicesettings.js"],"sourcesContent":["define(['jquery', 'core/log', 'filter_poodll/dlg_poodll'], function ($, log, dialog) {\r\n\r\n    log.debug('Device settings dialog: initialising');\r\n\r\n\r\n    return {\r\n        dlg: null,\r\n        pmr: null,\r\n        instanceprops: null,\r\n        dlgbox: null,\r\n        mediatype: null,\r\n\r\n        init: function (pmr, instanceprops) {\r\n            this.dlg = dialog.clone();\r\n            this.dlg.setHeader('settings');\r\n            this.pmr = pmr;\r\n            this.instanceprops = instanceprops;\r\n            this.mediatype = instanceprops.config.mediatype;\r\n        },\r\n        //for making multiple instances\r\n        clone: function () {\r\n            return $.extend(true, {}, this);\r\n        },\r\n\r\n        fetch_dialogue_box: function () {\r\n            //this returns html that will be set to the DOM\r\n            return this.dlg.fetch_dialogue_box('settings');\r\n        },\r\n        set_dialogue_box: function (dlgbox) {\r\n            //this is the jquery object that is the dlgbox in the DOM\r\n            this.dlgbox = dlgbox;\r\n            this.dlg.set_dialogue_box(dlgbox);\r\n\r\n        },\r\n        set_media_type: function (mediatype) {\r\n            //used by screen recorder skin to overide default media type in order to not show video\r\n            this.mediatype = mediatype;\r\n\r\n        },\r\n        open: function () {\r\n            var self = this;\r\n            var ip = this.instanceprops;\r\n            // fetch the audio and video devices\r\n            navigator.mediaDevices.enumerateDevices()\r\n                .then(function (devices) {\r\n                    var audiodevices = [];\r\n                    var videodevices = [];\r\n\r\n                    devices.forEach(function (device) {\r\n                        switch (device.kind) {\r\n                            case 'audioinput':\r\n                                audiodevices.push(device);\r\n                                break;\r\n                            case 'videoinput':\r\n                                videodevices.push(device);\r\n                                break;\r\n                        }\r\n                    });\r\n                    //make select boxes of devices\r\n                    var audioselect = '<div class=\"devicesettings_select\"><span class=\"devicesettings_select_label\">Audio: </span>' + self.makeSelect(audiodevices, 'audio') + '</div>';\r\n                    var videoselect = '<div class=\"devicesettings_select\"><span class=\"devicesettings_select_label\">Video: </span>' + self.makeSelect(videodevices, 'video') + '</div>';\r\n                    var content = '<div class=\"filter_poodll_mediadevices\">';\r\n\r\n                    if (self.mediatype == 'video') {\r\n                        content += audioselect + '<br>' + videoselect;\r\n                    } else {\r\n                        content += audioselect;\r\n                    }\r\n                    content += '</div>';\r\n                    //set the html to the dialog and DOM\r\n                    self.dlg.setContent(content);\r\n                    //register events for the select boxes\r\n                    self.registerEvents();\r\n\r\n                    if (self.mediatype == 'video') {\r\n                        self.dlg.onclose = function () {\r\n                            self.resetVideoUserInterface();\r\n                        };\r\n                    }\r\n\r\n                    //open the dialog\r\n                    self.dlg.open();\r\n                }).catch(function (e) {\r\n                log.debug(e);\r\n            });\r\n        },\r\n\r\n        registerEvents: function () {\r\n            var self = this;\r\n            var ip = this.instanceprops;\r\n            var preview = ip.controlbar.preview[0];\r\n\r\n\r\n            if (preview) {\r\n                preview.pause();\r\n            }\r\n            if (ip.mediaRecorder) {\r\n                ip.mediaRecorder.stop();\r\n            }\r\n\r\n            this.dlgbox.find('.select_settings_audio').change(function () {\r\n                self.instanceprops.useraudiodeviceid = this.value;\r\n            });\r\n\r\n            this.dlgbox.find('.select_settings_video').change(function () {\r\n                self.instanceprops.uservideodeviceid = this.value;\r\n\r\n                //This kind of worked but actually it was problematic in android\r\n                //and even on desktop because we reset the video when it was hidden\r\n                //we moved it to the onclose event\r\n                //self.resetUserInterface();\t\t\r\n            });\r\n        },\r\n\r\n        resetVideoUserInterface: function () {\r\n\r\n            //set up refs to use in inline functions and keep it brief\r\n            var ip = this.instanceprops;\r\n            var preview = ip.controlbar.preview[0];\r\n            var pmr = this.pmr;\r\n            //fetch video constraints\r\n            var constraints = pmr.fetch_video_constraints(ip);\r\n\r\n            //We always tidy up old streams before calling getUserMedia\r\n            //if we do not do this, we can get issues of the front or back camera being sticky\r\n            //but it causes a visible flicker and also an audio/video sync issue.\r\n            //so we removed the same call from poodll_mediarecorder.js doStartAudio\r\n            //but left it here\r\n            pmr.tidy_old_stream(ip.controlbarid);\r\n\r\n            //get a new mediastream based on those constraints and update PMR accordingly\r\n            navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {\r\n\r\n                //stop any playing tracks of the current stream\t\r\n                pmr.restream_preview_video_player(ip.controlbarid, stream)\r\n\r\n\r\n            }).catch(function (err) {\r\n                log.debug('location 4567');\r\n                log.debug(err);\r\n            });\r\n\r\n        },\r\n\r\n        makeSelect: function (devices, devicetype) {\r\n            //if no devices we are not ready\r\n            //must replace with lang string\r\n            if (devices.length == 1 && devices[0].label == '') {\r\n                return '<div>No devices available yet.</div>';\r\n            }\r\n            //get selected useraudiodevice and videodevice (if any)\r\n            switch (devicetype) {\r\n                case 'audio':\r\n                    var userdeviceid = this.instanceprops.useraudiodeviceid;\r\n                    break;\r\n                case 'video':\r\n                    var userdeviceid = this.instanceprops.uservideodeviceid;\r\n            }\r\n\r\n            //build dropdown from device list\r\n            var dlg_dropdown = '<select class=\"select_settings_' + devicetype + '\">';\r\n            devices.forEach(function (device) {\r\n                var selected = '';\r\n                if (userdeviceid == device.deviceId) {\r\n                    selected = 'selected';\r\n                }\r\n                dlg_dropdown += '<option value=\"' + device.deviceId + '\" ' + ' ' + selected + '>' + device.label + '</option>';\r\n            });\r\n            dlg_dropdown += '</select>';\r\n            //return dropdown\r\n            return dlg_dropdown;\r\n        }\r\n    }\r\n\r\n});"],"names":["define","$","log","dialog","debug","dlg","pmr","instanceprops","dlgbox","mediatype","init","clone","setHeader","config","extend","this","fetch_dialogue_box","set_dialogue_box","set_media_type","open","self","navigator","mediaDevices","enumerateDevices","then","devices","audiodevices","videodevices","forEach","device","kind","push","audioselect","makeSelect","videoselect","content","setContent","registerEvents","onclose","resetVideoUserInterface","catch","e","ip","preview","controlbar","pause","mediaRecorder","stop","find","change","useraudiodeviceid","value","uservideodeviceid","constraints","fetch_video_constraints","tidy_old_stream","controlbarid","getUserMedia","stream","restream_preview_video_player","err","devicetype","length","label","userdeviceid","dlg_dropdown","selected","deviceId"],"mappings":"AAAAA,0CAAO,CAAC,SAAU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