@curvebeamai/web-connect-service
v1.1.7
Published
Web connect service is a typescript library for connecting to a web socket and enabling communication between two frontend clients.
Downloads
121
Readme
Web Connect Service
Web connect service is a typescript library for connecting to a web socket and enabling communication between two frontend clients.
Installation
npm install @curvebeamai/web-connect-service
Usage
Connect to Web socket
import { WebSocketService } from "@curvebeamai/web-connect-service";
const webSocketServiceInstance = WebSocketService.getInstance();
const connectionOptions = new ConnectionOptions(
webSocketURL,
clientId,
sessionId,
tokenValidationEndpoint
);
webSocketServiceInstance.connect(connectionOptions).then((response: WebSocketServiceResponseObject) => {
// your application logic here
});
For sending messages and other options read on ...
Methods Summary
| Method Name | Description |
| ----------- | ----------- |
registerDisconnectHandler
| Register the method to call when the web socket connection is disconnected |
| sendMessage
| Send message to all the connected applications through web socket |
| closeConnection
| Close the web socket connection |
Methods
registerDisconnectHandler
This method registers the callback to be called when the web socket has successfully disconnected.
Example:
import { WebSocketService } from "@curvebeamai/web-connect-service";
function handleDisconnect(response: WebSocketServiceResponseObject){
// your application disconnect logic here
}
webSocketServiceInstance.RegisterDisconnectHandler(handleDisconnect);
sendMessage
Send message on web socket for all the connected applications. Returns a boolean variab
Example:
import { WebSocketService } from "@curvebeamai/web-connect-service";
// create message and request object
const dataObject = new WebSocketDataObject("Message to Send", sessionId);
const message = new WebSocketRequestObject("web-socket-action", dataObject);
webSocketServiceInstance.sendMessage(message);
closeConnection
Close the web socket connection
Example:
import { WebSocketService } from "@curvebeamai/web-connect-service";
webSocketServiceInstance.closeConnection();