Capacitor Socket Connection Plugin
npm install @spryrocks/capacitor-socket-connection-plugin@2.3.0
see main branch for capacitor 6
see main-capacitor5 branch for capacitor 5
const socket = new Socket();
socket.onData = function(data) {
// handle received data
};
Name | Type |
---|---|
data | Uint8Array |
socket.onClose = function() {
// handle socket close
};
socket.onError = function(error) {
// handle socket error
};
Name | Type |
---|---|
error | unknown |
socket.onStateChanged = function(state) {
// handle socket state change
};
Name | Type |
---|---|
state | SocketState |
await socket.open(host, port);
Name | Type |
---|---|
host | String |
port | Number |
await socket.write(data);
Name | Type |
---|---|
data | Uint8Array |
await socket.close();
const state = socket.state;
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.