Capacitor Socket Connection Plugin
npm install @spryrocks/[email protected]see main-capacitor5 branch for capacitor 5
see main-capacitor2 branch for capacitor 2
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.
- Thanks @JEreth for fix gradle config by adding missing settings and dependencies #22
- Thanks @dreadnought for update the plugin to Capacitor 6 #28
- Thanks @daanvanhulst for updating the plugin to Capacitor 7 [#43]