Skip to content

Commit

Permalink
Rename 'parserLayout' and 'BeaconParser'
Browse files Browse the repository at this point in the history
to 'beaconLayout' and 'BeaconLayout' because 'parser' is kind of
confusing.  This library doesn't scan and parse advertisements, it only
broadcasts them.  I was originally mimicking the names from the
ScanBeacon gem, but then I realized the Android Beacon Library calls it
a 'beaconLayout' string, not a 'parserLayout' string and I liked that
better.
  • Loading branch information
jnebeker committed Apr 26, 2016
1 parent b5b54b0 commit 2402626
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 83 deletions.
28 changes: 14 additions & 14 deletions README.md
Expand Up @@ -2,7 +2,7 @@

A JavaScript library for broadcasting BLE Beacon advertisements, wrapping existing
advertising APIs to make beacon transmission easier for developers. The library
is flexible, supporting custom beacon types that can be registered with a `parserLayout`
is flexible, supporting custom beacon types that can be registered with a `beaconLayout`
similar to the [Android Beacon Library](https://altbeacon.github.io/android-beacon-library/)
and [ScanBeacon Ruby Gem](https://github.com/RadiusNetworks/scanbeacon-gem). The
following beacon types are also supported by default:
Expand Down Expand Up @@ -89,12 +89,12 @@ To register a custom beacon type use the `registerBeaconType()` method:
```
beacon.registerBeaconType({
type: 'cool_beacon',
parserLayout: 'm:2-3=0000,i:4-19,i:20-21,i:22-23,p:24-24',
beaconLayout: 'm:2-3=0000,i:4-19,i:20-21,i:22-23,p:24-24',
manufacturerId: 0x1234
})
```

For more information on the `parserLayout` check out
For more information on the `beaconLayout` check out
[this page](http://altbeacon.github.io/android-beacon-library/javadoc/org/altbeacon/beacon/BeaconParser.html#setBeaconLayout(java.lang.String))
from the Android Beacon Library docs.

Expand Down Expand Up @@ -122,7 +122,7 @@ After building the product can be found under the project root directory
<dd></dd>
<dt><a href="#module_beacon-data">beacon-data</a></dt>
<dd></dd>
<dt><a href="#module_beacon-parser">beacon-parser</a></dt>
<dt><a href="#module_beacon-layout">beacon-layout</a></dt>
<dd></dd>
<dt><a href="#module_beacon">beacon</a></dt>
<dd></dd>
Expand Down Expand Up @@ -185,27 +185,27 @@ Validates the give array of bytes or converts the hex string into an array of by
| --- | --- | --- |
| value | <code>Array.&lt;number&gt;</code> &#124; <code>string</code> | The value to encode. |

<a name="module_beacon-parser"></a>
<a name="module_beacon-layout"></a>

## beacon-parser
## beacon-layout

* [beacon-parser](#module_beacon-parser)
* [BeaconParser](#exp_module_beacon-parser--BeaconParser)
* [.parseLayout()](#module_beacon-parser--BeaconParser.parseLayout)
* [beacon-layout](#module_beacon-layout)
* [BeaconParser](#exp_module_beacon-layout--BeaconParser)
* [.parseLayout()](#module_beacon-layout--BeaconParser.parseLayout)

<a name="exp_module_beacon-parser--BeaconParser"></a>
<a name="exp_module_beacon-layout--BeaconParser"></a>

### BeaconParser ⏏
This class provides helper functions that relate to deconstructing beacon parser.
This class provides helper functions that relate to deconstructing beacon beacon.

**Kind**: Exported class
<a name="module_beacon-parser--BeaconParser.parseLayout"></a>
<a name="module_beacon-layout--BeaconParser.parseLayout"></a>

#### BeaconParser.parseLayout()
Constructs an ordered array of matchers, identifiers, advertised power, and data based
on the parser layout
on the beacon layout

**Kind**: static method of <code>[BeaconParser](#exp_module_beacon-parser--BeaconParser)</code>
**Kind**: static method of <code>[BeaconParser](#exp_module_beacon-layout--BeaconParser)</code>
<a name="module_beacon"></a>

## beacon
Expand Down
42 changes: 21 additions & 21 deletions beacon.js
Expand Up @@ -72,7 +72,7 @@
A string containing the layout of the custom beacon advertisement layout.
Follows the same convention as the Android Beacon Library
*/
this.parserLayout = undefined;
this.beaconLayout = undefined;

if (typeof options.beaconType.manufacturerId !== 'undefined' && typeof options.beaconType.serviceUuid !== 'undefined') {
throw new Error('Manufacturer ID and Service UUID can\'t both be specified');
Expand Down Expand Up @@ -217,7 +217,7 @@
@default
*/

let BeaconParser = require('./beacon-parser.js');
let BeaconParser = require('./beacon-layout.js');

// If we are in a browser TextEncoder should be available already.
if (typeof global.TextEncoder === 'undefined') {
Expand Down Expand Up @@ -269,7 +269,7 @@
if (advertisedTxPower < -100 || advertisedTxPower > 20) {
throw new Error('Invalid Tx Power value: ' + advertisedTxPower + '.');
}
let layout = BeaconParser.parseLayout(beacon_type.parserLayout);
let layout = BeaconParser.parseLayout(beacon_type.beaconLayout);
let end_bytes = [].concat(layout.matchers, layout.ids, layout.power, layout.dataFields).map((e) => e.end);
let length = Math.max.apply(Math, end_bytes) + 1;
// Start with array of zeros
Expand All @@ -286,7 +286,7 @@
layout_ids.forEach((layout_id, index) => {
let id = ids[index];
let bytes;
if (beacon_type.parserLayout === 's:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-21v') {
if (beacon_type.beaconLayout === 's:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-21v') {
// Detect Eddystone URL and encode URL
bytes = BeaconData.encodeURL(id);
} else {
Expand Down Expand Up @@ -463,13 +463,13 @@
})();

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./beacon-parser.js":4,"text-encoding":undefined}],4:[function(require,module,exports){
},{"./beacon-layout.js":4,"text-encoding":undefined}],4:[function(require,module,exports){
(() => {
'use strict';

/**
* @module beacon-parser
* @typicalname parser
* @module beacon-layout
* @typicalname beacon
*/

/**
Expand All @@ -480,17 +480,17 @@
*/

/**
This class provides helper functions that relate to deconstructing beacon parser.
@alias module:beacon-parser
This class provides helper functions that relate to deconstructing beacon beacon.
@alias module:beacon-layout
*/
class BeaconParser {
/**
Constructs an ordered array of matchers, identifiers, advertised power, and data based
on the parser layout
on the beacon layout
*/
static parseLayout(parserLayout) {
static parseLayout(beaconLayout) {
let matchers = [], ids = [], dataFields = [], power, layoutArray = [];
layoutArray = parserLayout.split(',');
layoutArray = beaconLayout.split(',');
for (let i = 0; i < layoutArray.length; i++) {
let field, field_params, field_type, range_start, range_end, expected;
field = layoutArray[i];
Expand Down Expand Up @@ -576,8 +576,8 @@
registerBeaconType(options) {
let self = this;
// Register a new custom beacon type
if (!('parserLayout' in options) && !('type' in options)) {
throw new TypeError('Required member type or parserLayout is undefined.');
if (!('beaconLayout' in options) && !('type' in options)) {
throw new TypeError('Required member type or beaconLayout is undefined.');
}
if (!('manufacturerId' in options) && !('serviceUuid' in options)) {
throw new TypeError('Required member manufacturerId or serviceUuid is undefined.');
Expand All @@ -587,18 +587,18 @@
}

let type = options.type;
let parserLayout = options.parserLayout;
let beaconLayout = options.beaconLayout;

if ('manufacturerId' in options) {
let manufacturerId = options.manufacturerId;
self.beaconTypes[type] = {
parserLayout: parserLayout,
beaconLayout: beaconLayout,
manufacturerId: manufacturerId
};
} else if ('serviceUuid' in options) {
let serviceUuid = options.serviceUuid;
self.beaconTypes[type] = {
parserLayout: parserLayout,
beaconLayout: beaconLayout,
serviceUuid: serviceUuid
};
}
Expand All @@ -609,17 +609,17 @@
defaultBeaconTypes = [
{
type: 'altbeacon',
parserLayout: 'm:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25',
beaconLayout: 'm:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25',
manufacturerId: 0x0118
},
{
type: 'eddystone_uid',
parserLayout: 's:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19,d:20-21',
beaconLayout: 's:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19,d:20-21',
serviceUuid: 0xFEAA
},
{
type: 'eddystone_url',
parserLayout: 's:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-21v',
beaconLayout: 's:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-21v',
serviceUuid: 0xFEAA
}
];
Expand Down Expand Up @@ -667,7 +667,7 @@
if (!('manufacturerId' in options.beaconType) && !('serviceUuid' in options.beaconType)) {
throw new TypeError('Required member manufacturerId or serviceUuid is undefined.');
}
if (!('parserLayout' in options.beaconType)) {
if (!('beaconLayout' in options.beaconType)) {
throw new TypeError('Parser layout not defined in beacon type.');
}
if (!('ids' in options)) {
Expand Down
6 changes: 3 additions & 3 deletions jsdoc2md/README.hbs
Expand Up @@ -2,7 +2,7 @@

A JavaScript library for broadcasting BLE Beacon advertisements, wrapping existing
advertising APIs to make beacon transmission easier for developers. The library
is flexible, supporting custom beacon types that can be registered with a `parserLayout`
is flexible, supporting custom beacon types that can be registered with a `beaconLayout`
similar to the [Android Beacon Library](https://altbeacon.github.io/android-beacon-library/)
and [ScanBeacon Ruby Gem](https://github.com/RadiusNetworks/scanbeacon-gem). The
following beacon types are also supported by default:
Expand Down Expand Up @@ -89,12 +89,12 @@ To register a custom beacon type use the `registerBeaconType()` method:
```
beacon.registerBeaconType({
type: 'cool_beacon',
parserLayout: 'm:2-3=0000,i:4-19,i:20-21,i:22-23,p:24-24',
beaconLayout: 'm:2-3=0000,i:4-19,i:20-21,i:22-23,p:24-24',
manufacturerId: 0x1234
})
```

For more information on the `parserLayout` check out
For more information on the `beaconLayout` check out
[this page](http://altbeacon.github.io/android-beacon-library/javadoc/org/altbeacon/beacon/BeaconParser.html#setBeaconLayout(java.lang.String))
from the Android Beacon Library docs.

Expand Down
2 changes: 1 addition & 1 deletion lib/beacon-advertisement.js
Expand Up @@ -71,7 +71,7 @@
A string containing the layout of the custom beacon advertisement layout.
Follows the same convention as the Android Beacon Library
*/
this.parserLayout = undefined;
this.beaconLayout = undefined;

if (typeof options.beaconType.manufacturerId !== 'undefined' && typeof options.beaconType.serviceUuid !== 'undefined') {
throw new Error('Manufacturer ID and Service UUID can\'t both be specified');
Expand Down
6 changes: 3 additions & 3 deletions lib/beacon-data.js
Expand Up @@ -13,7 +13,7 @@
@default
*/

let BeaconParser = require('./beacon-parser.js');
let BeaconParser = require('./beacon-layout.js');

// If we are in a browser TextEncoder should be available already.
if (typeof global.TextEncoder === 'undefined') {
Expand Down Expand Up @@ -65,7 +65,7 @@
if (advertisedTxPower < -100 || advertisedTxPower > 20) {
throw new Error('Invalid Tx Power value: ' + advertisedTxPower + '.');
}
let layout = BeaconParser.parseLayout(beacon_type.parserLayout);
let layout = BeaconParser.parseLayout(beacon_type.beaconLayout);
let end_bytes = [].concat(layout.matchers, layout.ids, layout.power, layout.dataFields).map((e) => e.end);
let length = Math.max.apply(Math, end_bytes) + 1;
// Start with array of zeros
Expand All @@ -82,7 +82,7 @@
layout_ids.forEach((layout_id, index) => {
let id = ids[index];
let bytes;
if (beacon_type.parserLayout === 's:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-21v') {
if (beacon_type.beaconLayout === 's:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-21v') {
// Detect Eddystone URL and encode URL
bytes = BeaconData.encodeURL(id);
} else {
Expand Down
14 changes: 7 additions & 7 deletions lib/beacon-parser.js → lib/beacon-layout.js
Expand Up @@ -2,8 +2,8 @@
'use strict';

/**
* @module beacon-parser
* @typicalname parser
* @module beacon-layout
* @typicalname beacon
*/

/**
Expand All @@ -14,17 +14,17 @@
*/

/**
This class provides helper functions that relate to deconstructing beacon parser.
@alias module:beacon-parser
This class provides helper functions that relate to deconstructing beacon beacon.
@alias module:beacon-layout
*/
class BeaconParser {
/**
Constructs an ordered array of matchers, identifiers, advertised power, and data based
on the parser layout
on the beacon layout
*/
static parseLayout(parserLayout) {
static parseLayout(beaconLayout) {
let matchers = [], ids = [], dataFields = [], power, layoutArray = [];
layoutArray = parserLayout.split(',');
layoutArray = beaconLayout.split(',');
for (let i = 0; i < layoutArray.length; i++) {
let field, field_params, field_type, range_start, range_end, expected;
field = layoutArray[i];
Expand Down
18 changes: 9 additions & 9 deletions lib/beacon.js
Expand Up @@ -35,8 +35,8 @@
registerBeaconType(options) {
let self = this;
// Register a new custom beacon type
if (!('parserLayout' in options) && !('type' in options)) {
throw new TypeError('Required member type or parserLayout is undefined.');
if (!('beaconLayout' in options) && !('type' in options)) {
throw new TypeError('Required member type or beaconLayout is undefined.');
}
if (!('manufacturerId' in options) && !('serviceUuid' in options)) {
throw new TypeError('Required member manufacturerId or serviceUuid is undefined.');
Expand All @@ -46,18 +46,18 @@
}

let type = options.type;
let parserLayout = options.parserLayout;
let beaconLayout = options.beaconLayout;

if ('manufacturerId' in options) {
let manufacturerId = options.manufacturerId;
self.beaconTypes[type] = {
parserLayout: parserLayout,
beaconLayout: beaconLayout,
manufacturerId: manufacturerId
};
} else if ('serviceUuid' in options) {
let serviceUuid = options.serviceUuid;
self.beaconTypes[type] = {
parserLayout: parserLayout,
beaconLayout: beaconLayout,
serviceUuid: serviceUuid
};
}
Expand All @@ -68,17 +68,17 @@
defaultBeaconTypes = [
{
type: 'altbeacon',
parserLayout: 'm:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25',
beaconLayout: 'm:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25',
manufacturerId: 0x0118
},
{
type: 'eddystone_uid',
parserLayout: 's:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19,d:20-21',
beaconLayout: 's:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19,d:20-21',
serviceUuid: 0xFEAA
},
{
type: 'eddystone_url',
parserLayout: 's:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-21v',
beaconLayout: 's:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-21v',
serviceUuid: 0xFEAA
}
];
Expand Down Expand Up @@ -126,7 +126,7 @@
if (!('manufacturerId' in options.beaconType) && !('serviceUuid' in options.beaconType)) {
throw new TypeError('Required member manufacturerId or serviceUuid is undefined.');
}
if (!('parserLayout' in options.beaconType)) {
if (!('beaconLayout' in options.beaconType)) {
throw new TypeError('Parser layout not defined in beacon type.');
}
if (!('ids' in options)) {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/beacon-advertisement-unit.js
Expand Up @@ -22,7 +22,7 @@ describe('BeaconAdvertisement', () => {
let id = 100;
let type = 'altbeacon';
let beaconType = {
parserLayout: 'm:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25',
beaconLayout: 'm:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25',
manufacturerId: 0x0118
};
let ids = ['2F234454CF6D4A0FADF2F4911BA9FFA6', 1, 1];
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('BeaconAdvertisement', () => {
let advertisement = new BeaconAdvertisement(100 /* id */, {
type: 'altbeacon',
beaconType: {
parserLayout: 'm:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25',
beaconLayout: 'm:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25',
manufacturerId: 0x0118
},
ids: ['2F234454CF6D4A0FADF2F4911BA9FFA6', 1, 1],
Expand All @@ -68,7 +68,7 @@ describe('BeaconAdvertisement', () => {
let advertisement = new BeaconAdvertisement(100 /* id */, {
type: 'altbeacon',
beaconType: {
parserLayout: 'm:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25',
beaconLayout: 'm:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25',
manufacturerId: 0x0118
},
ids: ['2F234454CF6D4A0FADF2F4911BA9FFA6', 1, 1],
Expand Down

0 comments on commit 2402626

Please sign in to comment.