-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a Fat Beacon support and an example #42
Open
hardillb
wants to merge
12
commits into
don:master
Choose a base branch
from
hardillb:fatbeacon
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7d50752
scans, but doesnt connect properly
jacobrosenthal eb27b3b
Get basic fat beacon working
hardillb 765c1fa
Fix for payloads large than 1 MTU
hardillb cb939a0
Adds services to passed in options
2832a63
cleaned things up a bit
9e735c1
cleaned things up a bit
hardillb 5c8598b
Merge branch 'fatbeacon' of github.com:hardillb/node-eddystone-beacon…
hardillb 0f251f3
Add Physical Web icon to the FatBeacon demo
hardillb 985d7ad
set service after advertising start. fix for osx
jacobrosenthal cb592f8
remove globals and use onDisconnect instead of onAccept to reset queu…
jacobrosenthal b790890
bind instead of self
jacobrosenthal 425e56d
Merge pull request #1 from jacobrosenthal/fatbeacon2
hardillb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html> | ||
<head> | ||
<title>Fat Beacon Demo</title> | ||
<meta charset='UTF-8'> | ||
<meta name='description' content='Fat Beacon Demo'/> | ||
</head> | ||
<body> | ||
<h1>HelloWorld</h1> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="171" height="202"><g fill="#3F82C4" fill-rule="evenodd"><path d="M141.2 85.3c0-31-25-56-56-56-30.7 0-55.8 25-55.8 56 0 17 7.8 32.5 20 42.8l10-10c-9.8-7.6-16-19.4-16-32.7 0-23.2 18.8-42 42-42 23 0 41.8 18.8 41.8 42 0 13.3-6.2 25-16 32.8l10 10c12.2-10.2 20-25.6 20-42.7"/><path d="M14 85.3C14 46 46 14 85.3 14s71.3 32 71.3 71.3c0 21.4-9.5 40.6-24.5 53.7l10 10c17.6-15.7 28.6-38.4 28.6-63.7 0-47-38.2-85.3-85.3-85.3C38.3 0 0 38.2 0 85.3c0 25.3 11 48 28.5 63.6l10-10C23.5 126 14 106.7 14 85.3"/><path d="M89.2 200.3c-2 2-5.5 2-7.6 0l-35.8-35.8c-2-2-2-5.5 0-7.6l35.8-36c2-2 5.5-2 7.6 0l35.8 36c2 2 2 5.4 0 7.5l-35.8 35.8z"/></g></svg> | ||
</body> | ||
</html> |
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,12 @@ | ||
// Simplest way to create a Eddystone-FatBeacon | ||
|
||
// might want to include something like this https://www.npmjs.com/package/html-minify | ||
|
||
var eddystoneBeacon = require('./../../index'); | ||
var fs = require('fs'); | ||
|
||
fs.readFile('index.html', function(err, data){ | ||
if (!err) { | ||
eddystoneBeacon.advertiseFatBeacon('Fat Beacon Demo', {html: data}); | ||
} | ||
}); |
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,60 @@ | ||
/** | ||
* Copyright 2016 IBM Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
**/ | ||
var bleno = require('bleno'); | ||
var util = require('util'); | ||
|
||
function HTMLCharacteristic(html) { | ||
this._currentMTU = 0; | ||
this._queueOffset = 0; | ||
this._html = html; | ||
this._buffer = new Buffer(this._html, 'utf8'); | ||
bleno.Characteristic.call(this, { | ||
uuid: 'd1a517f0249946ca9ccc809bc1c966fa', | ||
properties: ['read'], | ||
descriptors: [ | ||
new bleno.Descriptor({ | ||
uuid: '2901', | ||
value: 'HTML' | ||
}) | ||
] | ||
}); | ||
|
||
bleno.on('mtuChange', function(mtu) { | ||
this._currentMTU = mtu; | ||
}.bind(this)); | ||
|
||
bleno.on('disconnect', function(){ | ||
this._queueOffset = 0; | ||
}.bind(this)); | ||
} | ||
|
||
util.inherits(HTMLCharacteristic,bleno.Characteristic); | ||
|
||
HTMLCharacteristic.prototype.onReadRequest = function(offset, callback) { | ||
if (this._queueOffset < this._buffer.length) { | ||
var transfer = this._currentMTU - 5; | ||
var end = this._queueOffset + transfer >= this._buffer.length ? this._buffer.length: this._queueOffset + transfer; | ||
var slice = this._buffer.slice(this._queueOffset, end); | ||
callback(this.RESULT_SUCCESS, slice); | ||
this._queueOffset = end; | ||
} else if (this._queueOffset === this._buffer.length) { | ||
callback(this.RESULT_SUCCESS, new Buffer()); | ||
this._queueOffset++; | ||
} | ||
|
||
} | ||
|
||
module.exports = HTMLCharacteristic; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about adding this in a separate file and using the
fs
module to read the contents?