Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

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

License

Notifications You must be signed in to change notification settings

RodrigoBertotti/askless-js-client

Repository files navigation

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:

  • 🤝 perform a websocket connection to exchange data that:

    • 📳 supports streams on the client side in Flutter

    • 💻 supports JavaScript clients: Web and Node.js

    • ↪️ it retries to send data automatically in case of connectivity issues between the client and the server

    • 🏷️ handles multiples and identical listen requests from a client as a single one in the server

  • ✏️ create your own CRUD operations with any database you like (Create, Read, Update and Delete)

  • ⛔ restrict client access to CRUD operations

  • 📣 notify in real-time clients who are listening for changes in a route, you can choose:

    • 🚷 only specify clients will receive the data

    • ✔️ all clients will receive the data

  • 🔒 accept and deny connection attempts

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:

  • ❔ questions

  • 💡 suggestions

  • 📄 documentation improvements

  • 🐜 potential bugs

License

MIT

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published