-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
67 lines (49 loc) · 2.19 KB
/
game.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
if (bPHONEGAP) document.addEventListener("deviceready", onDeviceReady, false);
else {
$(document).ready(function() {
onDeviceReady();
})
}
function createBeacon() {
var uuid = '2D85ED40-54D1-59D1-5961-B388-ABDFD8FD64A5'; // mandatory
var identifier = 'GemTot USB'; // mandatory
var minor = 4; // optional, defaults to wildcard if left empty
var major = 1; // optional, defaults to wildcard if left empty
// throws an error if the parameters are not valid
var beaconRegion = new cordova.plugins.locationManager.BeaconRegion(identifier, uuid, major, minor);
return beaconRegion;
}
function onDeviceReady() {
alert("1");
var beaconRegion = createBeacon();
alert("2");
var delegate = new cordova.plugins.locationManager.Delegate().implement({
// Event when advertising starts (there may be a short delay after the request)
// The property 'region' provides details of the broadcasting Beacon
peripheralManagerDidStartAdvertising: function(pluginResult) {
$(".wrap").html('peripheralManagerDidStartAdvertising: '+ JSON.stringify(pluginResult.region));
//console.log('peripheralManagerDidStartAdvertising: '+ JSON.stringify(pluginResult.region));
},
// Event when bluetooth transmission state changes
// If 'state' is not set to BluetoothManagerStatePoweredOn when advertising cannot start
peripheralManagerDidUpdateState: function(pluginResult) {
$(".wrap").html('peripheralManagerDidStartAdvertising: '+ JSON.stringify(pluginResult.region));
//console.log('peripheralManagerDidUpdateState: '+ pluginResult.state);
}
});
alert("3");
cordova.plugins.locationManager.setDelegate(delegate);
cordova.plugins.locationManager.isAdvertisingAvailable()
.then(function(isSupported){
if (isSupported) {
cordova.plugins.locationManager.startAdvertising(beaconRegion)
.fail(conole.error)
.done();
} else {
console.log("Advertising not supported");
}
})
.fail(console.error)
.done();
$(".wrap").html('done device 2');
}