Giter Club home page Giter Club logo

zilaws / client Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 9.8 MB

ZilaWS is a blazingly fast and very lightweight library that provides an extremely easy-to-use way to transmit data via websockets between clientside and serverside using eventhandlers and async waiters.

Home Page: https://zila.ws/docs/category/client-api

License: MIT License

JavaScript 15.99% TypeScript 84.01%
async browser client connection eventhandler events library nodejs realtime tcp

client's Introduction

ZilaWS Client

ZilaWS is a blazingly fast and very lightweight library that provides an extremely easy-to-use way to transmit data via websockets between client-side and server-side using eventhandlers and async waiters

Test status badge MIT License coverage label for branches coverage label for functions coverage label for lines of code coverage label for statements

ZilaWS logo

Looking for the zilaws-server package?

ZilaWS can establish WS connection to a non-zilaws server, but won't work as expected.

Waiters

ZilaWS has a unique function called waiter. Waiters (as their name suggests) can be awaited. They resolve when the client side MessageHandler resolves or returns thus making it perfect for retrieving data from a client. However if the client does not respond in time, waiters will resolve as undefined.

Parameters

Regular waiters

Regular waiters wait for a response for the amount of time specified by the maxWaiterTime property. This is a property of the client.

  • identifier: The name of the MessageHandler on the other side of the connection.
  • ...data: A waiter (or a send) can be given any number of any data.
socket.waiter<T>(identifier: string, ...data: any[]): Promise<T | undefined>

Timeout Waiters

  • maxWaitingTime: This paramater overrides the maximum waiting time for the corresponding waiter. The value is in miliseconds.
socket.waiterTimeout<T>(identifier: string, maxWaitingTime: number, ...data: any[]): Promise<T | undefined>

Example

Client

const client = await connectTo("wss://yourhost.com:6589");

console.log(await client.waiter("GetValueOfPI", "Some string") as number); // --> 3.141592653589793
console.log(await client.waiterTimeout("GetValueOfPI", 1200, "Some string") as number); // --> 3.141592653589793

Server

const server = new ZilaServer({
    port: 6589,
    https: {
        pathToCert: "cert/fullchain.pem",
        pathToKey: "cert/privkey.pem"
    }
});

server.setMessageHandler("GetValueOfPI", (param1: string) => {
    console.log(param1); // --> Some string
    return Math.PI;
});

More

ZilaWS offers much more. Check out the documentation!

client's People

Contributors

dependabot[bot] avatar snyk-bot avatar warstekhun avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.