cordova-plugin-sb-service-discovery

1.1.1 • Public • Published

Cordova Service Discovery

Forked from: https://github.com/scottdermott/cordova-plugin-discovery

Simple plugin to get any SSDP / UPnP / DLNA service on a local network

Using

$ cordova plugin add cordova-plugin-sb-service-discovery

Example angular service to discover particle devices:

import { Observable } from 'rxjs/Observable';
import { Injectable } from '@angular/core';
import 'rxjs/add/observable/fromPromise';
 
declare var serviceDiscovery: any;
 
@Injectable()
export class DiscoveryService {
    constructor() {}
 
    discoverParticleServices(): Observable<any[]> {
        console.log('Start service discovery');
        return Observable.fromPromise(
            new Promise((resolve, reject) => {
                try {
                    serviceDiscovery.getNetworkServices(
                        'ssdp:all',
                        function(devices) {
                            const particleDevices = devices.filter(d => {
                                const dString = JSON.stringify(d);
                                return dString.match('.*Particle.*');
                            });
                            console.log(JSON.stringify(particleDevices));
                            resolve(particleDevices);
                        },
                        function(err) {
                            console.log('ERROR:', err);
                            resolve([]);
                        }
                    );
                } catch (err) {
                    console.log(err);
                    resolve([]);
                }
            })
        );
    }
}

Package Sidebar

Install

npm i cordova-plugin-sb-service-discovery

Weekly Downloads

4

Version

1.1.1

License

MIT

Unpacked Size

19.3 kB

Total Files

9

Last publish

Collaborators

  • w3ll3k