RodrigoBertotti / askless-js-client

JavaScript client of Askless framework, which facilitates building realtime servers for JavaScript and Flutter Apps
MIT License
1 stars 0 forks source link
javascript realtime websockets

DISCONTINUED

The JavaScript Client of Askless is discontinued, if is useful for you, you can show interest in a continuation of Askless JS Client by sending me an email: rodrigo@wisetap.com

For Flutter Devs, check the Flutter Client of Askless here: askless-flutter-client


Askless - JavaScript client

JavaScript client of Askless framework, which facilitates building realtime servers for JavaScript and Flutter Apps allowing to:

This is the client side in JavaScript, click here to access the server side in Node.js.

Important links

Getting Started

Alt Text

The "Getting Started" is a example for a Node.js client, but it can be easily changed to SPA's (Vue, Angular, React) by changing how the library is imported (step 3).

1 - First create the server, click here and follow the server instructions in the section "Getting Started"

2 - Install

npm install askless-js-client --save

3 - Import by using ES5 or ES6

ES5:

// If you will run on the browser
const AsklessClient = require("askless-js-client/web") 

// If you will run on Node.js environment
const AsklessClient = require("askless-js-client/node") 

ES6:

import {AsklessClient} from "askless-js-client/web";

//or

import {AsklessClient} from "askless-js-client/node";

4 - Create an instance of the Askless client, and export it for your entire project

export const asklessClient = new AsklessClient();

5 - Initialize informing the server url with port (default: 3000). On the server side you can access the myAsklessServer.localUrl attribute to discover.

6 - Perform the connection with asklessClient.connect()

Example:

asklessClient.init({
     serverUrl: 'ws://192.168.2.1:3000',
});
asklessClient.connect();  

7 - Get realtime data updates

this.listening = asklessClient.listen({
    route: 'product/tracking',

    listen: data => {
        console.log("NEW DATA RECEIVED: ");
        console.log(data);
        //todo: update the text on the screen
    },
});

8 - Send data to the server when the user click on the button

asklessClient.create({
    route: 'product/customerSaid',
    body: 'I\'m waiting'
});

9 - We need to stop listening from product/customerSaid route on server, in this example let's stop after 120 seconds, but you should stop listening to this route when the user changes the screen

setTimeout(() => {
    this.listening.close();
    console.log("Stopped listening");
}, 120 * 1000);

Project ready! You can run :)

Following these links, you can also check this "Getting Started" complete project of the JavaScript client and of the server in Node.js.

Issues

Feel free to open a issue about:

License

MIT