Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit 8b28fb4

Browse files
authored
[CORE-1439] Stream Client code is not transpiled (#15)
* Transfer back to es6, transpile also node version * Only disable specific rules in webpack.config.js * Add mocha to eslintrc * Fix main js file name * Fix StreamrClient integration test * fix examples, add webpack example (still broken) * Add node_modules as externals in node build. Fix examples * cleanup files from examples/webpack/dist * examples/webpack/dist to .gitignore * add produce example for web * add shim for http and https * fix examples, add produce to webpack example
1 parent 0a389b4 commit 8b28fb4

31 files changed

+5893
-383
lines changed

.babelrc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
{
2-
"presets": ["env"],
3-
"plugins": ["babel-plugin-add-module-exports",
4-
["transform-runtime", {
5-
"polyfill": false,
6-
"regenerator": true
7-
}]]
2+
"presets": ["env", "stage-2"],
3+
"plugins": ["babel-plugin-add-module-exports"]
84
}

.eslintrc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module.exports = exports = {
22
extends: 'streamr',
3+
env: {
4+
mocha: true,
5+
},
36
rules: {
4-
// Transpiling for node would add a lot of complexity, se let's accept having to write CommonJS modules
5-
67
'no-plusplus': ["error", { "allowForLoopAfterthoughts": true }],
78
'no-underscore-dangle': ["error", { "allowAfterThis": true }]
89
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ node_modules
3030
*.iml
3131
.DS_Store
3232
dist/*
33+
examples/webpack/dist/*

examples/node/package-lock.json

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"description": "Using streamr-client in node",
55
"main": "node.js",
66
"dependencies": {
7-
"streamr-client": "0.10.0"
7+
"streamr-client": "^0.10.2"
88
}
99
}

examples/web/browser.html

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<html>
2+
<head>
3+
<!-- For debug messages, include debug.js and set localStorage.debug = 'StreamrClient'. See from https://github.com/visionmedia/debug -->
4+
<script src="../../dist/streamr-client.web.min.js"></script>
5+
6+
<script>
7+
const log = (msg) => {
8+
var elem = document.createElement('p')
9+
elem.innerHTML = msg
10+
document.body.appendChild(elem)
11+
}
12+
13+
const STREAM_ID = 'MY-STREAM-ID'
14+
const API_KEY = 'MY-API-KEY'
15+
16+
// Create the client and give the API key to use by default
17+
const client = new StreamrClient({
18+
restUrl: 'http://localhost:8890/api/v1',
19+
apiKey: API_KEY
20+
})
21+
22+
function produce() {
23+
// Here is the event we'll be sending
24+
const msg = {
25+
hello: 'world',
26+
random: Math.random()
27+
}
28+
29+
// Produce the event to the Stream
30+
client.produceToStream(STREAM_ID, msg)
31+
.then(() => console.log('Sent successfully: ', msg))
32+
.catch((err) => log(err))
33+
}
34+
</script>
35+
</head>
36+
<body>
37+
<button id="produce">Produce</button>
38+
<script>
39+
document.getElementById('produce').addEventListener('click', produce)
40+
</script>
41+
</body>
42+
</html>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<html>
2+
<head>
3+
<!-- For debug messages, include debug.js and set localStorage.debug = 'StreamrClient'. See from https://github.com/visionmedia/debug -->
4+
<script src="../../dist/streamr-client.web.min.js"></script>
5+
6+
<script>
7+
const log = (msg) => {
8+
var elem = document.createElement('p')
9+
elem.innerHTML = msg
10+
document.body.appendChild(elem)
11+
}
12+
13+
// Create the client with default options
14+
const client = new StreamrClient()
15+
16+
// Subscribe to a stream
17+
const subscription = client.subscribe({
18+
stream: '7wa7APtlTq6EC5iTCBy6dw',
19+
// Resend the last 10 messages on connect
20+
resend_last: 10,
21+
}, (message) => {
22+
// Handle the messages in this stream
23+
log(JSON.stringify(message))
24+
})
25+
26+
// Event binding examples
27+
client.on('connected', function() {
28+
log('A connection has been established!')
29+
})
30+
31+
subscription.on('subscribed', function() {
32+
log('Subscribed to ' + subscription.streamId)
33+
})
34+
35+
subscription.on('resending', function() {
36+
log('Resending from ' + subscription.streamId)
37+
})
38+
39+
subscription.on('resent', function() {
40+
log('Resend complete for ' + subscription.streamId)
41+
})
42+
43+
subscription.on('no_resend', function() {
44+
log('Nothing to resend for ' + subscription.streamId)
45+
})
46+
</script>
47+
</head>
48+
<body>
49+
</body>
50+
</html>

examples/webpack/.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["env", "stage-2"],
3+
"plugins": ["babel-plugin-add-module-exports"]
4+
}

examples/webpack/dist/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)