New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

capacitor-eventsource

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

capacitor-eventsource

EventSource (SSE) API for Capacitor

latest
Source
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

Native SSE (EventSource) Plugin for Capacitor

Because of the way Capacitor plugins are designed, it does not exactly follow the format/signature of the "real" browser EventSource API, but it works similarly.

Installation

npm install capacitor-eventsource
npx cap sync

On iOS or for pure-web use, no further steps are needed.

Android Installation

On Android, update your main activity to pull in the EventSource plugin:

import com.raccoonfink.plugins.eventsource.EventSource;

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
      // Additional plugins you've installed go here
      // Ex: add(TotallyAwesomePlugin.class);
      add(EventSource.class);
    }});
  }
}

Usage

EventSource.configure({
  url: 'https://my-sse-url/',
  reconnectTime: 1000,
  maxReconnectTime: 60000,
  idleTimeout: 30000,
});
EventSource.addListener('open', (openResult) => {
  console.debug('Connection opened.');
});
EventSource.addListener('message', (messageResult) => {
  console.info('I got a message: ' + messageResult.message);
});
EventSource.addListener('error', (errorResult) => {
  console.error('Uh-oh: ' + errorResult.error);
});
EventSource.addListener('readyStateChanged', (readyStateChangedResult) => {
  console.debug('Ready state changed: ' + readyStateChangedResult.state);
});

Parameters

note: all times are in milliseconds

  • url: required the URL to connect to
  • reconnectTime: time to reconnect after the first failure (iOS/Android)
  • maxReconnectTime: maximum amount of time to wait until attempting a reconnect (iOS/Android)
  • idleTimeout: maximum amount of time between receiving any data before considering the connection to have timed out (iOS/Android)

Keywords

capacitor

FAQs

Package last updated on 28 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts