npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nesto-software/capacitor-websocket

v1.0.5

Published

Basic websocket for capacitor

Downloads

3

Readme

websocket

Basic, cross-platform native websocket implementation for Capacitor/Ionic.

Install

npm install @miaz/capacitor-websocket
npx cap sync

Usage

Rather than overriding Capacitor's addListener and notifyListener under the hood, create specific event names to the source they're coming from, separated with a colon and then the event name itself.

type EventSourceNames = "chat" | "live";

addListener<EventSourceNames>("chat:message", ...);
addListener<EventSourceNames>("live:message", ...);

API

connect(...)

connect(options: ConnectOptions) => Promise<void>

| Param | Type | | ------------- | --------------------------------------------------- | | options | OptionsBase |


disconnect(...)

disconnect(options: DisconnectOptions) => Promise<void>

| Param | Type | | ------------- | --------------------------------------------------- | | options | OptionsBase |


send(...)

send(options: SendOptions) => Promise<void>

| Param | Type | | ------------- | --------------------------------------------------- | | options | SendOptions |


applyListeners(...)

applyListeners(options: ApplyListenersOptions) => Promise<void>

| Param | Type | | ------------- | --------------------------------------------------- | | options | OptionsBase |


build(...)

build(options: BuildOptions) => Promise<void>

| Param | Type | | ------------- | ----------------------------------------------------- | | options | BuildOptions |


addListener(${T}:message, ...)

addListener<T extends string>(eventName: `${T}:message`, listenerFunc: (event: MessageEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

| Param | Type | | ------------------ | ------------------------------------------------------------------------- | | eventName | ${T}:message | | listenerFunc | (event: MessageEvent) => void |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener(${T}:connected, ...)

addListener<T extends string>(eventName: `${T}:connected`, listenerFunc: (event: ConnectedEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

| Param | Type | | ------------------ | ----------------------------------------------------------------------------- | | eventName | ${T}:connected | | listenerFunc | (event: ConnectedEvent) => void |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener(${T}:disconnected, ...)

addListener<T extends string>(eventName: `${T}:disconnected`, listenerFunc: (event: DisconnectedEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

| Param | Type | | ------------------ | ----------------------------------------------------------------------------------- | | eventName | ${T}:disconnected | | listenerFunc | (event: DisconnectedEvent) => void |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener(${T}:statechange, ...)

addListener<T extends string>(eventName: `${T}:statechange`, listenerFunc: (event: StateChangedEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

| Param | Type | | ------------------ | ----------------------------------------------------------------------------------- | | eventName | ${T}:statechange | | listenerFunc | (event: StateChangedEvent) => void |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener(${T}:closeframe, ...)

addListener<T extends string>(eventName: `${T}:closeframe`, listenerFunc: (event: CloseFrameEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

| Param | Type | | ------------------ | ------------------------------------------------------------------------------- | | eventName | ${T}:closeframe | | listenerFunc | (event: CloseFrameEvent) => void |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener(${T}:connecterror, ...)

addListener<T extends string>(eventName: `${T}:connecterror`, listenerFunc: (event: ConnectErrorEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

| Param | Type | | ------------------ | ----------------------------------------------------------------------------------- | | eventName | ${T}:connecterror | | listenerFunc | (event: ConnectErrorEvent) => void |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener(${T}:error, ...)

addListener<T extends string>(eventName: `${T}:error`, listenerFunc: (event: ErrorEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

| Param | Type | | ------------------ | --------------------------------------------------------------------- | | eventName | ${T}:error | | listenerFunc | (event: ErrorEvent) => void |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener(${T}:messageerror, ...)

addListener<T extends string>(eventName: `${T}:messageerror`, listenerFunc: (event: MessageErrorEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

| Param | Type | | ------------------ | ----------------------------------------------------------------------------------- | | eventName | ${T}:messageerror | | listenerFunc | (event: MessageErrorEvent) => void |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener(${T}:senderror, ...)

addListener<T extends string>(eventName: `${T}:senderror`, listenerFunc: (event: SendErrorEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

| Param | Type | | ------------------ | ----------------------------------------------------------------------------- | | eventName | ${T}:senderror | | listenerFunc | (event: SendErrorEvent) => void |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener(${T}:textmessageerror, ...)

addListener<T extends string>(eventName: `${T}:textmessageerror`, listenerFunc: (event: TextMessageErrorEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

| Param | Type | | ------------------ | ------------------------------------------------------------------------------------------- | | eventName | ${T}:textmessageerror | | listenerFunc | (event: TextMessageErrorEvent) => void |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener(${T}:textmessage, ...)

addListener<T extends string>(eventName: `${T}:textmessage`, listenerFunc: (event: TextMessageEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

| Param | Type | | ------------------ | --------------------------------------------------------------------------------- | | eventName | ${T}:textmessage | | listenerFunc | (event: TextMessageEvent) => void |

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


Interfaces

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |

Type Aliases

ConnectOptions

OptionsBase

OptionsBase

{ name: string, }

DisconnectOptions

OptionsBase

SendOptions

OptionsBase & { data: any }

ApplyListenersOptions

OptionsBase

BuildOptions

OptionsBase & { url: string, headers?: { [headerKey: string]: string, } }

MessageEvent

{ data: string }

ConnectedEvent

{ headers: { [x: string]: string[] } }

DisconnectedEvent

{ closedByServer: boolean, serverCloseFrame: string, clientCloseFrame: string }

StateChangedEvent

{ state: string }

CloseFrameEvent

{ frame: string }

ConnectErrorEvent

{ exception: string }

ErrorEvent

{ cause: string }

MessageErrorEvent

{ cause: string, frame: string }

SendErrorEvent

{ cause: string, frame: string }

TextMessageErrorEvent

{ data: string, cause: string }

TextMessageEvent

{ data: string }