0.0.2 • Published 5 years ago

semplice-client v0.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

npm.io

SempliceJS Client

Semplice Client Library

##Mode of use:

Global methods that facilitate communication with Semplice

//A new instance of Semplice-Client is created 
//and the use of websocket is activated
const semplice = new Semplice('http://localhost:3000', { websocket: true } );

// EventListener websocket
semplice.io().on('recived', function(res){
	console.log(res.detail);
});

// Fetch for Semplice API`s
semplice.fetch('/').then(res => res.json())
.then(response => console.log(response));

//Send data websocket
semplice.io().send('send',{data:'recived'});

###Methods

Function nameDescriptiontype
fetch(route,opts)Fetch for Semplice API`s | Function
on(event,callback)EventListener websocketFunction
send(event,data)Send data websocketFunction
socketID().set(id)Save new socketIDFunction
socketID().get()View socketIDFunction
encodeBin(str)Encode string to binFunction
decodeBin(str)Dencode bin to stringFunction

###Defaults events

Event nameDescriptiontype
SUCCESS_CONECTIONReturns the event when the connection is establishedEvent