Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Address mmocny comments.
Browse files Browse the repository at this point in the history
Node now supports arrow functions \o/ No need for iojs now.
  • Loading branch information
g-ortuno committed Sep 10, 2015
1 parent 169cc4a commit a3e53bb
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- "iojs"
- "node"
before_install:
- cd libraries/javascript/eddystone-advertising
32 changes: 18 additions & 14 deletions libraries/javascript/eddystone-advertising/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ worry about these low level details. The library exposes simple functions that
developers can use to advertise a Valid Eddystone packet from their device.

** NOTE ** Currently only ChromeOS is supported.
** NOTE ** Currently only Eddystone-URL is supported.

## Usage
The Eddystone Advertising Library creates `window.eddystone` of type
Expand All @@ -14,22 +15,25 @@ The Eddystone Advertising Library creates `window.eddystone` of type
To advertise a url:
**Example**
```js
let registered_adv;
eddystone.registerAdvertisement({
type: 'url',
url: 'https://example.com',
txPower: -20
}).then(advertisement => console.log('Advertising: ' + advertisement.url))
.catch(error => console.log(error.message));
advertisedTxPower: -20
}).then(advertisement => {
registered_adv = advertisement;
console.log('Advertising: ' + advertisement.url)
}).catch(error => console.log(error.message));
```

To stop advertising:
**Example**
```js
advertisement.unregisterAdvertisement().then(() => {
console.log('Advertisment unregistered successfully.');
registered_adv.unregisterAdvertisement().then(() => {
console.log('Advertisement unregistered successfully.');
}).catch(error => console.log(error.message));
```
Or if you have multiple advertisments:
Or if you have multiple advertisements:
```js
eddystone.advertisements.forEach(advertisement => {
advertisement.unregisterAdvertisement()
Expand Down Expand Up @@ -74,15 +78,15 @@ Represents the Advertisement being broadcasted.
* [.id](#EddystoneAdvertisement+id) : <code>number</code>
* [.type](#EddystoneAdvertisement+type) : <code>string</code>
* [.url](#EddystoneAdvertisement+url) : <code>string</code> &#124; <code>undefined</code>
* [.txPower](#EddystoneAdvertisement+txPower) : <code>number</code> &#124; <code>undefined</code>
* [.advertisedTxPower](#EddystoneAdvertisement+advertisedTxPower) : <code>number</code> &#124; <code>undefined</code>
* [.unregisterAdvertisement()](#EddystoneAdvertisement+unregisterAdvertisement) ⇒ <code>Promise.&lt;void&gt;</code>

<a name="new_EddystoneAdvertisement_new"></a>
### new EddystoneAdvertisement(id, options, platform)

| Param | Type | Description |
| --- | --- | --- |
| id | <code>number</code> | Unique between browser restarts |
| id | <code>number</code> | Unique between browser restarts meaning the id will no longer be valid upon browser restart. |
| options | <code>[EddystoneAdvertisementOptions](#EddystoneAdvertisementOptions)</code> | The options used when creating the advertisement. |
| platform | <code>Object</code> | The underlying platform; used to unregister the advertisement. |

Expand All @@ -102,8 +106,8 @@ URL being advertised.
Only present if `type === 'url'`.

**Kind**: instance property of <code>[EddystoneAdvertisement](#EddystoneAdvertisement)</code>
<a name="EddystoneAdvertisement+txPower"></a>
### eddystoneAdvertisement.txPower : <code>number</code> &#124; <code>undefined</code>
<a name="EddystoneAdvertisement+advertisedTxPower"></a>
### eddystoneAdvertisement.advertisedTxPower : <code>number</code> &#124; <code>undefined</code>
Tx Power included in
the advertisement. Only present if `type === 'url'`.

Expand Down Expand Up @@ -154,11 +158,11 @@ This class provides helper functions that relate to Eddystone-URL.
**See**: [Eddystone-URL](https://github.com/google/eddystone/tree/master/eddystone-url)

* [EddystoneURL](#EddystoneURL)
* [.constructServiceData(url, txPower)](#EddystoneURL.constructServiceData) ⇒ <code>Array.&lt;number&gt;</code>
* [.constructServiceData(url, advertisedTxPower)](#EddystoneURL.constructServiceData) ⇒ <code>Array.&lt;number&gt;</code>
* [.encodeURL(url)](#EddystoneURL.encodeURL) ⇒ <code>Array.&lt;number&gt;</code>

<a name="EddystoneURL.constructServiceData"></a>
### EddystoneURL.constructServiceData(url, txPower) ⇒ <code>Array.&lt;number&gt;</code>
### EddystoneURL.constructServiceData(url, advertisedTxPower) ⇒ <code>Array.&lt;number&gt;</code>
Constructs a valid Eddystone-URL service data from a URL and a Tx Power
value.

Expand All @@ -180,7 +184,7 @@ Constructs a valid Eddystone-URL service data from a URL and a Tx Power
| Param | Type | Description |
| --- | --- | --- |
| url | <code>string</code> | The URL to use in the service data. |
| txPower | <code>number</code> | The Tx Power to use in the service data. |
| advertisedTxPower | <code>number</code> | The Tx Power to use in the service data. |

<a name="EddystoneURL.encodeURL"></a>
### EddystoneURL.encodeURL(url) ⇒ <code>Array.&lt;number&gt;</code>
Expand Down Expand Up @@ -236,5 +240,5 @@ Object that contains the characteristics of the package to advertise.
| --- | --- | --- |
| type | <code>[EddystoneFrameType](#EddystoneFrameType)</code> | Type of Eddystone. For now only `'url'` is supported. |
| url | <code>string</code> &#124; <code>undefined</code> | The URL to advertise |
| txPower | <code>number</code> &#124; <code>undefined</code> | The Tx Power to advertise |
| advertisedTxPower | <code>number</code> &#124; <code>undefined</code> | The Tx Power to advertise |

27 changes: 14 additions & 13 deletions libraries/javascript/eddystone-advertising/eddystone-advertising.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
class EddystoneAdvertisement {
/**
@constructs EddystoneAdvertisement
@param {number} id Unique between browser restarts
@param {number} id Unique between browser restarts meaning the id will
no longer be valid upon browser restart.
@param {EddystoneAdvertisementOptions} options The options used when
creating the advertisement.
@param {Object} platform The underlying platform; used to unregister the
Expand All @@ -59,15 +60,15 @@
*/
this.url = undefined;
/**
@member EddystoneAdvertisement#txPower {number|undefined} Tx Power included in
@member EddystoneAdvertisement#advertisedTxPower {number|undefined} Tx Power included in
the advertisement. Only present if `type === 'url'`.
*/
this.txPower = undefined;
this.advertisedTxPower = undefined;
if (options.type == EddystoneFrameType.URL) {
this.id = id;
this.type = options.type;
this.url = options.url;
this.txPower = options.txPower;
this.advertisedTxPower = options.advertisedTxPower;
} else {
throw new Error('Unsupported Frame Type');
}
Expand Down Expand Up @@ -102,7 +103,7 @@
@property {EddystoneFrameType} type Type of Eddystone. For now only `'url'` is
supported.
@property {string|undefined} url The URL to advertise
@property {number|undefined} txPower The Tx Power to advertise
@property {number|undefined} advertisedTxPower The Tx Power to advertise
*/

/**
Expand Down Expand Up @@ -177,8 +178,8 @@
if (!('url' in options)) {
throw new TypeError('Required member url is undefined.');
}
if (!('txPower' in options)) {
throw new TypeError('Required member txPower is undefined.');
if (!('advertisedTxPower' in options)) {
throw new TypeError('Required member advertisedTxPower is undefined.');
}
}
}
Expand Down Expand Up @@ -273,7 +274,7 @@
serviceUuids: [EDDYSTONE_UUID],
serviceData: [{
uuid: EDDYSTONE_UUID,
data: EddystoneURL.constructServiceData(options.url, options.txPower)
data: EddystoneURL.constructServiceData(options.url, options.advertisedTxPower)
}]
};
} else {
Expand Down Expand Up @@ -361,7 +362,7 @@
value.
@see {@link https://github.com/google/eddystone/tree/master/eddystone-url#frame-specification|URL Frame Specification}
@param {string} url The URL to use in the service data.
@param {number} txPower The Tx Power to use in the service data.
@param {number} advertisedTxPower The Tx Power to use in the service data.
@returns {number[]} The service data.
@throws {Error} If the Tx Power value is not in the allowed range. See
{@link https://github.com/google/eddystone/tree/master/eddystone-url#tx-power-level|Tx Power Level}.
Expand All @@ -372,12 +373,12 @@
invalid characters see the Note in
{@link https://github.com/google/eddystone/tree/master/eddystone-url#eddystone-url-http-url-encoding|HTTP URL Encoding}
*/
static constructServiceData(url, txPower) {
static constructServiceData(url, advertisedTxPower) {
// Check that it's a valid Tx Power
if (txPower < -100 || txPower > 20) {
throw new Error('Invalid Tx Power value: ' + txPower);
if (advertisedTxPower < -100 || advertisedTxPower > 20) {
throw new Error('Invalid Tx Power value: ' + advertisedTxPower);
}
let base_frame = [EDDYSTONE_URL_FRAME_TYPE, txPower];
let base_frame = [EDDYSTONE_URL_FRAME_TYPE, advertisedTxPower];
Array.prototype.push.apply(base_frame, EddystoneURL.encodeURL(url));
return base_frame;
}
Expand Down
16 changes: 10 additions & 6 deletions libraries/javascript/eddystone-advertising/jsdoc2md/README.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ worry about these low level details. The library exposes simple functions that
developers can use to advertise a Valid Eddystone packet from their device.

** NOTE ** Currently only ChromeOS is supported.
** NOTE ** Currently only Eddystone-URL is supported.

## Usage
The Eddystone Advertising Library creates `window.eddystone` of type
Expand All @@ -14,22 +15,25 @@ The Eddystone Advertising Library creates `window.eddystone` of type
To advertise a url:
**Example**
```js
let registered_adv;
eddystone.registerAdvertisement({
type: 'url',
url: 'https://example.com',
txPower: -20
}).then(advertisement => console.log('Advertising: ' + advertisement.url))
.catch(error => console.log(error.message));
advertisedTxPower: -20
}).then(advertisement => {
registered_adv = advertisement;
console.log('Advertising: ' + advertisement.url)
}).catch(error => console.log(error.message));
```

To stop advertising:
**Example**
```js
advertisement.unregisterAdvertisement().then(() => {
console.log('Advertisment unregistered successfully.');
registered_adv.unregisterAdvertisement().then(() => {
console.log('Advertisement unregistered successfully.');
}).catch(error => console.log(error.message));
```
Or if you have multiple advertisments:
Or if you have multiple advertisements:
```js
eddystone.advertisements.forEach(advertisement => {
advertisement.unregisterAdvertisement()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
class EddystoneAdvertisement {
/**
@constructs EddystoneAdvertisement
@param {number} id Unique between browser restarts
@param {number} id Unique between browser restarts meaning the id will
no longer be valid upon browser restart.
@param {EddystoneAdvertisementOptions} options The options used when
creating the advertisement.
@param {Object} platform The underlying platform; used to unregister the
Expand All @@ -58,15 +59,15 @@
*/
this.url = undefined;
/**
@member EddystoneAdvertisement#txPower {number|undefined} Tx Power included in
@member EddystoneAdvertisement#advertisedTxPower {number|undefined} Tx Power included in
the advertisement. Only present if `type === 'url'`.
*/
this.txPower = undefined;
this.advertisedTxPower = undefined;
if (options.type == EddystoneFrameType.URL) {
this.id = id;
this.type = options.type;
this.url = options.url;
this.txPower = options.txPower;
this.advertisedTxPower = options.advertisedTxPower;
} else {
throw new Error('Unsupported Frame Type');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@property {EddystoneFrameType} type Type of Eddystone. For now only `'url'` is
supported.
@property {string|undefined} url The URL to advertise
@property {number|undefined} txPower The Tx Power to advertise
@property {number|undefined} advertisedTxPower The Tx Power to advertise
*/

/**
Expand Down Expand Up @@ -84,8 +84,8 @@
if (!('url' in options)) {
throw new TypeError('Required member url is undefined.');
}
if (!('txPower' in options)) {
throw new TypeError('Required member txPower is undefined.');
if (!('advertisedTxPower' in options)) {
throw new TypeError('Required member advertisedTxPower is undefined.');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
serviceUuids: [EDDYSTONE_UUID],
serviceData: [{
uuid: EDDYSTONE_UUID,
data: EddystoneURL.constructServiceData(options.url, options.txPower)
data: EddystoneURL.constructServiceData(options.url, options.advertisedTxPower)
}]
};
} else {
Expand Down
10 changes: 5 additions & 5 deletions libraries/javascript/eddystone-advertising/lib/eddystone-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
value.
@see {@link https://github.com/google/eddystone/tree/master/eddystone-url#frame-specification|URL Frame Specification}
@param {string} url The URL to use in the service data.
@param {number} txPower The Tx Power to use in the service data.
@param {number} advertisedTxPower The Tx Power to use in the service data.
@returns {number[]} The service data.
@throws {Error} If the Tx Power value is not in the allowed range. See
{@link https://github.com/google/eddystone/tree/master/eddystone-url#tx-power-level|Tx Power Level}.
Expand All @@ -84,12 +84,12 @@
invalid characters see the Note in
{@link https://github.com/google/eddystone/tree/master/eddystone-url#eddystone-url-http-url-encoding|HTTP URL Encoding}
*/
static constructServiceData(url, txPower) {
static constructServiceData(url, advertisedTxPower) {
// Check that it's a valid Tx Power
if (txPower < -100 || txPower > 20) {
throw new Error('Invalid Tx Power value: ' + txPower);
if (advertisedTxPower < -100 || advertisedTxPower > 20) {
throw new Error('Invalid Tx Power value: ' + advertisedTxPower);
}
let base_frame = [EDDYSTONE_URL_FRAME_TYPE, txPower];
let base_frame = [EDDYSTONE_URL_FRAME_TYPE, advertisedTxPower];
Array.prototype.push.apply(base_frame, EddystoneURL.encodeURL(url));
return base_frame;
}
Expand Down
6 changes: 3 additions & 3 deletions libraries/javascript/eddystone-advertising/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"test": "test"
},
"scripts": {
"test": "iojs --harmony_arrow_functions `which gulp` test",
"generate-docs": "iojs --harmony_arrow_functions `which gulp` docs",
"browserify": "iojs --harmony_arrow_functions `which gulp` browserify"
"test": "gulp test",
"generate-docs": "gulp docs",
"browserify": "gulp browserify"
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ describe('EddystoneAdvertisement', () => {
id, {
type: type,
url: url,
txPower: tx_power
advertisedTxPower: tx_power
},
{});
expect(adv.id).to.eql(id);
expect(adv.type).to.eql(type);
expect(adv.url).to.eql(url);
expect(adv.txPower).to.eql(tx_power);
expect(adv.advertisedTxPower).to.eql(tx_power);
expect(adv._platform).to.eql({});
});
});
Expand All @@ -47,7 +47,7 @@ describe('EddystoneAdvertisement', () => {
let advertisement = new EddystoneAdvertisement(100 /* id */, {
type: 'url',
url: 'https://www.example.com/',
txPower: -10
advertisedTxPower: -10
}, {});
let error = new Error('Failed');
advertisement._platform.unregisterAdvertisement = sinon.stub().returns(Promise.reject(error));
Expand All @@ -58,7 +58,7 @@ describe('EddystoneAdvertisement', () => {
let advertisement = new EddystoneAdvertisement(100 /* id */, {
type: 'url',
url: 'https://www.example.com/',
txPower: -10
advertisedTxPower: -10
}, {});
advertisement._platform.unregisterAdvertisement = sinon.stub().returns(
Promise.resolve());
Expand Down
Loading

0 comments on commit a3e53bb

Please sign in to comment.