Skip to content

pauldev20/capacitor-websockets

Repository files navigation

capacitor-websockets 🔌

Simple WebSockets client and server for the Capacitor framework. It's only a really basic implementation with some caveats. If you find any bugs or have improvements create an issue or pull request.

Install

npm install capacitor-websockets
npx cap sync

API

startServer(...)

startServer(options?: StartOptions | undefined) => Promise<{ port: number; }>
Param Type
options StartOptions

Returns: Promise<{ port: number; }>


startClient(...)

startClient(options?: ClientOptions | undefined) => Promise<{ url: string; }>
Param Type
options ClientOptions

Returns: Promise<{ url: string; }>


stop()

stop() => Promise<void>

sendMessage(...)

sendMessage(options?: MessageData | undefined) => Promise<void>
Param Type
options MessageData

addListener('onOpen', ...)

addListener(eventName: 'onOpen', listenerFunc: (connection: SocketData) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Param Type
eventName 'onOpen'
listenerFunc (connection: SocketData) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('onClose', ...)

addListener(eventName: 'onClose', listenerFunc: (data: CloseData) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Param Type
eventName 'onClose'
listenerFunc (data: CloseData) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('onMessage', ...)

addListener(eventName: 'onMessage', listenerFunc: (data: MessageData) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Param Type
eventName 'onMessage'
listenerFunc (data: MessageData) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('onError', ...)

addListener(eventName: 'onError', listenerFunc: (data: CloseData) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
Param Type
eventName 'onError'
listenerFunc (data: CloseData) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


Interfaces

StartOptions

Prop Type
port number

ClientOptions

Prop Type
url string

MessageData

Prop Type
connection SocketData
message string

SocketData

Prop Type
ip string
host number

PluginListenerHandle

Prop Type
remove () => Promise<void>

CloseData

Prop Type
connection SocketData
error string

About

A simple WebSockets RFC6455 plugin for the Capacitor framework which implements client and server WebSocket handlers

Topics

Resources

Stars

Watchers

Forks