Appcelerator Device Token converted to FCM token - firebase-cloud-messaging

I have an old app developed with Appcelerator - Titanium SDK using FCM Push notifications.
The device token that I get on the device is:
"baf48325219887fdb5929ac5d9495d8897a48f0b77a1c9c23131097e51dc1234"
Because Appcelerator is deprecated, I want to know how to get the FCM token so I can still notify the devices even if Appcelerator has been deprecated.
** UPDATE **
This is the code for getting the deviceToken:
exports.requestDeviceToken = function() {
if (Ti.Platform.model.indexOf('Simulator') !== -1 || Ti.Platform.model.indexOf('Emulator') !== -1) {
return;
}
var params = {
callback:pushNotificationCallback,
success:deviceTokenSuccess,
error: deviceTokenError,
};
var types = [
Ti.Network.NOTIFICATION_TYPE_BADGE,
Ti.Network.NOTIFICATION_TYPE_ALERT,
Ti.Network.NOTIFICATION_TYPE_SOUND
];
if (Ti.Platform.name == 'android') {
var CloudPush = require('ti.cloudpush');
// Initialize the module
CloudPush.retrieveDeviceToken({
success: deviceTokenSuccess,
error: deviceTokenError,
});
CloudPush.addEventListener('callback', pushNotificationCallback);
}
else {
if (Ti.Platform.name != "android" && parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
Ti.API.info('registering push notifications iOS > 8');
Ti.Network.registerForPushNotifications(params);
Ti.App.iOS.registerUserNotificationSettings({types:types});
}
else {
params.types = types;
Ti.Network.registerForPushNotifications(params);
}
}
};
Any clue?

There is https://github.com/hansemannn/titanium-firebase-cloud-messaging available since 2017 that you can use to connect your app to FCM. Using it for years and it's working without any issue.
Transfering an existing app takes around 30mins.
...
if (OS_IOS) {
const FirebaseCore = require('firebase.core');
fc.configure();
}
const FirebaseCloudMessaging = require('firebase.cloudmessaging');
if (OS_ANDROID) {
FirebaseCloudMessaging.registerForPushNotifications();
}
...
as a short example. A fulll example with connection to the Android channels, how to get the token (iOS and Android) is available in the repo at https://github.com/hansemannn/titanium-firebase-cloud-messaging#example

Related

Why the webrtc Ice Candidate types are different from two peer connection

I have a peer connection between the web browser (chrome) and an android app.
When I query the stats to check the type of connections between two peers. I guessed that the information should have been the same, however, I saw that the two results are different.
Can anyone explain it to me?
On android
boolean success = peerConnection.getStats(statsReports -> {
for (StatsReport report : statsReports) {
Log.i(TAG, "report " + report.toString());
}
}, null);
Result on android (I manually filtered the Conn-audio filed)
[googLocalAddress: 192.168.123.13:47063],
[localCandidateId: Cand-b6zAa+KI],
[googLocalCandidateType: local],
[googRemoteAddress: 192.168.123.49:50663],
[remoteCandidateId: Cand-2rJUPD95],
[googRemoteCandidateType: local],
In web browser (chrome)
const reqFields = [
'googLocalAddress',
'googLocalCandidateType',
'googRemoteAddress',
'googRemoteCandidateType'
];
const connectionDetails = {};
peerConnection.getStats(stats => {
// console.log("peer starts", stats.result());
const filtered = stats.result().filter(e => {
return e.id.indexOf('Conn-audio') === 0 && e.stat('googActiveConnection') === 'true';
})[0];
if (!filtered) return resolve({});
reqFields.forEach(e => {
connectionDetails[e.replace('goog', '')] = filtered.stat(e);
});
console.log('1111111', connectionDetails);
});
Web browser result
LocalAddress: "192.168.123.49:50663"
LocalCandidateType: "local"
RemoteAddress: ":47063"
RemoteCandidateType: "prflx"

How to make a flag counter with react-native-beacons-manager

Scenario
Our app aims to detect beacons placed inside the restaurants our app
uses react-native-beacons-manager
When our app detects a beacon, I have developed a cloud function that accepts the beacon's major key and use it to query data of that restaurant from my database
The Cloud function then sends a push notification on the user about the restaurant details.
The Problem
The way I detect the beacons is not stable. this is my flow. I created a function located at
this.beaconsDidRangeEvent = Beacons.BeaconsEventEmitter.addListener(
//function-here
);
I can receive the beacons information like uuid, major and minor key and proximity (immediate, near, far, unknown) . Now inside that function I use the major key to determine the individuality of each beacons. Now, I've made a condition like this:
let beaconArr = data.beacons;
console.log(beaconArr);
console.log(count);
if (beaconArr.length > 0) {
console.log("beacons detected!");
let major = data.beacons[0].major;
let prox = data.beacons[0].proximity;
if ((prox === "near" || prox === "far") && beaconFlag === false && count === 0) {
console.log("beacon Action");
this.props.beaconAction(major);
this.props.createCheckInHistory(user.uid);
beaconFlag = true;
count++;
} else {
console.log("counter turned to 1!");
console.log(data);
beaconFlag = true;
}
} else {
console.log("no beacons detected!");
count = 0;
beaconFlag = false;
}
Expected Result
I expect that the functions inside the condition is true will only fire once.
Actual Result
Sometimes, its ok sometimes its not. even if im still at the range of the beacon, suddenly the beacon's array got 0. Then suddenly i'll receive a push notification again and again.
componentDidMount() Code
componentDidMount() {
this.props.selectedIcon('map');
firebase
.messaging()
.getInitialNotification()
.then(notification => {
console.log("Notification which opened the app: ", notification);
});
const user = firebase.auth().currentUser;
let count = 0;
let beaconFlag = false;
// will be set as a reference to "regionDidEnter" event:
this.beaconsDidRangeEvent = Beacons.BeaconsEventEmitter.addListener(
"beaconsDidRange",
_.throttle(data => {
let beaconArr = data.beacons;
console.log(beaconArr);
console.log(count);
if (beaconArr.length > 0) {
console.log("beacons detected!");
let major = data.beacons[0].major;
let prox = data.beacons[0].proximity;
if ((prox === "near" || prox === "far") && beaconFlag === false && count === 0) {
console.log("beacon Action");
this.props.beaconAction(major);
this.props.createCheckInHistory(user.uid);
beaconFlag = true;
count++;
} else {
console.log("counter turned to 1!");
console.log(data);
beaconFlag = true;
}
} else {
console.log("no beacons detected!");
count = 0;
beaconFlag = false;
}
}, 3000)
);
// monitoring events
this.regionDidEnterEvent = Beacons.BeaconsEventEmitter.addListener(
"regionDidEnter",
data => {
console.log("monitoring - regionDidEnter data: ", data);
}
);
// Monitoring: Listen for device leaving the defined region
this.regionDidExitEvent = Beacons.BeaconsEventEmitter.addListener(
"regionDidExit",
data => {
console.log("monitoring - regionDidExit data: ", data);
}
);
}
This is a common problem when ranging in beacon apps. Sometimes the detected beacons will briefly drop out then come back again. This can be solved by a software filter where you keep track of all beacons you have recently seen, and only perform an operation of it has not happened recently. In your case, you may use the major as the key to the index into the filter object.
// scope this globally
var minimumRetriggerMillis = 3600 * 1000; // 1hr
var recentTriggers = {};
// Before executing your trigger action:
var now = new Date().getTime();
if (recentTriggers[minor] == null || now-recentTriggers[minor] > minimumRetriggerMillis) {
recentTriggers[minor] = now;
// TODO: execute trigger logic here
}

Worklight JavaScript HTTP adapter unable to receive request data

I am trying to understand how MFP JSONStore & HTTP adapters work. I downloaded the source code here. I followed the steps to build the app. I also deployed this adapter here. But when I tried to push the dirty data to the adapter, I got noting there. The adapter still logs undefined.
Here is the push function code:
function pushToAdapter(){
alert("pushToAdapter");
try {
WL.JSONStore.get(collectionName).push().then(function (res) {
if(Array.isArray(res) && res.length < 1){ // I changed this to res.length > 1
document.getElementById("resultsDiv").innerHTML = "Documents Pushed Successfuly";
} else {
document.getElementById("resultsDiv").innerHTML = "Failed To Push Documents to Adapter: "+ res[0].errorObject;
}
}).fail(function (errorObject) {
alert(errorObject.msg);
});
} catch (e) {
alert("Failed To Push Documents to Adapter");
}
}
& this is the adapter code:
function pushPeople(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: pushPeople called.');
MFP.Logger.debug('Got data from JSONStore to ADD: ' + JSON.stringify(data)); //always undefined
return;
}
function addPerson(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: addPerson called.');
MFP.Logger.debug('Got data from JSONStore to ADD: ' + JSON.stringify(data)); //always undefined
return;
}
function removePerson(data) {
MFP.Logger.debug('Adapter: JSONStoreAdapter, procedure: removePerson called.');
MFP.Logger.debug('Got data from JSONStore to REMOVE: ' + JSON.stringify(data)); //always undefined
return;
}
Please note that I am using a patched version of cordova-plugin-mfp-jsonstore. It is the same as this version except for lines 5238 (as follows):
resourceRequest = new WLResourceRequest('adapters/' + invocationData.adapter + '/' + invocationData.procedure, WLResourceRequest.POST);
resourceRequest.setHeader('Content-Type','application/x-www-form-urlencoded'); //patched version
resourceRequest.send().then(ipOpts.onSuccess, ipOpts.onFailure);
Looks like the parameters were not being passed as a part of the push request. You can use the jsonstore.js provided here and verify if it solves your problem. This will be officially released in the next iFix.

Titanium Facebook Dialog does not appear

Im developing an "share on facebook" button.
But there is a problem, the facebook dialog is not prompted to the user.
I have tried the sample that titanium provide:
function facebook(){
var fb = require('facebook');
var data = {
link : "http://www.appcelerator.com",
name : "Appcelerator Titanium Mobile",
message : "Checkout this cool open source project for creating apps",
caption : "Appcelerator Titanium Mobile",
picture : "http://developer.appcelerator.com/assets/img/DEV_titmobile_image.png",
description : "You've got the ideas, now you've got the power."
};
fb.dialog("feed", data, function(e) {
var toast = Ti.UI.createNotification({
message:"Default",
duration: Ti.UI.NOTIFICATION_DURATION_LONG
});
if(e.success && e.result)
toast.message = "Success! New Post ID: " + e.result;
else {
if(e.error)
toast.message = e.error;
else
toast.message = "User canceled dialog.";
}
toast.show();
});
}
The function is called correctly, but nothing appear.
Someone knows why? Maybe permissions? But i have read that for the dialog aren't required permissions!
thanks to all
try this:
var fb = require('facebook');
fb.appid = FACEBOOK_APP_ID;
fb.permissions = ['publish_stream']; // Permissions your app needs
fb.forceDialogAuth = true;
fb.addEventListener('login', function(e) {
if (e.success) {
alert('Logged In');
} else if (e.error) {
alert(e.error);
} else if (e.cancelled) {
alert("Canceled");
}
});
fb.authorize();
I solved by myself!
Even if the Facebook Dialog not Require the Auth(), it require the init with an AppID.
var fb = require('facebook');
fb.appid = your_app_id_number;
With this worked very well.

WEBRTC Object #<RTCPeerConnection> has no method 'processSignalingMessage'

I have problems with the WebRTC:
I use this code from one example about Video calls.
if (new_connection) {
console.log('New Peer Connection');
var peer_connection = {};
peer_connection.connection_id = msg.from_connection_id;
peer_connection.pc = createPeerConnection(peer_connection.connection_id,
false);
peer_connections.push(peer_connection);
$('#remote').prepend(remoteVideoHtml.replace('remoteVideoId', 'peer' +
peer_connection.connection_id));
}
//Now process the SDP JSON Blob received
for (var i in peer_connections) {
if (peer_connections[i].connection_id == msg.from_connection_id) {
try {
peer_connections[i].pc.processSignalingMessage(msg.data);
}catch (e) {
console.log("Failed to create processSignalingMessage, exception: " + e.message);
}
I need help because I have one problem here.
peer_connections[i].pc.processSignalingMessage(msg.data);
The problem is:
Object #<RTCPeerConnection> has no method 'processSignalingMessage'
I don't know how those functions works and how they are invoqued:
pc.onconnecting = function (msg) {
console.log('onSessionConnecting');
}
pc.onopen = function (msg) {
console.log('onSessionOpened');
}
pc.onaddstream = function (event) {
console.log('onRemoteStreamAdded add the remote peers video stream.');
var url = webkitURL.createObjectURL(event.stream);
$('#peer' + connection_id).attr({
src: url
});
}
I will appreciate any help.
The initial version of WebRTC in Chrome was based on ROAP and it used to have a processSignallingMessage() method. The current version based on JSEP and it has methods like setRometeDescription() or setLocalDescription() to inject the local SDP and the SDP received from other users.
You can still find this implementation in old versions of Chrome or in Bowser.