@spryrocks/capacitor-socket-connection-plugin
TypeScript icon, indicating that this package has built-in type declarations

2.3.0 • Public • Published

@spryrocks/capacitor-socket-connection-plugin

Capacitor Socket Connection Plugin

Install

npm install @spryrocks/capacitor-socket-connection-plugin@2.3.0

see main branch for capacitor 6

see main-capacitor5 branch for capacitor 5

Usage

Create instance of socket connection class

const socket = new Socket();

Bind to events

onData

socket.onData = function(data) {
  // handle received data
};
Callback function parameters
Name Type
data Uint8Array

onClose

socket.onClose = function() {
    // handle socket close
};

onError

socket.onError = function(error) {
    // handle socket error
};
Callback function parameters
Name Type
error unknown

onStateChanges

socket.onStateChanged = function(state) {
    // handle socket state change
};
Callback function parameters
Name Type
state SocketState

Connect socket to endpoint

await socket.open(host, port);

Parameters

Name Type
host String
port Number

Write data to socket

await socket.write(data);

Parameters

Name Type
data Uint8Array

Close socket connection

await socket.close();

Get current state

const state = socket.state;

Q&A

Q: When I call the open method after being disconnected, I will be prompted that the open method can only be called once. How should I reconnect?

A: To re-connect the socket you should create the new socket and then open it.

Readme

Keywords

Package Sidebar

Install

npm i @spryrocks/capacitor-socket-connection-plugin

Weekly Downloads

53

Version

2.3.0

License

MIT

Unpacked Size

116 kB

Total Files

79

Last publish

Collaborators

  • maxim.zhemerenko