Capacitor Socket Connection Plugin
npm install @spryrocks/capacitor-socket-connection-pluginCapacitor Socket Connection Plugin
``bash`
npm install @spryrocks/capacitor-socket-connection-plugin@7.0.0
see main-capacitor5 branch for capacitor 5
see main-capacitor2 branch for capacitor 2
`typescript`
const socket = new Socket();
#### onData
`typescript`
socket.onData = function(data) {
// handle received data
};
##### Callback function parameters
| Name | Type |
| ---- | ---------- |
| data | Uint8Array |
#### onClose
`typescript`
socket.onClose = function() {
// handle socket close
};
#### onError
`typescript`
socket.onError = function(error) {
// handle socket error
};
##### Callback function parameters
| Name | Type |
| ----- | ------- |
| error | unknown |
#### onStateChanges
`typescript`
socket.onStateChanged = function(state) {
// handle socket state change
};
##### Callback function parameters
| Name | Type |
| ----- | ----------- |
| state | SocketState |
`typescript`
await socket.open(host, port);
#### Parameters
| Name | Type |
| ---- | ------ |
| host | String |
| port | Number |
`typescript`
await socket.write(data);
#### Parameters
| Name | Type |
| ---- | ---------- |
| data | Uint8Array |
`typescript`
await socket.close();
`typescript``
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.
* Thanks @JEreth for fix gradle config by adding missing settings and dependencies #22
* Thanks @dreadnought for update the plugin to Capacitor 6 #28