Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DeviceOrientation event listener
Message
From
04/10/2014 03:25:29
 
 
To
All
General information
Forum:
HTML5
Category:
Browser issues
Title:
DeviceOrientation event listener
Miscellaneous
Thread ID:
01608768
Message ID:
01608768
Views:
51
I've been using the above with the following code (Typescript):
            var processingEvent:boolean = false;
            if (window.DeviceOrientationEvent) {
                window.addEventListener('deviceorientation', (data): void=> {
                    if (Math.abs(lastAlpha - data.alpha) < 2) { return; }
                    if (processingEvent) {
                        return;
                    };
                    processingEvent = true;

                    lastAlpha = data.alpha;
                    if (data.absolute === true && data.alpha !== null) {
                        this.deviceOrientation = Math.round(360 - data.alpha);
                        console.log(this.deviceOrientation.toString());
                        this.updateArrows();
                    }
                    processingEvent = false;
                }, false);
            } else {
                alert('DeviceOrienation not supported');
            }
I noticed the event listener could be called again before the routine has finished (the event is raised extremely frequently) so added the 'processing' flag to prevent re-entrancy. It works fine - but it also appeared to work without the check so I'm wondering whether there is any really benefit in it.

Any opinions ?

Side Rant: I've been testing this with different browsers. Firefox gives by far the best results but Chrome, which one would expect to work well on Android devices, is annoyingly flacky....
Next
Reply
Map
View

Click here to load this message in the networking platform