Code Monkey home page Code Monkey logo

nativescript-zeroconf's Introduction

nativescript-zeroconf

This nativescript-zeroconf plugin provides a Zeroconf/Bonjour implementation for both iOS and Android. Currently, it only supports discovering domains and services in the local network. Should there be any requests, I might implement the service registration parts as well (please open an issue to let me know).

Demo Application

This repository contains a demo application in the demo-angular folder that uses this plugin to display discovered Zeroconf domains and services. The demo app can be a good starting point for your app and may be used for narrowing down issues whilst debugging. Just clone this repo and run npm run demo.ios or npm run demo.android in the src folder.

The demo app searches for by default for http services, but you can easily adjust the serviceType in app/zeroconf/zeroconf.provider.ts.

Installation

tns plugin add nativescript-zeroconf

Usage

First, import the plugin into your provider/component, and, since the plugin returns an Observable also the relevant types:

import { Zeroconf } from 'nativescript-zeroconf';
import { Observable, PropertyChangeData } from 'tns-core-modules/data/observable';

Then, instantiate a Zeroconf and define the event listeners:

    this.zeroconf = new Zeroconf('_http._tcp.', 'local.'); // param 1 = service type, param 2 = domain

    /* define event listener */

    this.zeroconf.on(Observable.propertyChangeEvent, (data: PropertyChangeData) => {
      switch(data.propertyName.toString()) {
        case 'serviceFound': {
          console.log(`serviceFound: ${JSON.stringify(data.value)}`);
          break;
        }
      }
    });

    this.zeroconf.startServiceDiscovery();

Tip: have a look at the demo project for an example implementation

API

Describe your plugin methods and properties here. See nativescript-feedback for example.

Property Default Description
some property property default value property description, default values, etc..
another property property default value property description, default values, etc..

Limitations

License

MIT license (see LICENSE file)

nativescript-zeroconf's People

Contributors

abhayastudios avatar dependabot[bot] avatar jlewallen avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

nativescript-zeroconf's Issues

Chance of upgrading to NS7?

Hi,
Since NS7 is becoming more adopted (including in my projects), i was wondering if we could get this plugin updated for NS7.

I have had a go at this, and i can create a PR for the changes I've made. But unfortunately i haven't been able to get it to work just yet.

Module should return IP address of service providers for further action

Hello. Thanks for the awesome module. However, it doesn't return an IP address.

Here's what Bonjour returns:

{ addresses:
   [ 'fe80::1067:1df6:2e65:440e',
     '192.168.88.235',
     'fe80::f4ae:26ff:fe41:63fd',
     'fe80::4006:72c4:f4b7:6292',
     'fe80::cd1b:e77e:f9bb:6ae6',
     'fe80::608e:f9b2:c226:272b',
     'fe80::f287:c988:48f9:c88b',
     'fe80::1daf:386d:b81:afc6',
     'fe80::aede:48ff:fe00:1122' ],
  name: 'RoomOS',
  fqdn: 'RoomOS._http._tcp.local',
  host: 'Damilola-10.local',
  referer:
   { address: '192.168.88.235',
     family: 'IPv4',
     port: 5353,
     size: 568 },
  port: 3000,
  type: 'http',
  protocol: 'tcp',
  subtypes: [],
  rawTxt: <Buffer 0e 47 72 65 65 74 69 6e 67 3d 48 45 4c 4c 4f>,
  txt: { greeting: 'HELLO' } }

Here's what the module returns:

{eventName: "propertyChange", object: Zeroconf, propertyName: "serviceFound", value: Object, oldValue: undefined}
serviceFound: {"eventName":"propertyChange","object":{"_observers":{"propertyChange":[{}]},"serviceType":"_http._tcp.","netServiceBrowser":{}},"propertyName":"serviceFound","value":{"name":"RoomOS","type":"_http._tcp.","host":"Damilola-9.local.","port":3000}}

Resolve Hostname to IP?

Is there anyway with this plugin, or via other methods that i can resolve a hostname.

This plugin returns the hostname, eg. serviceFound: {"name":"FX DocuPrint M225 dw","type":"_printer._tcp.","host":"BRN3000000000.local.","port":515,"address":"{}"}'

Is there a reason for only returning the hostname, and not an IP address?

Long story short, i need an IP address, and not a hostname - it just wont work for my case. Using multiple tools, i am able to see the IP address through the mDNS/zeroconf service discovery.

I have had a look around in the plugin to get an understanding on what is going on. What is interesting is that the addresses property comes back with an empty object.

Any help would be appreciated.

No services are found.

Make sure to check the demo app(s) for sample usage

Make sure to check the existing issues in this repository

If the demo apps cannot help and there is no issue for your problem, tell us about it

Please, ensure your title is less than 63 characters long and starts with a capital
letter.

Which platform(s) does your issue occur on?

Pixel 3 / Android 10

Please, provide the following version numbers that your issue occurs with:

  • CLI: (run tns --version to fetch it)
    6.1.2
  • Cross-platform modules: (check the 'version' attribute in the
    node_modules/tns-core-modules/package.json file in your project)
    6.1.2
  • Runtime(s): (look for the "tns-android" and "tns-ios" properties in the package.json file of your project)
    "tns-android": {
        "version": "6.1.2"
      },
      "tns-ios": {
        "version": "6.1.0"
      }
    
  • Plugin(s): (look for the version numbers in the package.json file of your
    project and paste your dependencies and devDependencies here)
    "dependencies": {
      "nativescript-betterwebsockets": "^1.0.0",
      "nativescript-screen-orientation": "^2.0.0",
      "nativescript-theme-core": "~1.0.6",
      "nativescript-videoplayer": "^4.2.1",
      "nativescript-zeroconf": "^1.0.2",
      "tns-core-modules": "~6.1.0"
    },
    "devDependencies": {
      "nativescript": "^6.1.2",
      "nativescript-dev-webpack": "~1.2.0"
    },
    

Please, tell us how to recreate the issue in as much detail as possible.

I've used the example code to try and find services but nothing is returned. I'm using avahi-browse on another computer to verify that my services are in fact discoverable.

I see in the log that service discovery has started:

10-28 19:21:15.555  1456  2267 D NsdService: Discover services
10-28 19:21:15.555  1456  2267 D NsdService: mdnssd [discover, 78, _http._tcp.]
10-28 19:21:15.558  1456  2267 D NsdService: Discover 6 78_http._tcp.

Is there any code involved?

  • provide a code example to recreate the problem
  • (EVEN BETTER) provide a .zip with application or refer to a repository with application where the problem is reproducible.
    this.zeroconf = new Zeroconf('_http._tcp.', 'local.'); // param 1 = service type, param 2 = domain
    this.zeroconf.on(
        Observable.propertyChangeEvent, 
        (data) => {
            switch(data.propertyName.toString()) {
                case 'serviceFound': {
                  console.log(`serviceFound: ${JSON.stringify(data.value)}`);
                  break;
                }
                case 'serviceLost': {
                  console.log(`serviceLost: ${JSON.stringify(data.value)}`);
                  break;
                }
            }
        }
    );
    this.zeroconf.startServiceDiscovery();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.