rockiot-client
is a wrapper to easily connect a client (browser) to a rockiot-api server.
Copy the build folder and start a web server from the folder (you can use http-server).
A rockiot-api server is required in order to successfully test the client.
Include rockiot.client.js in your HTML page.
<script src="rockiot.client.js"></script>
...
<!DOCTYPE html>
<html>
...
<script>
const client = rockiot.client({
url: 'http://localhost:3030',
login: {
user: 'admin',
password: 'password',
strategy: 'local'
},
storage: window.localStorage,
timeout: 5000
}).then ( resp => {
return resp
})
...
</script>
</body>
</html>
rockiot.topic('subscribe', {
url: 'http://test.mosquitto.org',
port: '1883',
topic: 'rockiot/garden/outside',
name: 'Home Garden'
}).then(resp=>{
console.log ( resp )
})
rockiot.topic('unsubscribe', {
url: 'http://test.mosquitto.org',
port: '1883',
topic: 'rockiot/garden/outside',
name: 'Home Garden'
}).then(resp=>{
console.log ( resp )
})
const client = rockiot.client({
url: 'http://localhost:3030',
login: {
user: 'admin',
password: 'password',
strategy: 'local'
},
storage: window.localStorage,
timeout: 5000
}).then ( resp => {
resp.api.service('mqtt/realtime').on('payload', (payload) => {
console.log ( 'payload=>' , payload )
})
return resp
})