2.0.6 • Published 3 years ago

@chipsgg/ws-api-client v2.0.6

Weekly downloads
-
License
MIT
Repository
bitbucket
Last release
3 years ago

WS API CLIENT

Standard websocket client for openservice-ws-server.

Install

yarn add @chipsgg/openservice-ws-client

Usage

Install for your frontend project.

import Client from '@chipsgg/openservice-ws-client'

//websockets must be supported in browser

const config = {
  host:'wss://yourwebsockethosturl',
  //your action/state channels, this is dependent on your server implementation
  channels:[
    //common example channels
    'public',
    'private',
    'auth',
  ]
}

const initState = {
  //some initial state
}

function handleStateChange(channel,channelState,fullState){
  //do something with the new state
  dispatch('updateChannelState')(channel,channelState)
}

Client(Websocket,config,initState,handleStateChange).then(api=>{
  //your api is an object with channels
  //see api documentation.
  //api = {
  //  public:{
  //    call(action,...arguments)=>promise,
  //  },
  //  private:{
  //    call(action,...arguments)=>promise,
  //  },
  //  auth:{
  //    call(action,...arguments)=>promise,
  //  },
  //  //low level objects available
  //  rpc:{
  //    call(),      //manually call api
  //    response(),  //manually respond to a pending call
  //    pending(),   //view all pending calls
  //  },
  //  setState(),  //manually set state, you need to know what you are doing
  //  getWs(),     //get websocket object
  //}

})
2.0.6

3 years ago

2.0.5

3 years ago

2.0.3

3 years ago