Skip to content
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

[WIP] MessageBus proposal #10

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d418d37
Add debug.html with mocked resolver response; check for mock existence
danekszy Jun 11, 2019
6ee6577
Add development info to README
danekszy Jun 11, 2019
814c059
Fix HHA port
danekszy Jun 11, 2019
01025bd
Adding mocked FQDN of a HoloPort and bundle_hash
peeech Jun 11, 2019
4d35923
Adding mocked FQDN of a HoloPort and bundle_hash
peeech Jun 11, 2019
1009f75
Update port and add comments
maackle Jun 18, 2019
48f863a
Adds dev server to replace resolver with proper response
maackle Jun 18, 2019
44871dd
README
maackle Jun 18, 2019
dcc21c1
Refactor: Move resolver functions into separate module
danekszy Jul 2, 2019
8cc0975
Simplify the code
danekszy Jul 3, 2019
77b397c
Add parcel dev-server
danekszy Jul 23, 2019
2acfd2c
Fix dev-server
danekszy Jul 23, 2019
6ce8a2d
Dirty message bus implementation with logging everywhere
danekszy Jul 25, 2019
2b26de0
Code style fixes
danekszy Jul 26, 2019
3d3b00a
Code cleanup, simple PubSub for handling subscribers
danekszy Jul 29, 2019
aa3364c
Working message bus with message queue
danekszy Jul 29, 2019
834f1e7
MessageBus requests (promises) support, host query example
danekszy Jul 29, 2019
a22a6b7
Fix linting
danekszy Jul 29, 2019
33195cf
Message queue clearing in provider
danekszy Jul 30, 2019
90143ef
requiredField helper
danekszy Jul 30, 2019
479a47f
Jest & first batch of tests
danekszy Jul 30, 2019
98871a1
Another batch of tests
danekszy Jul 30, 2019
fc2bf41
sendMessage tests
danekszy Aug 1, 2019
19465db
handleRequestUpdate tests
danekszy Aug 7, 2019
2081536
Configure basic tests on circle ci
danekszy Aug 9, 2019
831d271
Add build script
danekszy Aug 9, 2019
208eafa
Restructure tests on circle ci
danekszy Aug 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-proposal-class-properties",
]
}
65 changes: 65 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
version: 2.1

commands:
prepare-env:
steps:
- checkout
- restore_cache:
keys:
- v{{ .Environment.CIRCLE_CACHE_VERSION }}-{{ arch }}-npm-cache-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}
- v{{ .Environment.CIRCLE_CACHE_VERSION }}-{{ arch }}-npm-cache-master-{{ .Environment.CIRCLE_JOB }}
prepare-lint:
steps:
- run:
name: Install standard linter
command: npm i standard
setup-nodejs:
steps:
- prepare-env
- run:
name: NPM Versions
command: npm version
- run:
name: Install dependencies
command: npm ci
- run:
name: Webpack build
command: npm run build
- save-npm-cache
run-tests:
steps:
- setup-nodejs
- run:
name: Test
command: npm test
run-lint:
steps:
- prepare-env
- prepare-lint
- run:
name: Lint
command: npm run test:lint
save-npm-cache:
steps:
- save_cache:
key: v{{ .Environment.CIRCLE_CACHE_VERSION }}-{{ arch }}-npm-cache-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package-lock.json" }}
paths:
- ~/.npm/_cacache

jobs:
test-node-v10:
docker:
- image: node:10
steps:
- run-tests
lint-node-v10:
docker:
- image: node:10
steps:
- run-lint

workflows:
test:
jobs:
- test-node-v10
- lint-node-v10
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
dist-dev
.cache
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ This is Pre-Alpha software only for testing purposes.

## Description

This is a repository of the JavaScript tool which run on initial load of a web application running on Holo.Host P2P infrastructure.
This is a branch of loader that locally mocks KV store and proxy behaviour. For full instruction how to set up your local Holo development environment go [here](https://hackmd.io/TlzylZCqR_GJ3Tjs5ZPvqQ).

Every Holo web application starts from the hLoader index.html and index.js. The loader function `initHapp` reads the current URL and uses this to query the resolver service for Hosts which can provide the static assets and also a holochain node for the app that is registered at this URL.
If you're willing to use specific `bundel_hash` please update `index.html` to your needs.

The resolved returns a collection of host URLs, currently the first one is selected.
In the same maner the port that envoy is listening on for UI requests can be changed in `index.html`

The loader then loads content of the hApp into the iFrame. This is also used to configure the websocket connection in [hClient.js](https://github.com/Holo-Host/hClient.js/), the client side holo library, so that it can redirect holochain calls to the holo host.
## Dev server

In the next iteration iFrame will communicate with parent window to update page title, update url and handle browsing history.
To use the dev server you must modify your `/etc/hosts` to include the following:

## Deployment
127.0.0.1 resolver.holohost.net

TODO: Set up automatic deployment to holo infrastructure
Then, run the dev server like so:

```
npm install
sudo npm start <HHA_ID>
```

where HHA_ID is the hash of the Holo Hosting App entry (the hostingAppId). The sudo is so that the server can run on port 80.
45 changes: 45 additions & 0 deletions dev-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const cors = require('cors')
const express = require('express')
const morgan = require('morgan')
const app = express()
const Bundler = require('parcel-bundler')
const port = 80

const hostingAppId = process.argv[2]

if (!hostingAppId) {
console.error('Holo Hosting App ID must be specified as command line argument, e.g.:')
console.error('')
console.error(' npm start <HHA_ID>')
console.error('')
process.exit(1)
}

const bundler = new Bundler('dev/index.html', {
outDir: './dist-dev'
})

app.use(morgan('dev'))
app.use(cors({ origin: true }))

app.use('/', (req, res, next) => {
if (req.hostname === 'resolver.holohost.net') {
res.send({
// Holo Hosting App ID (change)
hash: hostingAppId,
hosts: [
// `pubkey` is arbitrary,
// 48080 is the port that envoy is listening on for static asset serving
'pubkey.holohost.net'
]
})
} else {
next()
}
})

app.use(bundler.middleware())

// app.use(express.static(path.join(__dirname, 'dev')))

app.listen(port, () => console.log(`Mock resolver listening on port ${port} for HHA ID: ${hostingAppId}`))
19 changes: 19 additions & 0 deletions dev/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example hApp</title>
<meta name="description" content="Loading Holo...">
<meta name="author" content="Holo">
<style>
body {
background-color: #ddd;
}
</style>
</head>
<body>
<!-- TODO: Render some placeholder/spinner for better UX -->
<div id="old_main"></div>
<script src="index.js"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions dev/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
This is an example consumer implementation (for example in hClient)
*/

import MessageBusConsumer from '../src/modules/message-bus/consumer'
import { REQEUST_ACTION_SUFFIX, REQEUST_SUCCESS_ACTION_SUFFIX } from '../src/modules/message-bus/const'

const bus = new MessageBusConsumer(window)

const testCallback = (action, data) => {
console.log('client got message', action, data)

// Simulate successful request response
bus.sendMessage(
'GET_APP_ID' + REQEUST_SUCCESS_ACTION_SUFFIX,
{
actionProviderRequestId: data.actionProviderRequestId,
actionPayload: 'this-is-my-app-id'
}
)
}

bus.subscribe(testCallback, 'GET_APP_ID' + REQEUST_ACTION_SUFFIX)

bus.makeRequest('GET_HOSTS', 'QmWzAyDWAeYYQVPAK87qPQryBLhje26dWvaYDMWcLgkwfe').then(
(data) => console.log('successfully got hosts from loader', data),
(data) => console.log('couldnt get hosts from loader', data)
)
92 changes: 0 additions & 92 deletions error.js

This file was deleted.

12 changes: 9 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<!doctype html>
<html lang="en">
<head>
<script src="index.js"></script>
<meta charset="utf-8">
<title>Loading Holo...</title>
<title>Loading Holo app...</title>
<meta name="description" content="Loading Holo...">
<meta name="author" content="Holo">
<style>
body {
margin: 0;
}
</style>
</head>
<body style="margin: 0">
<body>
<!-- TODO: Render some placeholder/spinner for better UX -->
<div id="old_main"></div>
<script src="src/index.js"></script>
</body>
</html>
Loading