Beispiel #1
0
 def __init__(self, remi_app_instance, **kwargs):
     """
     This class uses javascript code from cookie.js framework ( https://developer.mozilla.org/en-US/docs/Web/API/document.cookie )
     /*\
     |*|
     |*|  :: cookies.js ::
     |*|
     |*|  A complete cookies reader/writer framework with full unicode support.
     |*|
     |*|  Revision #2 - June 13th, 2017
     |*|
     |*|  https://developer.mozilla.org/en-US/docs/Web/API/document.cookie
     |*|  https://developer.mozilla.org/User:fusionchess
     |*|  https://github.com/madmurphy/cookies.js
     |*|
     |*|  This framework is released under the GNU Public License, version 3 or later.
     |*|  http://www.gnu.org/licenses/gpl-3.0-standalone.html
     |*|
     \*/
     """
     super(CookieInterface, self).__init__(**kwargs)
     self.eventManager = gui._EventManager(self)
     self.app_instance = remi_app_instance
     self.EVENT_ONCOOKIES = "on_cookies"
     self.cookies = {}
Beispiel #2
0
 def __init__(self, cookieInterface, session_timeout_seconds = 60, **kwargs):
     super(LoginManager, self).__init__(**kwargs)
     self.eventManager = gui._EventManager(self)
     self.expired = True
     self.session_uid = str(random.randint(1,999999999))
     self.cookieInterface = cookieInterface
     self.session_timeout_seconds = session_timeout_seconds
     self.timer_request_cookies() #starts the cookie refresh
     self.timeout_timer = None #checks the internal timeout
     self.EVENT_ONSESSIONEXPIRED = "on_session_expired"
Beispiel #3
0
 def __init__(self, **kwargs):
     super(GeolocationAPI, self).__init__(_type='script', **kwargs)
     self.eventManager = gui._EventManager(self)
     self.EVENT_ONCHANGE = 'onchange'
     self.add_child("javascript", """
     navigator.geolocation.getCurrentPosition(function(position) {
         var lat = position.coords.latitude;
         var lon = position.coords.longitude;
         var params={};
         params['latitude']=lat;
         params['longitude']=lon;
         sendCallbackParam('%(id)s','%(evt)s',params);
     });
     """% {'id': self.identifier,'evt': self.EVENT_ONCHANGE})
Beispiel #4
0
 def __init__(self, **kwargs):
     super(AccelerometerAPI, self).__init__(_type='script', **kwargs)
     self.eventManager = gui._EventManager(self)
     self.EVENT_ONCHANGE = 'onchange'
     self.add_child("javascript", """
     window.ondevicemotion = function(event) {
         var accelerationX = event.accelerationIncludingGravity.x;
         var accelerationY = event.accelerationIncludingGravity.y;
         var accelerationZ = event.accelerationIncludingGravity.z;
         var params={};
         params['accelerationX']=accelerationX;
         params['accelerationY']=accelerationY;
         params['accelerationZ']=accelerationZ;
         sendCallbackParam('%(id)s','%(evt)s',params);
     }
     """% {'id': self.identifier,'evt': self.EVENT_ONCHANGE})
Beispiel #5
0
 def __init__(self, **kwargs):
     super(OrientationAPI, self).__init__(_type='script', **kwargs)
     self.eventManager = gui._EventManager(self)
     self.EVENT_ONCHANGE = 'onchange'
     self.add_child("javascript", """
     if (window.DeviceOrientationEvent) {
         window.addEventListener('deviceorientation', function(event) {
             var gamma = event.gamma;
             var beta = event.beta;
             var alpha = event.alpha;
             var params={};
             params['gamma']=gamma;
             params['beta']=beta;
             params['alpha']=alpha;
             sendCallbackParam('%(id)s','%(evt)s',params);
         });
     }
     """% {'id': self.identifier,'evt': self.EVENT_ONCHANGE})
Beispiel #6
0
    def __init__(self, app_instance, width, height, **kwargs):
        super(ImageGrabber, self).__init__(_type='script', **kwargs)
        self.app = app_instance
        self.eventManager = gui._EventManager(self)
        self.EVENT_ONCHANGE = 'onchange'
        self.EVENT_ONNEWVIDEODEVICE = 'onnewvideodevice'
        self.add_child(
            "javascript", """
            var video = null;
            var canvas = null;
            var localMediaStream = null;
            var mediaStreamTrack = null;
            var flash_on = false;


            function snapshot() {
                if (localMediaStream) {
                    var ctx = canvas.getContext('2d');
                    ctx.drawImage(video, 0, 0);
                    canvas.toBlob(function(blob){
                        var xhr = new XMLHttpRequest();
                        var fd = new FormData();
                        xhr.open("POST", "/", true);
                        xhr.setRequestHeader('filename', "test");
                        xhr.setRequestHeader('listener', '%(id)s');
                        xhr.setRequestHeader('listener_function', '%(evt_foto)s');
                        xhr.onreadystatechange = function() {
                            if (xhr.readyState == 4 && xhr.status == 200) {
                                console.log('upload success: ');
                            }else if(xhr.status == 400){
                                console.log('upload failed: ');
                            }
                        };
                        fd.append('upload_file', blob);
                        xhr.send(fd);

                        /*
                        var reader = new FileReader();
                        reader.readAsDataURL(blob); 
                        reader.onloadend = function() {
                            base64data = reader.result;                
                            var params={};
                            params['img_data']=base64data.split(',')[1];
                            sendCallbackParam('%(id)s','new_blob',params);
                        }
                        */
                    }, "image/png");
                    if(flash_on){
                        flashlight();
                        //flash_on=false;
                    }

                }
            }

            function flashlight(){
                mediaStreamTrack.applyConstraints({advanced: [{torch: true}]});
            }

            function get_available_videoinputs(){
                //looking for available video input devices
                navigator.mediaDevices.enumerateDevices().then(function(devices) {
                    // devices is an array of accessible audio and video inputs. deviceId is the property I used to switch cameras
                    for(var i = 0; i < devices.length; i++){
                        if( devices[i].kind == 'videoinput'){
                            var params={};params['device_id']=devices[i].deviceId;
                            params['device_kind']=devices[i].kind;
                            params['device_label']=devices[i].label;
                            sendCallbackParam('%(id)s','%(evt_videodevice)s',params);
                        }
                    }
                });
            }

            function getUserMedia(constraints, successCallback, failureCallback) {
                /*var api = navigator.getUserMedia || navigator.webkitGetUserMedia ||
                    navigator.mozGetUserMedia || navigator.msGetUserMedia;
                if (api) {
                    return api.bind(navigator)(constraints, successCallback, failureCallback);
                }*/

                navigator.mediaDevices.getUserMedia(constraints).then(successCallback);
            }
            
            function startGrab(device_id, use_flash){
                flash_on = use_flash;
                try{
                    localMediaStream = null;
                    mediaStreamTrack.stop();
                }catch(e){}

                var constraints = {
                        video: {deviceId: {exact: device_id}, width: { ideal: %(width)s }, height: { ideal: %(height)s } }
                    };
                
                getUserMedia(constraints
                    , function (stream) {
                        mediaStreamTrack = stream.getVideoTracks()[0];
                        //var imageCapture = new ImageCapture(mediaStreamTrack);
                        
                        video = document.querySelector('video');
                        canvas = document.querySelector('canvas');

                        if (navigator.mozGetUserMedia) {
                            video.mozSrcObject = stream;
                        } else {
                            video.srcObject = stream;
                            video.src = (window.URL || window.webkitURL).createObjectURL(stream);
                        }
                        video.play();
                        localMediaStream = stream;
                        snapshot();
                    }, function (err) {
                        alert('Error: ' + err);
                    });
            }
            
            """ % {
                'width': width,
                'height': height,
                'id': self.identifier,
                'evt_foto': self.EVENT_ONCHANGE,
                'evt_videodevice': self.EVENT_ONNEWVIDEODEVICE
            })  # on new image available
Beispiel #7
0
 def __init__(self, *args, **kvargs):
     self.EVENT_ONNEWHALCONCODE = 'onnewhalconcode'
     self.eventManager = gui._EventManager(self)
     super(HalconMsgHandler, self).__init__(*args, **kvargs)