capacitor-sockets/README.md
2024-10-03 13:55:00 -04:00

137 lines
3.7 KiB
Markdown

# capacitor-sockets
Sockets
## Install
```bash
npm install capacitor-sockets
npx cap sync
```
## API
<docgen-index>
* [`create(...)`](#create)
* [`connect(...)`](#connect)
* [`send(...)`](#send)
* [`disconnect(...)`](#disconnect)
* [`close(...)`](#close)
* [`addListener('state', ...)`](#addlistenerstate-)
* [`addListener('message', ...)`](#addlistenermessage-)
* [Interfaces](#interfaces)
</docgen-index>
<docgen-api>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
### create(...)
```typescript
create(options: { id: string; host: string; port: number; useTLS?: boolean; acceptInvalidCertificates?: boolean; }) => Promise<void>
```
| Param | Type |
| ------------- | --------------------------------------------------------------------------------------------------------------- |
| **`options`** | <code>{ id: string; host: string; port: number; useTLS?: boolean; acceptInvalidCertificates?: boolean; }</code> |
--------------------
### connect(...)
```typescript
connect(options: { id: string; }) => Promise<void>
```
| Param | Type |
| ------------- | ---------------------------- |
| **`options`** | <code>{ id: string; }</code> |
--------------------
### send(...)
```typescript
send(options: { id: string; message: string; }) => Promise<void>
```
| Param | Type |
| ------------- | --------------------------------------------- |
| **`options`** | <code>{ id: string; message: string; }</code> |
--------------------
### disconnect(...)
```typescript
disconnect(options: { id: string; }) => Promise<void>
```
| Param | Type |
| ------------- | ---------------------------- |
| **`options`** | <code>{ id: string; }</code> |
--------------------
### close(...)
```typescript
close(options: { id: string; }) => Promise<void>
```
| Param | Type |
| ------------- | ---------------------------- |
| **`options`** | <code>{ id: string; }</code> |
--------------------
### addListener('state', ...)
```typescript
addListener(eventName: "state", listenerFunc: (message: { id: string; state: string; }) => void) => Promise<PluginListenerHandle>
```
| Param | Type |
| ------------------ | ----------------------------------------------------------------- |
| **`eventName`** | <code>'state'</code> |
| **`listenerFunc`** | <code>(message: { id: string; state: string; }) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
--------------------
### addListener('message', ...)
```typescript
addListener(eventName: "message", listenerFunc: (message: { id: string; message: string; }) => void) => Promise<PluginListenerHandle>
```
| Param | Type |
| ------------------ | ------------------------------------------------------------------- |
| **`eventName`** | <code>'message'</code> |
| **`listenerFunc`** | <code>(message: { id: string; message: string; }) =&gt; void</code> |
**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
--------------------
### Interfaces
#### PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
</docgen-api>