WiFi Fence Initial Event Trap - ibm-mobilefirst

I have a test application that has two buttons one is to start Wifi Tracking and one to to stop. When I start the Wifi tracking, if there is an access point in range and entry event is not fired so I am not aware of being in the fence. Is there a way that when tracking starts that I can be notified that I am within a fence?
function startWifiTracking() {
//create the geofences and triggers
var triggers = {
Wifi : {
fc_entry : { type : 'Enter',
areaAccessPoints : [{SSID: 'test', MAC: '12:12:12:12:12:12'}],
callback : entry1,
otherAccessPointsAllowed : true},
fc_exit : { type : 'Exit',
areaAccessPoints : [{SSID: 'test', MAC: '12:12:12:12:12:12'}],
callback : exited1,
otherAccessPointsAllowed : true}
}};
//create the wifi policy for the wifi access points to be monitored
var policy = {
Wifi : {
interval : 3000,
signalStrengthThreshold : 15,
accessPointFilters : [{SSID: 'test', MAC: '*'}]
}};
WL.Device.startAcquisition(policy, triggers, acquisitionFailure);
}
//trigger callbacks for each wifi fence
function entry1() { alert('entered'); }
function exited1() { alert('exited'); }
function acquisitionFailure() {alert('failed');}
$(function() {
$('#btnStart').click( function(){
startWifiTracking();
});
});
$(function() {
$('#btnStop').click( function(){
WL.Device.stopAcquisition();
});
});

I think there are a couple of different things that you could try here.
1) Use a DwellInside trigger with a dwellingTime parameter of 0.
2) Use WL.Device.Wifi.acquireVisibleAccessPoints API and check if the received array of access points is non-empty in the onSuccess callback.

Related

Vuetify v-simple-table loading state

I'm trying to show loading state in v-simple-data, but for some reason, it doesn't work, maybe there is another way to do it?
Here is my code:
https://codesandbox.io/s/vuetify-template-forked-bmobx?file=/src/App.vue
You are resetting the dataLoading variable outside of the timeout. Therefore it is immediately set to false. You should move it inside the timeout callback.
initialize() {
//you do not need to call the set method; since you are setting a primitive data type; reactivity is detected
//this.$set(this, "dataLoading", true);
this.dataLoading = true
let vm = this;
setTimeout(() => {
vm.items = [
{ name: "Art", position: "Manager" },
{ name: "David", position: "Salesman" },
];
// reset the dataLoading only after the data has been loaded.
vm.dataLoading = false
}, 1000);
// this line of code does not wait for the setTimeout to finish. This line of code was resetting your variable without waiting for the timeout to complete; thus you never saw the data loading indicator
//this.$set(this, "dataLoading", false);
}

Finding the number of active push notifications from service worker

I’ve implemented push notifications using service workers. Is there any way to find out the number of notifications which are currently shown in the window? My intention is to limit the number of notifications shown in the window.
I tried the following. But the getNotifications function returning me empty array.
self.addEventListener('push', function(event) {
if (!(self.Notification && self.Notification.permission === 'granted')) {
return;
}
var data = event.data.json();
var options = {
body: data.notificationText,
icon: 'files/assets/staff.png',
vibrate: [100, 50, 100],
data: {
dateOfArrival: Date.now(),
onClickUrl: data.onClickUrl,
event_id: data.event_id,
productName: data.product_name
}
};
event.waitUntil(
self.registration.getNotifications().then(function(notifications) {
console.log(notifications);
if (notifications && notifications.length > 0) {
notifications.forEach(function(notification) {
notification.close();
});
}
showNotification(data.title, options);
})
);
});
You can use serviceWorker.getNotifications() which returns a list of notifications. You can use it like so:
navigator.serviceWorker.register('sw.js');
navigator.serviceWorker.ready.then(function(registration) {
registration.getNotifications().then(function(notifications) {
// get the number of notifications
})
});
if you're doing this in your serviceworker file, it's:
self.registration.getNotifications().then(function(notifications) {
// get the number of notifications
})

RTCPeerConnection.iceConnectionState changed from checking to closed

Following the method here I'm trying to answer an audio call initiated with a Chrome browser from an iPhone simulator(with React Native).
A summary of the event sequence:
received call signal
got local stream
sent join call signal
received remote description(offer),
created PeerConnection
added local stream
received candidate
added candidate
7 and 8 repeated 15 times (that is 16 times in total)
onnegotiationneeded triggered
signalingState changed into have-remote-offer
onaddstream triggered
the callback function of setRemoteDescription was triggered, created answer.
signalingState changed into stable
iceconnectionstate changed into checking
onicecandidate triggered for the first time.
emited the candidate from 15
onicecandidate triggered for the 2nd time. The candidate is null
iceconnectionstate changed into closed
Step 7,8,9 may appear at different places after 6 and before 19.
I have been stuck on this problem for quite a while. I don't even know what to debug at this time. What are the possible causes of the closing of connection? I can post more logs if needed.
One observation is that the two RTCEvent corresponding to iceconnectionstatechange has the following properties:
isTrusted:false
The target RTCPeerConnection has
iceConnectionState:"closed"
iceGatheringState:"complete"
Here are my functions to handle remoteOffer and remoteCandidates:
WebRTCClass.prototype.onRemoteOffer = function(data) {
var ref;
if (this.active !== true) {
return;
}
var peerConnection = this.getPeerConnection(data.from);
console.log('onRemoteOffer', data,peerConnection.signalingState);
if (peerConnection.iceConnectionState !== 'new') {
return;
}
var onSuccess = (function(_this){
return function(){
console.log("setRemoteDescription onSuccess function");
_this.getLocalUserMedia((function(_this) {
return function(onSuccess,stream) {
peerConnection.addStream(_this.localStream);
var onAnswer = (function(_this) {
return function(answer) {
var onLocalDescription = function() {
return _this.transport.sendDescription({
to: data.from,
type: 'answer',
ts: peerConnection.createdAt,
description: {
sdp: answer.sdp,
type: answer.type
}
});
};
return peerConnection.setLocalDescription(new RTCSessionDescription(answer), onLocalDescription, _this.onError);
};
})(_this);
return peerConnection.createAnswer(onAnswer, _this.onError);
}
})(_this)
);
}
})(this);
return peerConnection.setRemoteDescription(new RTCSessionDescription(data.description),onSuccess,console.warn);
};
WebRTCClass.prototype.onRemoteCandidate = function(data) {
var peerConnection, ref;
if (this.active !== true) {
return;
}
if (data.to !== this.selfId) {
return;
}
console.log('onRemoteCandidate', data);
peerConnection = this.getPeerConnection(data.from);
if ((ref = peerConnection.iceConnectionState) !== "closed" && ref !== "failed" && ref !== "disconnected" && ref !== "completed") {
peerConnection.addIceCandidate(new RTCIceCandidate(data.candidate));
}
};
I found that if I call the following two functions one by one, then it will work.
peerConnection.setRemoteDescription(new RTCSessionDescription(data.description),onSuccess,console.warn);
(...definition of onAnswer ...)
peerConnection.createAnswer(onAnswer, this.onError);
My previous codes called createAnswer within the onSuccess callback of setRemoteDescription. That did work for the react-native-webrtc demo, but not with Rocket.Chat. Still don't fully understand it. But my project can move on now.

do something after user click the notification center message in MobileFirst app?

Page navigating and communicating with backend system should be done after users click the notification center message entering the app.
But where should my code be ?
In the same function that handles the incoming notification.
If you're using Event Source-based notifications then that would be the pushNotificationReceived() function. Replace the alerts with required applicative logic.
function pushNotificationReceived(props, payload) {
alert("pushNotificationReceived invoked");
alert("props :: " + JSON.stringify(props));
alert("payload :: " + JSON.stringify(payload));
}
If you're using broadcast/tag notifications it is done in a similar fashion. From the sample application you can do something like the following, just replace with your required applicative logic:
WL.Client.Push.onMessage = function (props, payload) {
WL.SimpleDialog.show("Tag Notifications", "Provider notification data: " + JSON.stringify(props), [ {
text : 'Close',
handler : function() {
WL.SimpleDialog.show("Tag Notifications", "Application notification data: " + JSON.stringify(payload), [ {
text : 'Close',
handler : function() {}
}]);
}
}]);
};

Correct way of attaching 'disclose' (or any other) event handler in Sencha Touch

In my simple application I'm listening for the disclose event like this :
In the NotesList.js (view) file...
Ext.define("NotesApp.view.NotesList", {
extend : "Ext.dataview.List",
xtype : "noteslist",
...
config : {
onItemDisclosure : true, //adds the disclose arrow
}
});
NotesList is used in NotesListContainer which is an Ext.Container.
Then in NotesListContainer.js (view) ...
var notesList = {
xtype : "noteslist",
...
listeneres : {
disclose : { fn : this.onNotesListDisclose, scope : this }
}
};
this.add([topToolbar, notesList]);
The function does this :
onNotesListDisclose : function(list, record, target, index, evt, options) {
console.log(' onNotesListDisclose() called'); //nevers gets logged
this.fireEvent('editNoteCommand', this, record);
}
Then in Notes.js (controller) :
refs : {
//get elemets using xtype attr
notesListContainer : "noteslistcontainer",
noteEditor : "noteeditor"
},
//handlers for events
control : {
//define which events should this controller respond to
notesListContainer : {
//events fired by NotesListContainer
newNoteCommand : "onNewNoteCommand",
editNoteCommand : "onEditNoteCommand"
}
}
},
//Event/Command handler
onEditNoteCommand : function(list, record) {
console.log(' onEditNoteCommand called ');
this.activateNoteEditor(record);
}
I think the problem is in NotesListContainer.js where I am instantiating the list.
If I listen for the event in controller like this :
refs : {
//get elemets using xtype attr
notesListContainer : "noteslistcontainer",
notesList : "noteslistcontainer list",
},
//handlers for events
control : {
//define which events should this controller respond to
notesListContainer : {
//events fired by NotesListContainer
newNoteCommand : "onNewNoteCommand",
//editNoteCommand : "onEditNoteCommand"
},
notesList : {
disclose : "onEditNoteCommand" //adding it this way works...
}
}
It works just fine. However, I would prefer to work with a more application specific event instead of very generic disclose event.
I am new to sencha touch, any help is appreciated.
If you want to have your own custom business logic driven events, do the following:
Subscribe to necessary UI events in your main controller
Generate application wide business events
Subscribe to these events in your view controller
what you mean with 'a more application specific event'?
The disclose event is a list-component specific one:
http://docs.sencha.com/touch/2.2.1/#!/api/Ext.dataview.List-event-disclose