-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add http_get_json helper; bump version * add xbr buyer/seller examples
- Loading branch information
Showing
22 changed files
with
634 additions
and
20 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Utilities | ||
|
||
## HTTP requests | ||
|
||
Autobahn includes helpers to do HTTP requests returning JS promises, allowing | ||
a modern style of asynchronous programming without callback hell. | ||
|
||
To do a HTTP/GET requesting JSON data: | ||
|
||
```javascript | ||
autobahn.util.http_get_json("/config").then( | ||
function (config) { | ||
console.log(config); | ||
}, | ||
function (err) { | ||
console.log(err); | ||
} | ||
); | ||
``` | ||
|
||
JSON data can be served directly from Crossbar.io using a webservice of type `json`. | ||
|
||
Here is a node configuration that will serve the `value` configured on the HTTP | ||
URL `/config`: | ||
|
||
|
||
```json | ||
{ | ||
"workers": [ | ||
{ | ||
"type": "router", | ||
"transports": [ | ||
{ | ||
"type": "web", | ||
"endpoint": { | ||
"type": "tcp", | ||
"port": 8080 | ||
}, | ||
"paths": { | ||
"/": { | ||
"type": "static", | ||
"directory": "../web", | ||
"options": { | ||
"enable_directory_listing": true | ||
} | ||
}, | ||
"config": { | ||
"type": "json", | ||
"value": { | ||
"nodes": [ | ||
"ws://localhost:8081/ws", | ||
"ws://localhost:8082/ws", | ||
"ws://localhost:8083/ws", | ||
"ws://localhost:8084/ws" | ||
] | ||
} | ||
}, | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` |
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
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
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,8 @@ | ||
diff: | ||
clear | ||
@echo "" | ||
@echo "\n******* SELLER DIFF between browser/node:\n" | ||
-diff browser/seller.js nodejs/seller.js | ||
@echo "\n******* BUYER DIFF between browser/node:\n" | ||
-diff browser/buyer.js nodejs/buyer.js | ||
@echo "" |
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,33 @@ | ||
# XBR Seller/Buyer with Autobahn-JS | ||
|
||
Install NodeJS: | ||
|
||
```bash | ||
cd $HOME | ||
wget https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-x64.tar.xz | ||
tar xvf node-v10.16.0-linux-x64.tar.xz | ||
``` | ||
|
||
and add the following to `$HOME/.profile`: | ||
|
||
```bash | ||
export PATH=${HOME}/node-v10.16.0-linux-x64/bin:${PATH} | ||
``` | ||
|
||
Install dependencies | ||
|
||
```bash | ||
make deps | ||
``` | ||
|
||
To start the seller run | ||
|
||
```bash | ||
make seller | ||
``` | ||
|
||
For the buyer | ||
|
||
```bash | ||
make buyer | ||
``` |
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,2 @@ | ||
run: | ||
twistd -n web --listen tcp:8050 --path . |
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 @@ | ||
# XBR Buyer/Seller for Browser | ||
|
||
This folder contains a simple XBR buyer and XBR seller that runs in a HTML5 browser (Firefox/Chrome tested). | ||
|
||
Open | ||
|
||
* [XBR Buyer](buyer.html) | ||
* [XBR Seller](seller.html) | ||
|
||
and hit F12 to watch console output. | ||
|
||
> The respective JS code is identical to the NodeJS examples - the only difference are the very top couple of lines that import the Autobahn libraries. |
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> | ||
<meta charset="UTF-8"> | ||
<body> | ||
<script>AUTOBAHN_DEBUG = false;</script> | ||
<script src="autobahn.js"></script> | ||
<script src="autobahn-xbr.js"></script> | ||
<script src="buyer.js"></script> | ||
<h1>XBR Buyer Example</h1> | ||
<p>Open JavaScript console to watch output.</p> | ||
</body> | ||
</html> |
Oops, something went wrong.