137 lines
3.7 KiB
Markdown
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; }) => Promise<void>
|
|
```
|
|
|
|
| Param | Type |
|
|
| ------------- | ---------------------------- |
|
|
| **`options`** | <code>{ id: string; }</code> |
|
|
|
|
--------------------
|
|
|
|
|
|
### connect(...)
|
|
|
|
```typescript
|
|
connect(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> |
|
|
|
|
--------------------
|
|
|
|
|
|
### 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; }) => void</code> |
|
|
|
|
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></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; }) => void</code> |
|
|
|
|
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
|
|
--------------------
|
|
|
|
|
|
### Interfaces
|
|
|
|
|
|
#### PluginListenerHandle
|
|
|
|
| Prop | Type |
|
|
| ------------ | ----------------------------------------- |
|
|
| **`remove`** | <code>() => Promise<void></code> |
|
|
|
|
</docgen-api>
|