Code Monkey home page Code Monkey logo

shivneri-ws-client-javascript's Introduction

GitHub version Node.js CI

shivneri-ws-client-javascript

Shivneri framework web socket client library for javascript

Installation

How to use

var socket = new shivneriWsClient.Instance();

// subscribe to event message which will be emited from server        
socket.on("message", (msg) => {
   console.log("message is", msg);
})

// connect to server

await socket.init(`localhost:4000/chat`);

// emit an event message to server
socket.emit("message","Hello world")

Docs

create instance

 var socket = new shivneriWsClient.Instance();

subsribe to events

// subscribe to event message which will be emited from server        
socket.on("message", (msg) => {
   console.log("message is", msg);
})

send a message to server

// emit an event message to server
socket.emit("message","Hello world")

sunscribe to system events

socket.onConnected = () => {
    console.log("connected")
}

socket.onDisconnected = () => {
    console.log("Disconnected")
}

socket.onError = (evt) => {
    console.log("error message is", evt.data)
}

close connection

socket.close();

Socket state

connectionState = socket.state;
if(connectionState==0){
    console.log("connecting")
}
else if(connectionState==1){
    console.log("connected")
}
else if(connectionState==2){
    console.log("closing")
}
else if(connectionState==3){
    console.log("closed")
}

confiure ping pong time

By default pingInterval is 10ms & pingTimeout is 10ms

socket.init("websocket url", {
    pingInterval: 5000,
    pingTimeout: 5000
})

shivneri-ws-client-javascript's People

Contributors

ujjwalguptaofficial avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.