Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
94
gaia/apps/communications/contacts/js/nfc.js
Executable file
94
gaia/apps/communications/contacts/js/nfc.js
Executable file
|
|
@ -0,0 +1,94 @@
|
|||
'use strict';
|
||||
|
||||
/* global LazyLoader, ContactToVcard, MozNDEFRecord, fb, utils,
|
||||
NDEF, NfcUtils, utils*/
|
||||
/* exported NFC */
|
||||
|
||||
(function(exports) {
|
||||
var mozNfc = window.navigator.mozNfc;
|
||||
var currentContact;
|
||||
var vCardContact;
|
||||
var mozNfcPeer;
|
||||
|
||||
var startListening = function(contact) {
|
||||
if (!mozNfc) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentContact = contact;
|
||||
// We cannot share Facebook data via NFC so we check if the contact
|
||||
// is an FB contacts. However, if the contact is linked to a regular
|
||||
// mozContact, we can share linked data
|
||||
if (fb && !(fb.isFbContact(contact) && !fb.isFbLinked(contact))) {
|
||||
mozNfc.onpeerready = handlePeerReady;
|
||||
} else {
|
||||
mozNfc.onpeerready = handlePeerReadyForFb;
|
||||
}
|
||||
};
|
||||
|
||||
var stopListening = function() {
|
||||
if (!mozNfc) {
|
||||
return;
|
||||
}
|
||||
|
||||
mozNfc.onpeerready = null;
|
||||
currentContact = null;
|
||||
vCardContact = null;
|
||||
mozNfcPeer = null;
|
||||
};
|
||||
|
||||
var handlePeerReady = function(event) {
|
||||
mozNfcPeer = event.peer;
|
||||
LazyLoader.load([
|
||||
'/shared/js/contact2vcard.js',
|
||||
'/shared/js/setImmediate.js',
|
||||
'/shared/js/nfc_utils.js'
|
||||
], function() {
|
||||
ContactToVcard(
|
||||
[currentContact],
|
||||
function append(vcard) {
|
||||
vCardContact = vcard;
|
||||
},
|
||||
function success() {
|
||||
sendContact();
|
||||
},
|
||||
// use default batch size
|
||||
null,
|
||||
// We don't want to share a profile photo via NFC,
|
||||
// like on Android:
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1003767#c5
|
||||
true
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
var sendContact = function() {
|
||||
var nfcUtils = new NfcUtils();
|
||||
var NDEFRecord = new MozNDEFRecord({
|
||||
tnf: NDEF.TNF_MIME_MEDIA,
|
||||
type: nfcUtils.fromUTF8('text/vcard'),
|
||||
payload: nfcUtils.fromUTF8(vCardContact)
|
||||
});
|
||||
|
||||
var promise = mozNfcPeer.sendNDEF([NDEFRecord]);
|
||||
promise.then(() => {
|
||||
console.log('Contact succesfuly sent');
|
||||
}).catch(e => {
|
||||
console.log('Something goes wrong : ' + e);
|
||||
});
|
||||
};
|
||||
|
||||
var handlePeerReadyForFb = function() {
|
||||
utils.status.show({
|
||||
id: 'facebook-export-forbidden'
|
||||
});
|
||||
};
|
||||
|
||||
var nfc_tools = {
|
||||
startListening: startListening,
|
||||
stopListening: stopListening
|
||||
};
|
||||
|
||||
exports.NFC = nfc_tools;
|
||||
|
||||
}(window));
|
||||
Loading…
Reference in a new issue