The Eddystone Advertising Library abstracts low level concepts of the Eddystone protocol and wraps existing Advertising APIs so that developers don't have to 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.
The Eddystone Advertising Library creates window.eddystone
of type
Eddystone
To advertise a url: Example
let registered_adv;
eddystone.registerAdvertisement({
type: 'url',
url: 'https://example.com',
advertisedTxPower: -20
}).then(advertisement => {
registered_adv = advertisement;
console.log('Advertising: ' + advertisement.url)
}).catch(error => console.log(error.message));
To stop advertising: Example
registered_adv.unregisterAdvertisement().then(() => {
console.log('Advertisement unregistered successfully.');
}).catch(error => console.log(error.message));
Or if you have multiple advertisements:
eddystone.advertisements.forEach(advertisement => {
advertisement.unregisterAdvertisement()
.then(() => console.log('Unregistered successfully'))
.catch(error => console.log('Couldn\'t unregister the advertisement: ' + error.message));
});
Example
const advertisement = require('eddystone-advertisement')
- eddystone-advertisement
- .EddystoneAdvertisement
- new EddystoneAdvertisement(id, options, platform)
- .id :
number
- .type :
string
- .url :
string
|undefined
- .advertisedTxPower :
number
|undefined
- .unregisterAdvertisement() ⇒
Promise.<void>
- .EddystoneFrameType :
enum
- .EddystoneAdvertisement
Represents the Advertisement being broadcasted.
Kind: static class of eddystone-advertisement
- .EddystoneAdvertisement
- new EddystoneAdvertisement(id, options, platform)
- .id :
number
- .type :
string
- .url :
string
|undefined
- .advertisedTxPower :
number
|undefined
- .unregisterAdvertisement() ⇒
Promise.<void>
Throws:
TypeError
If no platform was passed.Error
If type is an unsupported Frame Type.
Param | Type | Description |
---|---|---|
id | number |
Unique between browser restarts meaning the id will no longer be valid upon browser restart. |
options | EddystoneAdvertisementOptions |
The options used when creating the advertisement. |
platform | Object |
The underlying platform; used to unregister the advertisement. |
The ID of this advertisment.
Kind: instance property of EddystoneAdvertisement
The Eddystone Type
Kind: instance property of EddystoneAdvertisement
URL being advertised. Only present if type === 'url'
.
Kind: instance property of EddystoneAdvertisement
Tx Power included in the advertisement. Only present if type === 'url'
.
Kind: instance property of EddystoneAdvertisement
Unregisters the current advertisement.
Kind: instance method of EddystoneAdvertisement
Fulfill: void
- If the advertisement was unregistered successfully.
Reject: Error
- If the advertisement failed to be registered. If
the promise rejects the advertisment may still be broadcasting. The only
way to recover may be to reboot your machine.
Possible Eddystone frame types.
Kind: static constant of eddystone-advertisement
Read only: true
See
Properties
Name | Type | Default |
---|---|---|
URL | string |
"url" |
UID | string |
"uid" |
TLM | string |
"tlm" |
- eddystone-advertising
- Eddystone ⏏
- instance
- .advertisements :
Array.<EddystoneAdvertisement>
- .registerAdvertisement() ⇒
Promise.<EddystoneAdvertisement>
- .advertisements :
- inner
- ~EddystoneAdvertisementOptions :
Object
- ~EddystoneAdvertisementOptions :
- instance
- Eddystone ⏏
Exposes platform independent functions to register/unregister Eddystone Advertisements.
Contains all previously registered advertisements. Note: In a Chrome App, if the event page gets killed users won't be able to unregister the advertisement.
Kind: instance property of Eddystone
Function to register an Eddystone BLE advertisement.
Kind: instance method of Eddystone
Params: EddystoneAdvertisementOptions
options The characteristics
of the advertised Eddystone.
Fulfill: EddystoneAdvertisement
- If the advertisement was registered
successfully.
Reject: Error
- If the advertisement failed to be registered.
Object that contains the characteristics of the package to advertise.
Kind: inner typedef of Eddystone
Properties
Name | Type | Description |
---|---|---|
type | EddystoneFrameType |
Type of Eddystone. For now only 'url' is supported. |
url | string | undefined |
The URL to advertise |
advertisedTxPower | number | undefined |
The Tx Power to advertise |
- eddystone-chrome-os
- EddystoneChromeOS ⏏
- .registerAdvertisement(options) ⇒
Promise.<EddystoneAdvertisement>
- .unregisterAdvertisement(advertisement) ⇒
Promise.<void>
- ._constructAdvertisement() ⇒
ChromeOSAdvertisement
- .registerAdvertisement(options) ⇒
- EddystoneChromeOS ⏏
This class wraps the underlying ChromeOS BLE Advertising API.
Kind: Exported class
Todo
- Add link to API.
Function that registers an Eddystone BLE advertisement.
Kind: static method of EddystoneChromeOS
Fulfill: EddystoneAdvertisement
- If the advertisement was registered
successfully.
Reject: Error
- If the advertisement failed to be regsitered.
Param | Type | Description |
---|---|---|
options | EddystoneAdvertisementOptions |
The characteristics of the advertisement. |
Function to unregister an advertisement.
Kind: static method of EddystoneChromeOS
Fulfill: void
- If the advertisment was unregistered successfully.
Reject: Error
- If the advertisment failed to be unregistered.
Param | Type | Description |
---|---|---|
advertisement | EddystoneAdvertisement |
The advertisement to unregister. |
Construct the ChromeOS specific advertisement to register.
Kind: static method of EddystoneChromeOS
Returns: ChromeOSAdvertisement
- advertisement
Throws:
Error
If the frame type is not supportedError
If the Tx Power value is not in the allowed range. See: https://github.com/google/eddystone/tree/master/eddystone-url#tx-power-levelError
If the URL Scheme prefix is unsupported. For a list of supported Scheme prefixes see: https://github.com/google/eddystone/tree/master/eddystone-url#url-scheme-prefixError
If the URL contains an invalid character. For a list of invalid characters see the Note in: https://github.com/google/eddystone/tree/master/eddystone-url#eddystone-url-http-url-encoding
Params: EddystoneAdvertisementOptions
options The characteristics of the
advertisement.
- eddystone-url
- EddystoneURL ⏏
- .constructServiceData(url, advertisedTxPower) ⇒
Array.<number>
- .encodeURL(url) ⇒
Array.<number>
- .constructServiceData(url, advertisedTxPower) ⇒
- EddystoneURL ⏏
This class provides helper functions that relate to Eddystone-URL.
Kind: Exported class
See: Eddystone-URL
Constructs a valid Eddystone-URL service data from a URL and a Tx Power value.
Kind: static method of EddystoneURL
Returns: Array.<number>
- The service data.
See: URL Frame Specification
Param | Type | Description |
---|---|---|
url | string |
The URL to use in the service data. |
advertisedTxPower | number |
The Tx Power to use in the service data. |
Encodes the given string using the encoding defined in the Eddystone-URL Spec.
Kind: static method of EddystoneURL
Returns: Array.<number>
- The encoded url.
Throws:
Error
If the URL Scheme prefix is unsupported. For a list of supported Scheme prefixes see: https://github.com/google/eddystone/tree/master/eddystone-url#url-scheme-prefixError
If the URL contains an invalid character. For a list of invalid characters see the Note in: https://github.com/google/eddystone/tree/master/eddystone-url#eddystone-url-http-url-encoding
See: Eddystone-URL
Param | Type | Description |
---|---|---|
url | string |
The url to encode. |
Detects what API is available in the platform.
Kind: Exported function
Returns: Object
- An object that wraps the underlying BLE
Advertising API
Throws:
Error
If the platform is unsupported
eddystone : Eddystone
The global eddystone instance.
Kind: global variable