-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from evrythng/v1-dev
Update for evrythng.js v5, to replace separate MQTT and WS SDKs
- Loading branch information
Showing
32 changed files
with
9,657 additions
and
194 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,3 @@ bower_components | |
dist | ||
report | ||
.idea | ||
*.sh |
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 |
---|---|---|
|
@@ -5,5 +5,3 @@ node_modules | |
bower_components | ||
report | ||
.idea | ||
docker | ||
Dockerfile |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM node:8-alpine | ||
|
||
WORKDIR /srv | ||
COPY . /srv | ||
|
||
# Install dependencues | ||
RUN apk add --no-cache python3 | ||
RUN pip3 install awscli --upgrade --user | ||
RUN npm i | ||
|
||
# Build | ||
RUN npm run build | ||
|
||
# Deploy | ||
CMD ["sh", "-c", "~/.local/bin/aws s3 cp /srv/dist/evrythng-pubsub.js s3://$BUCKET/js/evrythng-pubsub/$VERSION/evrythng-pubsub-$VERSION.js --acl public-read"] |
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,63 +1,91 @@ | ||
# evrythng-pubsub.js [](https://travis-ci.org/evrythng/evrythng-pubsub.js) | ||
# evrythng-pubsub.js | ||
|
||
[](http://standardjs.com) | ||
Plugin for [`evrythng.js`](https://github.com/evrythng/evrythng.js) (v5.1.0 and | ||
above) allowing easy subscription and publication to resources such as Thngs, | ||
products, and actions using either MQTT or WebSockets. | ||
|
||
## Getting started | ||
|
||
### Install evrythng-pubsub.js using npm. | ||
## Install | ||
|
||
```javascript | ||
npm install evrythng-pubsub | ||
### npm | ||
|
||
``` | ||
npm i --save evrythng-pubsub | ||
``` | ||
|
||
Then require it into any module. | ||
|
||
```javascript | ||
const EVT = require('evrythng') | ||
const EVTPubSub = require('evrythng-pubsub') | ||
```js | ||
const evrythng = require('evrythng') | ||
const PubSub = require('evrythng-pubsub') | ||
|
||
evrythng.use(PubSub) | ||
``` | ||
|
||
EVT.use(EVTPubSub) | ||
### CDN | ||
|
||
/* ... Init app using EVT.js ... */ | ||
Add it as a script tag to your page: | ||
|
||
app.scan().then(match => { | ||
app.redirect(match.redirections[0].redirectUrl) | ||
}) | ||
```html | ||
<script src="https://d10ka0m22z5ju5.cloudfront.net/js/evrythng-pubsub/1.0.0/evrythng-pubsub-1.0.0.js"></script> | ||
``` | ||
|
||
### Browser | ||
|
||
To use immutable from a browser, download `dist/evrythng-pubsub.min.js` or use a CDN such as CDNJS or jsDelivr. | ||
Then use in the same manner as for Node: | ||
|
||
Then, add it as a script tag to your page: | ||
|
||
```html | ||
<script src="evrythng.min.js"></script> | ||
<script src="evrythng-pubsub.min.js"></script> | ||
<script> | ||
EVT.use(EVTPubSub) | ||
evrythng.use(PubSub) | ||
</script> | ||
``` | ||
|
||
/* ... Init app using EVT.js ... */ | ||
|
||
app.scan().then(match => { | ||
app.redirect(match.redirections[0].redirectUrl) | ||
}) | ||
</script> | ||
## Usage | ||
|
||
After installing the plugin with `evrythng.use()`, three methods are added to | ||
all resource types, such as Thngs, products, actions, etc. if they are | ||
[available as subscription topics](https://developers.evrythng.com/docs/pubsub#section-available-topics). | ||
|
||
* `.subscribe(onMessage)` - Subscribe to topic updates with a callback. | ||
* `.unsubscribe()` - Unsubscribe from topic updates. | ||
* `.publish(payload)` - Publish to a topic with payload data, such as an action. | ||
|
||
|
||
## Examples | ||
|
||
Subscribe to all actions: | ||
|
||
```js | ||
const onActionCreated = (action) => { | ||
console.log(`Action created: ${action.id} of type ${action.type}`) | ||
} | ||
|
||
await user.action('all').subscribe(onActionCreated) | ||
``` | ||
|
||
Or use an AMD loader (such as RequireJS): | ||
Pubish a new action: | ||
|
||
```js | ||
const payload = { type: 'scans', thng: thngId } | ||
|
||
```javascript | ||
require(['./evrythng.min.js', './evrythng-pubsub.min.js'], (EVT, EVTPubSub) => { | ||
EVT.use(EVTPubSub) | ||
await user.action('all').publish(payload) | ||
``` | ||
|
||
/* ... Init app using EVT.js ... */ | ||
Unsubscribe from all actions: | ||
|
||
app.scan().then(match => { | ||
app.redirect(match.redirections[0].redirectUrl) | ||
}) | ||
}) | ||
```js | ||
await user.action('all').unsubscribe() | ||
``` | ||
|
||
If you're using browserify, the `evrythng-pubsub npm module also works from the browser. | ||
|
||
## Testing | ||
|
||
Use the `tests/browser` and `tests/node` directories to test this SDK in the | ||
browser or Node, or run the Mocha test suite using a testable Trusted | ||
Application API Key: | ||
|
||
``` | ||
export TRUSTED_API_KEY=a87s9j3h... | ||
npm test | ||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# Use a Docker container to build and deploy a new SDK build to the S3 bucket | ||
# used for distribution (publish to npm happens separately). | ||
# | ||
# Required environment variables: | ||
# BUCKET - The S3 bucket to push the built SDK file. | ||
# VERSION - The new SDK version being published. | ||
# AWS_ACCESS_KEY_ID - AWS Access Key ID with permission to put to the bucket. | ||
# AWS_SECRET_ACCESS_KEY - AWS Secret Key ID corresponding to the AWS_ACCESS_KEY_ID. | ||
|
||
docker build -t evrythng-pubsub-js-deploy . | ||
|
||
docker run \ | ||
-e "BUCKET=$BUCKET" \ | ||
-e "VERSION=$VERSION" \ | ||
-e "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" \ | ||
-e "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" \ | ||
evrythng-pubsub-js-deploy |
Oops, something went wrong.