项目作者: EddyVerbruggen

项目描述 :
Detect when a headphone (jack or bluetooth) is (dis)connected.
高级语言: TypeScript
项目地址: git://github.com/EddyVerbruggen/nativescript-headset-detection.git
创建时间: 2017-12-02T14:23:53Z
项目社区:https://github.com/EddyVerbruggen/nativescript-headset-detection

开源协议:MIT License

下载


NativeScript Headset Detection plugin

Build Status
NPM version
Twitter Follow

Installation

  1. tns plugin add nativescript-headset-detection

API

isConnected

To check for a headset at any given moment, use this method:

JavaScript

  1. var headsetDetection = require("nativescript-headset-detection");
  2. headsetDetection.isConnected()
  3. .then(function (connected) { console.log("Connected? " + connected); })
  4. .catch(function (err) { console.log("Error: " + err)});

TypeScript

  1. import * as headsetDetection from 'nativescript-headset-detection';
  2. headsetDetection.isConnected()
  3. .then(connected => console.log(`Connected? ${connected}`))
  4. .catch(err => console.log(`Error: ${err}`));

onConnectionStateChanged

To listen to changes to the headset state, use this one (adding it to a high level component like `app.[ts|js] makes sense);
you can pass in a callback function that gets invoked whenever a headset is (dis)connected:

JavaScript

  1. var headsetDetection = require("nativescript-headset-detection");
  2. headsetDetection.onConnectionStateChanged(function (connected) {
  3. console.log("Connection changed to: " + connected);
  4. });

TypeScript

  1. import * as headsetDetection from 'nativescript-headset-detection';
  2. headsetDetection.onConnectionStateChanged(connected => console.log(`Connection changed to: ${connected}`));