chrome app bluetooth api - google-chrome

I am trying to get the list of bluetooth devices paired with my windows 7 machine. I took the code from here https://developer.chrome.com/apps/app_bluetooth
var device_names = {};
var updateDeviceName = function(device) {
device_names[device.address] = device.name;
};
var removeDeviceName = function(device) {
delete device_names[device.address];
}
// Add listeners to receive newly found devices and updates
// to the previously known devices.
chrome.bluetooth.onDeviceAdded.addListener(updateDeviceName);
chrome.bluetooth.onDeviceChanged.addListener(updateDeviceName);
chrome.bluetooth.onDeviceRemoved.addListener(removeDeviceName);
// With the listeners in place, get the list of devices found in
// previous discovery sessions, or any currently active ones,
// along with paired devices.
chrome.bluetooth.getDevices(function(devices) {
for (var i = 0; i < devices.length; i++) {
updateDeviceName(devices[i]);
}
});
// Now begin the discovery process.
chrome.bluetooth.startDiscovery(function() {
// Stop discovery after 30 seconds.
setTimeout(function() {
chrome.bluetooth.stopDiscovery(function() {});
}, 30000);
});
In the manifest file i gave bluetooth permission
"bluetooth": {
"uuids": [ "1105", "1106" ]
}
But getDevices always return empty list even after startDiscovery is initiated.
I have enabled bluetooth in my mobile and paired it with my windows 7 as well even then its not showing the paired device when getdevice is called.
The chrome app is frameless and running in developer mode.
BTW my windows bluetooth UI shows my mobile device and some other devices as well
I will be grateful if anyone can suggest where i am making a mistake?

Related

Offline Ready using Service worker

I built an offline first app using the appcache a while ago and wanted to convert it to using the service-worker (my clients all use the latest chrome so I don't have any browser compatibility issues).
I'm using sw-precache to generate a service-worker that caches my local assets (specifically, my html/css/fonts and also some js) and it looks like when the service-worker installs, it does successfully add all the assets to cache storage and it does successfully start (install and activate both fire and complete successfully. And I have the self.skipWaiting() at the end of the install event to start the service-worker (which it does successfully as well)).
The issue is that the "fetch" event doesn't seem to ever fire. As such, if I go offline or open a browser (while already offline) and navigate to the site, I get the Chrome offline dinosaur. When I look at the network tab, it looks like the browser is trying to hit a server to retrieve the pages. I'm not sure what I'm doing wrong and I didn't touch the fetch method that was generated by the sw-precache utility...so I'm not sure what I'm missing. Any help would be greatly appreciated. My fetch event is below:
self.addEventListener('fetch', function(event) {
if (event.request.method === 'GET') {
var urlWithoutIgnoredParameters = stripIgnoredUrlParameters(event.request.url,
IgnoreUrlParametersMatching);
var cacheName = AbsoluteUrlToCacheName[urlWithoutIgnoredParameters];
var directoryIndex = 'index.html';
if (!cacheName && directoryIndex) {
urlWithoutIgnoredParameters = addDirectoryIndex(urlWithoutIgnoredParameters, directoryIndex);
cacheName = AbsoluteUrlToCacheName[urlWithoutIgnoredParameters];
}
var navigateFallback = '';
// Ideally, this would check for event.request.mode === 'navigate', but that is not widely
// supported yet:
// https://code.google.com/p/chromium/issues/detail?id=540967
// https://bugzilla.mozilla.org/show_bug.cgi?id=1209081
if (!cacheName && navigateFallback && event.request.headers.has('accept') &&
event.request.headers.get('accept').includes('text/html') &&
/* eslint-disable quotes, comma-spacing */
isPathWhitelisted([], event.request.url)) {
/* eslint-enable quotes, comma-spacing */
var navigateFallbackUrl = new URL(navigateFallback, self.location);
cacheName = AbsoluteUrlToCacheName[navigateFallbackUrl.toString()];
}
if (cacheName) {
event.respondWith(
// Rely on the fact that each cache we manage should only have one entry, and return that.
caches.open(cacheName).then(function(cache) {
return cache.keys().then(function(keys) {
return cache.match(keys[0]).then(function(response) {
if (response) {
return response;
}
// If for some reason the response was deleted from the cache,
// raise and exception and fall back to the fetch() triggered in the catch().
throw Error('The cache ' + cacheName + ' is empty.');
});
});
}).catch(function(e) {
console.warn('Couldn\'t serve response for "%s" from cache: %O', event.request.url, e);
return fetch(event.request);
})
);
}
}
});

Choose default webcam for node-webkit

I have a node-webkit application that is using RecordRTC to capture a snippet of video. I'm running the application on a Windows Surface Pro 3, and need the front-facing webcam to be used instead of the back-facing one. I know there is a setting in Chrome to change the default webcam, but how do I configure this in node-webkit?
I don't have a device to test this on but it should work. I believe mobile devices will return either 'user' or 'environment' to determine if it's front or rear facing.
var devices = function (devices) {
for (var i = 0; i !== devices.length; ++i) {
var camera = devices[i];
if (camera.kind === 'video' && camera.facing === 'user') {
createStream(camera.id);
} else {
console.log('No front facing camera');
}
}
}
var createStream = function(id) {
var settings = {video: {optional: {sourceId: id} }};
navigator.webkitGetUserMedia(settings, successCallback, errorCallback);
};
MediaStreamTrack.getSources(devices);
This basically loops through all of the available devices and checks if it's a video source and that it is facing the user. It will then use the id of that device to create the media stream.

Adobe DPS HTML Alert when tapping link that no internet connection available

I created an HTML page that has some external links, when the user taps the external link how can I prompt the user that there is no internet connection available? Thanks.
You will probably need some JavaScript and Adobe's store api (for banners or store) or reading api (for html articles or web view in folios). The api provides the singleton object adobeDPS.deviceService which can tell you if the device is online or not. Additionally it provides a signal to indicate a change.
For each link element you register an onclick event handler that checks online state and either passes the click through or catches it and gives a message to the user.
The following code could work:
<script src="js/AdobeLibraryAPI.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", myLinkChecker.register, false);
var myLinkChecker = {
register: function(){
if (typeof(adobeDPS) !== 'object') {
console.log("Adobe Library not loaded :-(");
this.check = function() { return true } // Fallback
}
var linkList = document.querySelectorAll("a, map > area");
for (var i=0; i < linkList.length; i++){
var e = linkList[i];
if (e.hasAttribute('href'))
e.addEventListener('click', myLinkChecker.check, false);
}
},
check: function(ev){
if (adobeDPS.deviceService.isOnline) { // let <a> process the click
console.log("online");
return true
} else { // cancel click event and show message
event.stopPropagation();
event.preventDefault();
alert("Sorry, your device is not online")
return false;
}
}
}
</script>
Remote debugging html in DPS apps can be done using iOS developer apps and desktop Safari, or Android apps with Google Chrome.

Google maps touch scroll not working on Windows Phone

My web application lets users create new location based trips. There is a google maps map displaying the current location they've entered in a form.
I've read in this post about touch scrolling and google-maps that most of touch scrolling is ok with this code:
var dragFlag = false;
var start = 0, end = 0;
$('#maps-map').on('touchstart', function(e) {
console.log('Starting!');
dragFlag = true;
start = e.originalEvent.touches[0].pageY;
});
$('#maps-map').on('touchmove', function(e) {
console.log('Moving!');
if ( !dragFlag ) return;
end = e.originalEvent.touches[0].pageY;
window.scrollBy( 0,( start - end ) );
});
$('#maps-map').on('touchend', function(e) {
console.log('Ending');
dragFlag = false;
});
And of course, google maps has to be added to following container:
<div id="#maps-map"></div>
Now if I test this on my HTC-device, in my console I get:
'Starting!'
'Moving!'
'Moving!'
'Ending!'
But if I watch my console when debugging my Nokia Lumnia device (emulated) i get nothing.
Jquery states that is has support for this device. What could be the cause of not doing this intuïtive touch gestures?

continous speech recognition with Webkit speech api

i started using this browser(chrome) feature.
i ve written a JS based on this , but the problem is even , it recognises the speech only once and ends . its not going continuously, i need to press the button again and again to start speech recognition . tell me where i should tweak . i ve set "recognition.continuous=true" still not helping ?
var recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = true;
recognition.onstart = function() {
console.log("Recognition started");
};
recognition.onresult = function(event){
console.log(event.results);
};
recognition.onerror = function(e) {
console.log("Error");
};
recognition.onend = function() {
console.log("Speech recognition ended");
};
function start_speech() {
recognition.lang = 'en-IN'; // 'en-US' works too, as do many others
recognition.start();
}
I call "start_speech" from a button ! thats it
I know this is an old thread, but I had this problem too. I found that, even with the continuous flag set, if there are pauses in the input speech, a "no-speech" error gets thrown (triggers the onerror event) and the engine is shut down. I just added code in the onend to restart the engine:
recognition.onend = function() {
recognition.start();
};
The next problem you might get is, every time the engine restarts, the user has to re-grant permission to let the browser use the microphone. The only solution at this time seems to be to make sure you connect to your site over HTTPS (source: http://updates.html5rocks.com/2013/01/Voice-Driven-Web-Apps-Introduction-to-the-Web-Speech-API bottom of post in bold)
Perhaps the typo on this line:
recognition.continuos = true;
Should equal:
recognition.continuous = true;
recognition.onend = function(){
recognition.start();
// sets off a beep/noise each time it is accessed from a cell phone (Andoid).
// does NOT if accessed from a desktop (Windows using Chrome).
};