detect user agent with javascript then execute action if not mobile - mobile

I designed my site to first serve mobile devices but if the user agent is a desktop, I wanted to run a script. I came up with the following script but it is not working. The idea is to run the horizontalview() function if none of the variables match.
function view() {
var ua = navigator.userAgent;
var checker = {
iphone: ua.match(/(iPhone|iPod|iPad)/),
blackberry: ua.match(/BlackBerry/),
android: ua.match(/Android/)
};
if (checker.iphone);
{}
if (checker.blackberry);
{}
if (checker.android);
{}
else
{
horizontalview();
}
}
Any help is appreciated.

I figured it out. I omitted semi-colons after brackets on the following snippet from my previous example.
if (checker.iphone)
{}
if (checker.blackberry)
{}
if (checker.android)
{}

Related

Is Jasmine advise to reduce local variable or karma coverage report?

My Karma coverage report shows to cover the local variable. is that possible or its a karma-coverage report issue.
Please have a look at the Angular Controller Code.
'use strict';
angular.module('moduleName')
.controller('FormController', [ '$log',
function FormController($log) {
// Controller Local Variables.
var that = this;
that.hideLoader = function () {
that.isLoading = false;
};
}
]);
My Question: Is that possible to cover the local variables and function parameter conditions. for instance is below.
that.hideLoader = function (userObj) {
var id = userObj.id;
if(id) {
that.isLoading = false;
}
else {
that.isError = true;
}
};
In the above example, I have declared user object id attribute to local id variable. now its very tough to cover the code. in this case, jasmine advise to reduce local variable or its karma-coverage report suggestion ?
my karma coverage report wants to cover the local variable. is that
possible or its a karma-coverage report issue.
The coverage tool is working correctly by checking that your tests cover every line of code. That is the definition of code coverage.
On the other hand:
var that = this;
that.hideLoader = function() { that.isLoading = false};
are NOT local variables. As defined, they are properties of your controller. Word of caution: please use "use strict" and don't use undeclared properties such as that.isLoading. It is not very readable and it is bad practice even though the language allows for it.
Also, when asking questions please paste the code and not images of the code.
Update
The answer to your question is yes. Karma-coverage reports on every line of code touched (green), or untouched (red).

AngularJS and BrightCove Media API

I am working on integrating BrightCove into an Ionic App (allows HTML and JS/Angular to run as a native app on mobile devices).
The app will play videos and allow user's to download the video to save the user's device, I can get the app to play the video but am having issues getting the
Media API to run the 'find_video_by_id' call.
So I have a download button which triggers the following function
_this.downloadBrightcoveVideo = () => {
let searchParams = {}
BCMAPI.token = 'xxxx..'
BCMAPI.callback = 'useDownloadLink'
BCMAPI.command = 'find_video_by_id'
searchParams.video_id = 1234567890
searchParams.media_delivery = 'HTTP'
searchParams.video_fields = 'FLVURL'
BCMAPI.find (BCMAPI.command, searchParams)
}
where token and video_id are set to my video and URL Access token.
I have tried setting the useDownloadLink function as below
let useDownloadLink = function () { console.log ("I'm Alive") }
or
function useDownloadLink () { console.log ("I'm Alive") }
or
_this. useDownloadLink = () => { console.log ("I'm Alive") }
Every time I run the code I get the error below, even though I have useDownloadLink above the download function
Uncaught ReferenceError: useDownloadLink is not defined
I have tried several variations now and nothing is working, any solution would be gratefully received.
Thanks in advance,
Áine
So after a bit of Google-ing came to the conclusion it was better to use BrightCove's CMS Api to achieve the results I wanted, once going through the api it was actually pretty simple..
Hope that helps someone else :D
Happy Coding!

Ionic application not detecting iBeacons on iOS (cordova-plugin-estimote)

I am currently working on a hybrid application (Ionic) and have a problem with detecting iBeacons on iOS (currently developing on 9.2). I'm using cordova-plugin-estimote (https://github.com/evothings/phonegap-estimotebeacons) to detect beacons, followed their documentation and everything works fine on Android, but not on iOS. The beacons are simply not detected. There is no error, it just doesn't find anything.
Fun fact: When I downloaded the original estimote app on iPhone, it also did not detect any iBeacons until I logged in. After that, it started detecting them normally. Why is this happening?
Relevant part of my AngularJS code based on plugin documentation:
$scope.init = function() {
bluetoothSerial.isEnabled(scanBeacons, errorBluetooth);
}
function scanBeacons() {
startScanning();
updateList = $interval(updateView, 5000);
}
function startScanning() {
console.log("requesting permissions");
estimote.beacons.requestAlwaysAuthorization(successAuth, errorAuth);
}
function successAuth(){
console.log("success auth, starting scan");
estimote.beacons.startRangingBeaconsInRegion(
{},
onMonitoringSuccess,
onError);
}
function errorAuth(){
console.log("error auth");
popupService.showPopup("Authorization error", "Location services required to perform scanning");
}
function onMonitoringSuccess(regionState) {
console.log("monitoring success: "+JSON.stringify(regionState));
var successHandler = function (response) {
$scope.downloadedlist = response;
$scope.offline = false;
};
var errorHandler = function (response) {
$scope.beaconList = regionState.beacons;
};
eventService.getBeaconList(regionState.beacons, storageService.getEventId())
.then(successHandler)
.catch(errorHandler);
}
function onError(response) {
console.log("monitoring error: "+JSON.stringify(response));
popupService.showPopup('popup.error.title', 'popup.error.server');
}
As you can see, I have some console.log statements (it has to be done this way) and I'm getting "requesting permissions", instantly followed by "success auth, starting scan". It's weird because authorization popup is displayed but the code does not wait for the user input, it just automatically fires success handler (successAuth) function and that's it. No more logs, which means no monitoring success, no error, it just doesn't find any beacons.
Any help appreciated. Thanks.
Finally found the solution. The problem was here:
estimote.beacons.startRangingBeaconsInRegion(
{},
onMonitoringSuccess,
onError);
Turns out Android allows for {} parameter (which means look for all regions) in the following function but iOS doesn't. After specifying a region, my application successfuly finds the beacons.
Example:
function successAuth(){
console.log("success auth, starting scan");
var region = { uuid: 'YOUR_UUID_HERE' }
estimote.beacons.startRangingBeaconsInRegion(
region,
onMonitoringSuccess,
onError);
}
Estimote Developer quote:
iOS only allows scanning for beacons the UUID of which you know. All Estimote Beacons ship with our default UUID, "B9407F30-F5F8-466E-AFF9-25556B57FE6D", and these are the beacons you can see on the radar even when not logged in. If you change this UUID to something else, then you need to stay logged in so that Estimote app can know what the UUIDs of your beacons are, and scan for them in addition to the default UUID.
Source: https://forums.estimote.com/t/beacons-not-detected-using-estimote-ios-app/1580/5
This also explains why Estimote App started detecting iBeacons after logging in.

Get the current browser name in Protractor test

I'm creating users in some test. Since it is connected to the backend and create real users I need fixtures. I was thinking of using the browser name to create unique user. However, It has proven to be quite difficult to get to it...
Anyone can point me in the right direction?
Another case of rubber ducking :)
The answer was actually quite simple.
in my onPrepare function I added the following function and it works flawlessly.
browser.getCapabilities().then(function (cap) {
browser.browserName = cap.caps_.browserName;
});
I can get access the name in my test using browser.browserName.
This has changed in version of protractor starting from 3.2 (selenium webdriver 2.52)
Now one should call:
browser.driver.getCapabilities().then(function(caps){
browser.browserName = caps.get('browserName');
}
If you want to avoid the a browser, you may want to do this:
it('User should see a message that he has already been added to the campaing when entering the same email twice', function () {
browser.getCapabilities().then(function (capabilities) {
browserName = capabilities.caps_.browserName;
platform = capabilities.caps_.platform;
}).then(function () {
console.log('Browser:', browserName, 'on platform', platform);
if (browserName === 'internet explorer') {
console.log('IE Was avoided for this test.');
} else {
basePage.email.sendKeys('bruno#test.com');
console.log('Mande el mail');
basePage.subscribe.click().then(function () {
basePage.confirmMessage('Contact already added to target campaign');
});
}
});
});

Can not access ANY directories in phonegap through the getDirectory() function

This should be quite simple but I just cannot get it to work
Szenario:
I want to iterate through my folders with the phonegap file API
Problem:
I can not get the getDirectory() function wo work
Very simple example: (to illustrate my problem)
var fileSystem, basePath;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, doStuff, function(error) {
notificationservice.log('Failed to get local filesystem: ' + error.code);
});
function doStuff(fs) {
fileSystem = fs;
basePath = fileSystem.root.fullPath;
var directoryEntry = new DirectoryEntry('', basePath);
readDirectory(directoryEntry);
}
function readDirectory(directoryEntry) {
var directoryReader = directoryEntry.createReader();
directoryReader.readEntries(function(entries) {
for (var i = 0 ; i < entries.length ; i++) {
notificationservice.log(entries[i].fullPath);
fileSystem.root.getDirectory(entries[i].fullPath, {create: false}, function(dir) {
notificationservice.log('SUCCESS');
}, function (error) {
notificationservice.log('Failed to get directory');
});
}
});
}
I can access my folder with the new DirectoryEntry() but whenever I try the access a directory with the getDirectory() function I fail - if anyone could help me correct the above code so that the fileSystem.root.getDirectory() would not return an error I´d be very thanksfull !
Please note:
I use the eclipse editor for deployment and deploy to a nexus 7
(if possible the code should work an plattforms like iOS or win as well)
thanks,
matthias
by the way: I am sure there are a lot of questions which actually solve this issue - however, I haven´t been able to find ANYTHING working for me...
according to https://meta.stackexchange.com/questions/17845/etiquette-for-answering-your-own-question
Silly me - was hooked on script which I got from the web - I have to use the .name property (relative path from the current directory) like this fileSystem.root.getDirectory(name, {create: false}, function(dir) {... - THIS QUESTION IS SOLVED (and sorry if anyone wasted time on this)

Resources