Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cordova cli 3.1.0-0.2.0 has a bug for wp8. cd plaforms/wp8 remove plugins with plugman re-add plugins with plugman
- Loading branch information
Showing
9 changed files
with
342 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
platforms/wp8/cordova/plugins/com.chariotsolutions.nfc.plugin/.fetch.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"source":{"type":"local","path":"C:\\Users\\don\\AppData\\Local\\Temp\\com.chariotsolutions.nfc.plugin\\package"}} | ||
{"source":{"type":"git","url":"https://github.com/chariotsolutions/phonegap-nfc","subdir":"."}} |
13 changes: 0 additions & 13 deletions
13
platforms/wp8/cordova/plugins/com.chariotsolutions.nfc.plugin/package.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
platforms/wp8/cordova/plugins/com.chariotsolutions.nfc.plugin/src/blackberry10/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/*jshint quotmark:double, strict:false, bitwise: false */ | ||
/*global PluginResult */ | ||
|
||
// based on code from Gord Tanner https://github.com/chariotsolutions/phonegap-nfc/pull/32 | ||
|
||
var alphabet = "ABCDEFGHIJKLM" + | ||
"NOPQRSTUVWXYZ" + | ||
"abcdefghijklm" + | ||
"nopqrstuvwxyz" + | ||
"0123456789+/="; | ||
|
||
function b64toArray(input) { | ||
var result = [], | ||
workValue = [], | ||
bytes = [], | ||
offset = 0; | ||
|
||
while (offset < input.length) { | ||
for (var i = 0; i < 4; ++i) { | ||
if (offset >= input.length) { | ||
workValue[i] = 64; | ||
} else { | ||
var index = alphabet.indexOf(input.substring(offset++, offset)); | ||
if (index === -1) { | ||
--i; | ||
continue; | ||
} | ||
workValue[i] = index; | ||
} | ||
} | ||
bytes[0] = (workValue[0] << 2 | workValue[1] >> 4) & 255; | ||
bytes[1] = (workValue[1] << 4 | workValue[2] >> 2) & 255; | ||
bytes[2] = (workValue[2] << 6 | workValue[3]) & 255; | ||
|
||
if (workValue[3] === 64 && workValue[2] === 64) { | ||
result.push(bytes[0]); | ||
} else if (workValue[3] === 64) { | ||
result.push(bytes[0]); | ||
result.push(bytes[1]); | ||
} else { | ||
result.push(bytes[0]); | ||
result.push(bytes[1]); | ||
result.push(bytes[2]); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
function decodeNdefRecord(encoded) { | ||
|
||
var ndefRecord = { | ||
tnf: encoded[0] & 7 | ||
}, | ||
flags = encoded[0], | ||
isShortRecord = (flags & 16) !== 0, // short record | ||
hasIdLength = (flags & 8) !== 0, // identification length | ||
offset = 1, | ||
typeLength = encoded[offset++], | ||
idLength = 0, | ||
payloadLength = 0; | ||
|
||
if (isShortRecord) { | ||
payloadLength = encoded[offset++]; | ||
} else { | ||
for ( var i = 0; i < 4; ++i) { | ||
payloadLength *= 256; | ||
payloadLength |= encoded[offset++]; | ||
} | ||
} | ||
|
||
if (hasIdLength) { | ||
idLength = encoded[offset++]; | ||
} | ||
|
||
ndefRecord.type = encoded.slice(offset, offset + typeLength); | ||
|
||
offset += typeLength; | ||
ndefRecord.id = encoded.slice(offset, offset + idLength); | ||
|
||
offset += idLength; | ||
ndefRecord.payload = encoded.slice(offset, offset + payloadLength); | ||
|
||
return ndefRecord; | ||
} | ||
|
||
function decode(encoding) { | ||
var decoded = []; | ||
var offset = 0; | ||
|
||
while (offset < encoding.length) { | ||
var start = offset; | ||
var remaining = encoding.length - offset; | ||
var flags = encoding[offset++]; | ||
var minLength = 1 + 1; | ||
var sr = (flags & 16) !== 0; | ||
var il = (flags & 8) !== 0; | ||
|
||
minLength += sr ? 1 : 4; | ||
minLength += il ? 1 : 0; | ||
if (minLength <= remaining) { | ||
var typeLength = encoding[offset++]; | ||
var payloadLength = 0; | ||
if (sr) { | ||
payloadLength = encoding[offset++]; | ||
} else { | ||
for ( var i = 0; i < 4; ++i) { | ||
payloadLength <<= 8; | ||
payloadLength |= encoding[offset++]; | ||
} | ||
} | ||
var idLength = il ? encoding[offset++] : 0; | ||
var totalLength = minLength + typeLength + payloadLength + idLength; | ||
if (totalLength <= remaining) { | ||
var encoded = encoding.slice(start, start + totalLength); | ||
|
||
decoded.push(decodeNdefRecord(encoded)); | ||
|
||
offset = start + totalLength; | ||
} | ||
} | ||
} | ||
return decoded; | ||
} | ||
|
||
// called by invoke, when NFC tag is scanned | ||
var tagListener = function(pluginResult, payloadString) { | ||
var payload = JSON.parse(payloadString), | ||
ndefObjectAsString = JSON.stringify(decode(b64toArray(payload.data))); | ||
pluginResult.callbackOk(ndefObjectAsString, true); | ||
}; | ||
|
||
module.exports = { | ||
init: function(success, failure, args, env) { | ||
// no-op, just here for Android compatibility | ||
var result = new PluginResult(args, env); | ||
result.ok(); | ||
}, | ||
registerNdef: function(success, failure, args, env) { | ||
|
||
var result = new PluginResult(args, env), | ||
application = window.qnx.webplatform.getApplication(), | ||
ndefListener = tagListener.bind(null, result); | ||
|
||
application.invocation.addEventListener("invoked", ndefListener); | ||
result.noResult(true); | ||
} | ||
}; |
63 changes: 63 additions & 0 deletions
63
platforms/wp8/cordova/plugins/com.chariotsolutions.nfc.plugin/www/phonegap-nfc-blackberry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*jslint browser: true, unused: vars, quotmark: double */ | ||
/*global cordova, nfc, ndef, blackberry */ | ||
|
||
// blackberry requires the com.blackberry.invoke plugin installed | ||
|
||
// you need to edit config.xml for your app and add an invoke-target | ||
// <rim:invoke-target id="com.chariotsolutions.nfc.demo.reader.target"> | ||
// <type>APPLICATION</type> | ||
// <filter> | ||
// <action>bb.action.OPEN</action> | ||
// <mime-type>application/vnd.rim.nfc.ndef</mime-type> | ||
// <property value="ndef://0,ndef://1,ndef://2,ndef://3,ndef://4" var="uris" /> | ||
// </filter> | ||
// </rim:invoke-target> | ||
|
||
// clobber existing share function | ||
nfc.share = function(ndefMessage, success, failure) { | ||
"use strict"; | ||
var byteArray = ndef.encodeMessage(ndefMessage), | ||
data = "", | ||
query; | ||
|
||
for (var i=0; i< byteArray.length; ++i) { | ||
data += String.fromCharCode(byteArray[i]); | ||
} | ||
|
||
query = { | ||
"action": "bb.action.SHARE", | ||
"type": "application/vnd.rim.nfc.ndef", | ||
"data": data | ||
}; | ||
|
||
blackberry.invoke.invoke(query, success, failure); | ||
}; | ||
|
||
// clobber existing unshare function | ||
nfc.unshare = function(success, failure) { | ||
"use strict"; | ||
blackberry.invoke.closeChildCard(); | ||
if (success) { // no idea if it worked. assume success. | ||
success(); | ||
} | ||
}; | ||
|
||
// takes an ndefMessage from the success callback and fires a javascript event | ||
var proxy = function(ndefMessageAsString) { | ||
"use strict"; | ||
var ndefMessage = JSON.parse(ndefMessageAsString); | ||
cordova.fireDocumentEvent("ndef", { | ||
type: "ndef", | ||
tag: { | ||
ndefMessage: ndefMessage | ||
} | ||
}); | ||
}; | ||
|
||
// clobber existing addNdefListener function | ||
nfc.addNdefListener = function (callback, success, failure) { | ||
"use strict"; | ||
document.addEventListener("ndef", callback, false); | ||
cordova.exec(proxy, failure, "com.chariotsolutions.nfc.plugin", "registerNdef", []); | ||
success(); // assume success | ||
}; |
Oops, something went wrong.