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 🙏

© 2026 – Pkg Stats / Ryan Hefner

capacitor-foreground-websocket

v1.0.1

Published

Capacitor plugin for a persistent foreground WebSocket client with wake-up mechanisms

Readme

capacitor-foreground-websocket

capacitor-foreground-websocket is a Capacitor plugin that provides a persistent WebSocket client running as a foreground service. It works on both Android and iOS, ensuring the WebSocket connection remains active regardless of window changes, backgrounding, or other apps being opened. This plugin is designed to integrate seamlessly with Quasar Framework applications.

Features

  • Foreground Service: Runs as a persistent foreground service on Android (displayed in the notification bar) and as a background task on iOS.
  • WebSocket Connection: Connects to a specified IP and port using either ws or wss protocols.
  • Event Handling: Emits onopen, onmessage, onclose, onerror events to the JavaScript layer.
  • Message Sending: Supports sending messages from the Quasar app to the native layer via a send method.
  • Wake-Up Mechanism: Automatically wakes up the main application when a message is received, using native mechanisms:
    • Android: Uses WakeLock and Intent to bring the MainActivity to the foreground.
    • iOS: Uses PushKit (VoIP push) to wake the app in the background.
  • Cross-Platform Compatibility: Works on both Android and iOS.

Project Structure

 capacitor-foreground-websocket/
├── package.json
├── tsconfig.json
├── README.md
├── src/
│   ├── definitions.ts
│   ├── index.ts
│   └── web.ts
├── android/
│   └── src/
│         └── main/
│              └── java/
│                   └── com/
│                        └── example/
│                             └── capacitorforegroundwebsocket/
│                                  ├── CapacitorForegroundWebsocketPlugin.kt
│                                  └── ForegroundWebSocketService.kt
└── ios/
└── Plugin/
└── CapacitorForegroundWebsocketPlugin.swift

Installation

1. Install the Plugin

Install via npm:

npm install capacitor-foreground-websocket
npx cap sync

Android

OkHttp: Used for managing the WebSocket connection. Add the following dependency in your android/app/build.gradle file:

dependencies {
    implementation 'com.squareup.okhttp3:okhttp:4.9.1'
    // other dependencies...
}

iOS

No additional CocoaPod is required; however, configure background modes in your Info.plist as described below.

Platform Specific Configuration

Android

AndroidManifest.xml Modifications In your android/app/src/main/AndroidManifest.xml file, add the following permissions and service declaration:

<manifest ... >
    <!-- Required Permissions -->
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

    <application ... >
        <!-- Foreground Service Declaration -->
        <service
            android:name="com.example.capacitorforegroundwebsocket.ForegroundWebSocketService"
            android:foregroundServiceType="dataSync" 
            android:enabled="true" 
            android:exported="false" 
            tools:replace="android:exported"/>
        ...
    </application>
</manifest>

iOS

Info.plist Modifications Add the following keys to your Info.plist file to enable background modes:

<key>UIBackgroundModes</key>
<array>
    <string>voip</string>
    <string>fetch</string>
</array>

Sample Usage in a Quasar Framework Application

// Import the plugin
import { CapacitorForegroundWebsocket } from 'capacitor-foreground-websocket'

// Define WebSocket options
const options = {
  ip: '192.168.1.100',
  port: 8080,
  isWss: false,
  title: 'Foreground WebSocket',
  description: 'Persistent connection running in foreground'
}

// Start the WebSocket service
CapacitorForegroundWebsocket.start(options)
  .then(() => console.log('WebSocket service started successfully'))
  .catch(err => console.error('Error starting WebSocket service:', err))

// Add event listeners for WebSocket events
CapacitorForegroundWebsocket.addListener('onopen', (data) => {
  console.log('WebSocket opened:', data)
})

CapacitorForegroundWebsocket.addListener('onmessage', (data) => {
  console.log('Received message:', data)
})

CapacitorForegroundWebsocket.addListener('onclose', (data) => {
  console.log('WebSocket closed:', data)
})

CapacitorForegroundWebsocket.addListener('onerror', (data) => {
  console.error('WebSocket error:', data)
})

CapacitorForegroundWebsocket.addListener('onpush', (data) => {
  console.log('Push notification received:', data)
})

CapacitorForegroundWebsocket.addListener('onpushToken', (data) => {
  console.log('Push token:', data)
})

// Function to send messages through the WebSocket
function sendMessage(message) {
  CapacitorForegroundWebsocket.send(message)
    .then(() => console.log('Message sent successfully'))
    .catch(err => console.error('Error sending message:', err))
}

Contributing

Contributions are welcome! If you would like to contribute to this project, please open an issue or submit a pull request. All feedback and contributions are greatly appreciated.

License

This project is licensed under the MIT License.