From 2d4f3e917502b3c0f3de2f5586cca1851be9e2e0 Mon Sep 17 00:00:00 2001 From: tanguy stenel Date: Tue, 28 May 2019 12:28:06 +0200 Subject: [PATCH 01/22] modifications to bluez.js --- .idea/jsLibraryMappings.xml | 6 + .idea/misc.xml | 6 + .idea/modules.xml | 8 ++ .idea/node-bluez.iml | 12 ++ .idea/vcs.xml | 6 + .idea/workspace.xml | 249 ++++++++++++++++++++++++++++++++++++ lib/Bluez.js | 25 +++- package-lock.json | 2 +- 8 files changed, 312 insertions(+), 2 deletions(-) create mode 100644 .idea/jsLibraryMappings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/node-bluez.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..d23208f --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f47b24a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/node-bluez.iml b/.idea/node-bluez.iml new file mode 100644 index 0000000..24643cc --- /dev/null +++ b/.idea/node-bluez.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..5af0eb1 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,249 @@ + + + + + + + + + + + + + + + + + registerA + removeListener + on('signal + removeALl + removeEventListener + getMed + media_player + player + getMedia + object + this.adapter + this.userService + this.bus. + .on( + + + removeEventListener + removeListener + + + + + + + + + true + + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - 1558355609949 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 07c3eb2af8b54a0d960c7f601de89e0e6a681ffe Mon Sep 17 00:00:00 2001 From: tstenel Date: Tue, 28 May 2019 12:32:13 +0200 Subject: [PATCH 04/22] Delete vcs.xml --- .idea/vcs.xml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 2ca7063d3aca6c7b7fe6100da69f116730d6ed52 Mon Sep 17 00:00:00 2001 From: tstenel Date: Tue, 28 May 2019 12:32:14 +0200 Subject: [PATCH 05/22] Delete node-bluez.iml --- .idea/node-bluez.iml | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .idea/node-bluez.iml diff --git a/.idea/node-bluez.iml b/.idea/node-bluez.iml deleted file mode 100644 index 24643cc..0000000 --- a/.idea/node-bluez.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file From ef4aa97bc7899ae18c03ce92f87e4d05a295f588 Mon Sep 17 00:00:00 2001 From: tstenel Date: Tue, 28 May 2019 12:32:16 +0200 Subject: [PATCH 06/22] Delete modules.xml --- .idea/modules.xml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .idea/modules.xml diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index f47b24a..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file From ce85f12339fb87ad6160dd6217e6235499bd7963 Mon Sep 17 00:00:00 2001 From: tstenel Date: Tue, 28 May 2019 12:32:16 +0200 Subject: [PATCH 07/22] Delete misc.xml --- .idea/misc.xml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .idea/misc.xml diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 28a804d..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file From d79be6789801fc9743c5733a01ebcef78cdd4f2d Mon Sep 17 00:00:00 2001 From: tstenel Date: Tue, 28 May 2019 12:32:17 +0200 Subject: [PATCH 08/22] Delete jsLibraryMappings.xml --- .idea/jsLibraryMappings.xml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .idea/jsLibraryMappings.xml diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml deleted file mode 100644 index d23208f..0000000 --- a/.idea/jsLibraryMappings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From db2047b5c3eb9d1140142a86681c39acb8d6f6b2 Mon Sep 17 00:00:00 2001 From: tanguy stenel Date: Tue, 28 May 2019 12:43:57 +0200 Subject: [PATCH 09/22] read to try in the monimalz --- .idea/workspace.xml | 110 +++++++++++++++++++++++++++++++++--------- lib/Bluez.js | 3 ++ lib/Device.js | 33 ++++++------- lib/MediaControl.js | 32 ++++++------ lib/MediaPlayer.js | 30 ++++++------ lib/MediaTransport.js | 32 ++++++------ 6 files changed, 150 insertions(+), 90 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5af0eb1..c3dd025 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,7 +3,10 @@ - + + + + @@ -15,7 +18,44 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -33,6 +73,7 @@ this.userService this.bus. .on( + this._path removeEventListener @@ -45,11 +86,11 @@ @@ -132,15 +173,16 @@ - + - + @@ -197,51 +239,73 @@ + + + + + + + + + - + + + + + + + - + - + - - + + - + + + + + + + + - - + + - - + + - + - - + + - + - - + + diff --git a/lib/Bluez.js b/lib/Bluez.js index 5dc5602..1c5cd18 100644 --- a/lib/Bluez.js +++ b/lib/Bluez.js @@ -60,6 +60,9 @@ class Bluez extends EventEmitter { if (obj[key].removeAllListeners) { obj[key].removeAllListeners(); } + if (obj[key].destroy) { + obj[key].destroy(); + } }); }); this.objectManager.removeAllListeners(); diff --git a/lib/Device.js b/lib/Device.js index 2cd793e..edef65a 100644 --- a/lib/Device.js +++ b/lib/Device.js @@ -6,27 +6,26 @@ class Device extends EventEmitter { this._interface = _interface; this.services = {}; this._DBusObject = DbusObject; + this._DBusObject.on('signal', this.signalHandler.bind(this)); + + } + + destroy() { + this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); } - initEvents() - { - this._DBusObject.on('signal', (uniqueBusName, sender, objectPath, interfaceName, signalName, args) => { - - if(objectPath == this._interface.objectPath) - { - if(Array.isArray(args)) - { - if(args.length > 1 && args[0] == 'org.bluez.Device1') - { - Object.entries(args[1]).forEach(entry => { - let key = entry[0]; - let value = entry[1]; - this.emit("PropertyChanged", this._interface.objectPath, key, value); - }); - } + signalHandler(uniqueBusName, sender, objectPath, interfaceName, signalName, args) { + if (objectPath === this._interface.objectPath) { + if (Array.isArray(args)) { + if (args.length > 1 && args[0] === 'org.bluez.Device1') { + Object.entries(args[1]).forEach(entry => { + let key = entry[0]; + let value = entry[1]; + this.emit("PropertyChanged", this._interface.objectPath, key, value); + }); } } - }); + } } /* diff --git a/lib/MediaControl.js b/lib/MediaControl.js index 4a63fc6..25d3755 100644 --- a/lib/MediaControl.js +++ b/lib/MediaControl.js @@ -5,27 +5,25 @@ class MediaControl extends EventEmitter { super(); this._interface = _interface; this._DBusObject = DbusObject; + this._DBusObject.on('signal', this.signalHandler.bind(this)); } - initEvents() - { - this._DBusObject.on('signal', (uniqueBusName, sender, objectPath, interfaceName, signalName, args) => { - - if(objectPath == this._interface.objectPath) - { - if(Array.isArray(args)) - { - if(args.length > 1 && args[0] == 'org.bluez.MediaControl1') - { - Object.entries(args[1]).forEach(entry => { - let key = entry[0]; - let value = entry[1]; - this.emit("PropertyChanged", key, value); - }); - } + destroy() { + this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); + } + + signalHandler(uniqueBusName, sender, objectPath, interfaceName, signalName, args) { + if (objectPath === this._interface.objectPath) { + if (Array.isArray(args)) { + if (args.length > 1 && args[0] === 'org.bluez.MediaControl1') { + Object.entries(args[1]).forEach(entry => { + let key = entry[0]; + let value = entry[1]; + this.emit("PropertyChanged", this._interface.objectPath, key, value); + }); } } - }); + } } /****** Properties ******/ diff --git a/lib/MediaPlayer.js b/lib/MediaPlayer.js index d6bcd8c..00d0128 100644 --- a/lib/MediaPlayer.js +++ b/lib/MediaPlayer.js @@ -5,27 +5,25 @@ class MediaPlayer extends EventEmitter { super(); this._interface = _interface; this._DBusObject = DbusObject; + this._DBusObject.on('signal', this.signalHandler.bind(this)); } - initEvents() - { - this._DBusObject.on('signal', (uniqueBusName, sender, objectPath, interfaceName, signalName, args) => { + destroy() { + this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); + } - if(objectPath == this._interface.objectPath) - { - if(Array.isArray(args)) - { - if(args.length > 1 && args[0] == 'org.bluez.MediaPlayer1') - { - Object.entries(args[1]).forEach(entry => { - let key = entry[0]; - let value = entry[1]; - this.emit("PropertyChanged", key, value); - }); - } + signalHandler(uniqueBusName, sender, objectPath, interfaceName, signalName, args) { + if (objectPath === this._interface.objectPath) { + if (Array.isArray(args)) { + if (args.length > 1 && args[0] === 'org.bluez.MediaPlayer1') { + Object.entries(args[1]).forEach(entry => { + let key = entry[0]; + let value = entry[1]; + this.emit("PropertyChanged", this._interface.objectPath, key, value); + }); } } - }); + } } /****** Properties ******/ diff --git a/lib/MediaTransport.js b/lib/MediaTransport.js index 15d9e2a..0c7babb 100644 --- a/lib/MediaTransport.js +++ b/lib/MediaTransport.js @@ -5,27 +5,25 @@ class MediaTransport extends EventEmitter { super(); this._interface = _interface; this._DBusObject = DbusObject; + this._DBusObject.on('signal', this.signalHandler.bind(this)); } - initEvents() - { - this._DBusObject.on('signal', (uniqueBusName, sender, objectPath, interfaceName, signalName, args) => { - - if(objectPath == this._interface.objectPath) - { - if(Array.isArray(args)) - { - if(args.length > 1 && args[0] == 'org.bluez.MediaTransport1') - { - Object.entries(args[1]).forEach(entry => { - let key = entry[0]; - let value = entry[1]; - this.emit("PropertyChanged", key, value); - }); - } + destroy() { + this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); + } + + signalHandler(uniqueBusName, sender, objectPath, interfaceName, signalName, args) { + if (objectPath === this._interface.objectPath) { + if (Array.isArray(args)) { + if (args.length > 1 && args[0] === 'org.bluez.MediaTransport1') { + Object.entries(args[1]).forEach(entry => { + let key = entry[0]; + let value = entry[1]; + this.emit("PropertyChanged", key, value); + }); } } - }); + } } /****** Properties ******/ From 7fe2550549c2a6d89247813271cfbcb4fff4e2b2 Mon Sep 17 00:00:00 2001 From: tanguy stenel Date: Tue, 28 May 2019 15:40:18 +0200 Subject: [PATCH 10/22] what about now ? --- lib/Device.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Device.js b/lib/Device.js index edef65a..40a595f 100644 --- a/lib/Device.js +++ b/lib/Device.js @@ -6,8 +6,7 @@ class Device extends EventEmitter { this._interface = _interface; this.services = {}; this._DBusObject = DbusObject; - this._DBusObject.on('signal', this.signalHandler.bind(this)); - + this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); this._DBusObject.on('signal', this.signalHandler.bind(this)); } destroy() { @@ -450,4 +449,4 @@ class Device extends EventEmitter { } } -module.exports = Device; \ No newline at end of file +module.exports = Device; From 46e07b7bcee357186cca3b89b5a427fd3785eed7 Mon Sep 17 00:00:00 2001 From: tanguy stenel Date: Tue, 28 May 2019 16:45:52 +0200 Subject: [PATCH 11/22] what about now ? 2 : electric boogaloo --- lib/Device.js | 3 ++- lib/MediaControl.js | 1 + lib/MediaPlayer.js | 1 + lib/MediaTransport.js | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Device.js b/lib/Device.js index 40a595f..b49fcd8 100644 --- a/lib/Device.js +++ b/lib/Device.js @@ -6,7 +6,8 @@ class Device extends EventEmitter { this._interface = _interface; this.services = {}; this._DBusObject = DbusObject; - this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); this._DBusObject.on('signal', this.signalHandler.bind(this)); + this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); + this._DBusObject.on('signal', this.signalHandler.bind(this)); } destroy() { diff --git a/lib/MediaControl.js b/lib/MediaControl.js index 25d3755..e4788f2 100644 --- a/lib/MediaControl.js +++ b/lib/MediaControl.js @@ -5,6 +5,7 @@ class MediaControl extends EventEmitter { super(); this._interface = _interface; this._DBusObject = DbusObject; + this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); this._DBusObject.on('signal', this.signalHandler.bind(this)); } diff --git a/lib/MediaPlayer.js b/lib/MediaPlayer.js index 00d0128..a371f68 100644 --- a/lib/MediaPlayer.js +++ b/lib/MediaPlayer.js @@ -5,6 +5,7 @@ class MediaPlayer extends EventEmitter { super(); this._interface = _interface; this._DBusObject = DbusObject; + this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); this._DBusObject.on('signal', this.signalHandler.bind(this)); } diff --git a/lib/MediaTransport.js b/lib/MediaTransport.js index 0c7babb..e33c60f 100644 --- a/lib/MediaTransport.js +++ b/lib/MediaTransport.js @@ -5,6 +5,7 @@ class MediaTransport extends EventEmitter { super(); this._interface = _interface; this._DBusObject = DbusObject; + this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); this._DBusObject.on('signal', this.signalHandler.bind(this)); } From c354c920a03f40db894c5932925f705f82760a6f Mon Sep 17 00:00:00 2001 From: tanguy stenel Date: Wed, 29 May 2019 11:57:49 +0200 Subject: [PATCH 12/22] main event emitter is now Bluez --- lib/Bluez.js | 25 +++++++++++++++++++++++++ lib/Device.js | 24 +----------------------- lib/MediaControl.js | 24 +----------------------- lib/MediaPlayer.js | 24 +----------------------- lib/MediaTransport.js | 24 +----------------------- 5 files changed, 29 insertions(+), 92 deletions(-) diff --git a/lib/Bluez.js b/lib/Bluez.js index 1c5cd18..9aa8458 100644 --- a/lib/Bluez.js +++ b/lib/Bluez.js @@ -45,6 +45,31 @@ class Bluez extends EventEmitter { this.objectManager.GetManagedObjects((err, objs) => { Object.keys(objs).forEach((k) => this.onInterfacesAdded(k, objs[k])) }); + this.bus.on('signal', this.signalHandler); + } + + signalHandler(uniqueBusName, sender, objectPath, interfaceName, signalName, args) { + if (signalName === 'PropertiesChanged' && objectPath.includes('bluez')) { + if (Array.isArray(args) && args.length > 1) { + let event = null; + let [[key, value]] = Object.entries(args[1]); + let addr = objectPath.substr('/org/bluez/hci0/dev_'.length, 17); + switch (args[0]) { + case 'org.bluez.Device1': + this.emit('device_property', addr, key, value) + break; + case 'org.bluez.MediaPlayer1': + this.emit('player_property', addr, key, value) + break; + case 'org.bluez.MediaTransport1': + this.emit('transport_property', addr, key, value) + break; + case 'org.bluez.MediaControl1': + this.emit('control_property', addr, key, value) + break; + } + } + } } close() { diff --git a/lib/Device.js b/lib/Device.js index b49fcd8..a60faa5 100644 --- a/lib/Device.js +++ b/lib/Device.js @@ -1,31 +1,9 @@ -const EventEmitter = require('events').EventEmitter; - -class Device extends EventEmitter { +class Device { constructor(_interface, DbusObject) { super(); this._interface = _interface; this.services = {}; this._DBusObject = DbusObject; - this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); - this._DBusObject.on('signal', this.signalHandler.bind(this)); - } - - destroy() { - this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); - } - - signalHandler(uniqueBusName, sender, objectPath, interfaceName, signalName, args) { - if (objectPath === this._interface.objectPath) { - if (Array.isArray(args)) { - if (args.length > 1 && args[0] === 'org.bluez.Device1') { - Object.entries(args[1]).forEach(entry => { - let key = entry[0]; - let value = entry[1]; - this.emit("PropertyChanged", this._interface.objectPath, key, value); - }); - } - } - } } /* diff --git a/lib/MediaControl.js b/lib/MediaControl.js index e4788f2..2357324 100644 --- a/lib/MediaControl.js +++ b/lib/MediaControl.js @@ -1,30 +1,8 @@ -const EventEmitter = require('events').EventEmitter; - -class MediaControl extends EventEmitter { +class MediaControl { constructor(_interface, DbusObject) { super(); this._interface = _interface; this._DBusObject = DbusObject; - this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); - this._DBusObject.on('signal', this.signalHandler.bind(this)); - } - - destroy() { - this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); - } - - signalHandler(uniqueBusName, sender, objectPath, interfaceName, signalName, args) { - if (objectPath === this._interface.objectPath) { - if (Array.isArray(args)) { - if (args.length > 1 && args[0] === 'org.bluez.MediaControl1') { - Object.entries(args[1]).forEach(entry => { - let key = entry[0]; - let value = entry[1]; - this.emit("PropertyChanged", this._interface.objectPath, key, value); - }); - } - } - } } /****** Properties ******/ diff --git a/lib/MediaPlayer.js b/lib/MediaPlayer.js index a371f68..ad55372 100644 --- a/lib/MediaPlayer.js +++ b/lib/MediaPlayer.js @@ -1,30 +1,8 @@ -const EventEmitter = require('events').EventEmitter; - -class MediaPlayer extends EventEmitter { +class MediaPlayer { constructor(_interface, DbusObject) { super(); this._interface = _interface; this._DBusObject = DbusObject; - this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); - this._DBusObject.on('signal', this.signalHandler.bind(this)); - } - - destroy() { - this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); - } - - signalHandler(uniqueBusName, sender, objectPath, interfaceName, signalName, args) { - if (objectPath === this._interface.objectPath) { - if (Array.isArray(args)) { - if (args.length > 1 && args[0] === 'org.bluez.MediaPlayer1') { - Object.entries(args[1]).forEach(entry => { - let key = entry[0]; - let value = entry[1]; - this.emit("PropertyChanged", this._interface.objectPath, key, value); - }); - } - } - } } /****** Properties ******/ diff --git a/lib/MediaTransport.js b/lib/MediaTransport.js index e33c60f..3295450 100644 --- a/lib/MediaTransport.js +++ b/lib/MediaTransport.js @@ -1,30 +1,8 @@ -const EventEmitter = require('events').EventEmitter; - -class MediaTransport extends EventEmitter { +class MediaTransport { constructor(_interface, DbusObject) { super(); this._interface = _interface; this._DBusObject = DbusObject; - this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); - this._DBusObject.on('signal', this.signalHandler.bind(this)); - } - - destroy() { - this._DBusObject.removeListener('signal', this.signalHandler.bind(this)); - } - - signalHandler(uniqueBusName, sender, objectPath, interfaceName, signalName, args) { - if (objectPath === this._interface.objectPath) { - if (Array.isArray(args)) { - if (args.length > 1 && args[0] === 'org.bluez.MediaTransport1') { - Object.entries(args[1]).forEach(entry => { - let key = entry[0]; - let value = entry[1]; - this.emit("PropertyChanged", key, value); - }); - } - } - } } /****** Properties ******/ From bac79299b5bb38a2e3e0636a1813ef68b71afea5 Mon Sep 17 00:00:00 2001 From: tanguy stenel Date: Wed, 29 May 2019 12:01:38 +0200 Subject: [PATCH 13/22] small_fixes --- lib/Bluez.js | 2 +- lib/Device.js | 1 - lib/MediaControl.js | 1 - lib/MediaPlayer.js | 1 - lib/MediaTransport.js | 1 - 5 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Bluez.js b/lib/Bluez.js index 9aa8458..39b41a1 100644 --- a/lib/Bluez.js +++ b/lib/Bluez.js @@ -53,7 +53,7 @@ class Bluez extends EventEmitter { if (Array.isArray(args) && args.length > 1) { let event = null; let [[key, value]] = Object.entries(args[1]); - let addr = objectPath.substr('/org/bluez/hci0/dev_'.length, 17); + let addr = objectPath.substr('/org/bluez/hci0/dev_'.length, 17).replace(s/_/g, ':'); switch (args[0]) { case 'org.bluez.Device1': this.emit('device_property', addr, key, value) diff --git a/lib/Device.js b/lib/Device.js index a60faa5..a81490d 100644 --- a/lib/Device.js +++ b/lib/Device.js @@ -1,6 +1,5 @@ class Device { constructor(_interface, DbusObject) { - super(); this._interface = _interface; this.services = {}; this._DBusObject = DbusObject; diff --git a/lib/MediaControl.js b/lib/MediaControl.js index 2357324..20dafbc 100644 --- a/lib/MediaControl.js +++ b/lib/MediaControl.js @@ -1,6 +1,5 @@ class MediaControl { constructor(_interface, DbusObject) { - super(); this._interface = _interface; this._DBusObject = DbusObject; } diff --git a/lib/MediaPlayer.js b/lib/MediaPlayer.js index ad55372..7f829bf 100644 --- a/lib/MediaPlayer.js +++ b/lib/MediaPlayer.js @@ -1,6 +1,5 @@ class MediaPlayer { constructor(_interface, DbusObject) { - super(); this._interface = _interface; this._DBusObject = DbusObject; } diff --git a/lib/MediaTransport.js b/lib/MediaTransport.js index 3295450..f121e7a 100644 --- a/lib/MediaTransport.js +++ b/lib/MediaTransport.js @@ -1,6 +1,5 @@ class MediaTransport { constructor(_interface, DbusObject) { - super(); this._interface = _interface; this._DBusObject = DbusObject; } From 27c891212c8f1f54b55ac71c3048ef64e0c64c29 Mon Sep 17 00:00:00 2001 From: tanguy stenel Date: Wed, 29 May 2019 12:06:46 +0200 Subject: [PATCH 14/22] forgot to remove listener --- lib/Bluez.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Bluez.js b/lib/Bluez.js index 39b41a1..86a6389 100644 --- a/lib/Bluez.js +++ b/lib/Bluez.js @@ -97,6 +97,7 @@ class Bluez extends EventEmitter { this.userService.removeObject(this.userServiceObject); this.userServiceObject = undefined; } + this.bus.removeListener('signal', this.signalHandler); } async getAdapter(dev) { From 98b836200a09ffc2ec5c8ad293e24dd26b8f5f43 Mon Sep 17 00:00:00 2001 From: tanguy stenel Date: Wed, 29 May 2019 12:16:50 +0200 Subject: [PATCH 15/22] small fixw --- lib/Bluez.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Bluez.js b/lib/Bluez.js index 86a6389..6f3d470 100644 --- a/lib/Bluez.js +++ b/lib/Bluez.js @@ -53,7 +53,7 @@ class Bluez extends EventEmitter { if (Array.isArray(args) && args.length > 1) { let event = null; let [[key, value]] = Object.entries(args[1]); - let addr = objectPath.substr('/org/bluez/hci0/dev_'.length, 17).replace(s/_/g, ':'); + let addr = objectPath.substr('/org/bluez/hci0/dev_'.length, 17).replace(/_/g, ':'); switch (args[0]) { case 'org.bluez.Device1': this.emit('device_property', addr, key, value) @@ -453,4 +453,4 @@ class Bluez extends EventEmitter { } } -module.exports = Bluez; \ No newline at end of file +module.exports = Bluez; From 7433dd0c0433bd6137afe11f40572203d4686c28 Mon Sep 17 00:00:00 2001 From: tanguy stenel Date: Wed, 29 May 2019 12:31:43 +0200 Subject: [PATCH 16/22] last try before lunch --- lib/Bluez.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Bluez.js b/lib/Bluez.js index 6f3d470..8d45769 100644 --- a/lib/Bluez.js +++ b/lib/Bluez.js @@ -45,15 +45,15 @@ class Bluez extends EventEmitter { this.objectManager.GetManagedObjects((err, objs) => { Object.keys(objs).forEach((k) => this.onInterfacesAdded(k, objs[k])) }); - this.bus.on('signal', this.signalHandler); + this.bus.on('signal', this.signalHandler.bind(this)); } signalHandler(uniqueBusName, sender, objectPath, interfaceName, signalName, args) { if (signalName === 'PropertiesChanged' && objectPath.includes('bluez')) { if (Array.isArray(args) && args.length > 1) { - let event = null; let [[key, value]] = Object.entries(args[1]); let addr = objectPath.substr('/org/bluez/hci0/dev_'.length, 17).replace(/_/g, ':'); + console.log(args[0], addr, key, value); switch (args[0]) { case 'org.bluez.Device1': this.emit('device_property', addr, key, value) From 318f5ff73fb97501a5f5f1bf3016965ab8ea2697 Mon Sep 17 00:00:00 2001 From: tanguy stenel Date: Wed, 29 May 2019 12:33:47 +0200 Subject: [PATCH 17/22] log is useless now --- lib/Bluez.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Bluez.js b/lib/Bluez.js index 8d45769..e4f1f85 100644 --- a/lib/Bluez.js +++ b/lib/Bluez.js @@ -53,7 +53,6 @@ class Bluez extends EventEmitter { if (Array.isArray(args) && args.length > 1) { let [[key, value]] = Object.entries(args[1]); let addr = objectPath.substr('/org/bluez/hci0/dev_'.length, 17).replace(/_/g, ':'); - console.log(args[0], addr, key, value); switch (args[0]) { case 'org.bluez.Device1': this.emit('device_property', addr, key, value) From 04bae2f6e09a2ea792616b1907903e3452cf2702 Mon Sep 17 00:00:00 2001 From: tstenel Date: Wed, 29 May 2019 14:05:28 +0200 Subject: [PATCH 18/22] Update Bluez.js --- lib/Bluez.js | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/lib/Bluez.js b/lib/Bluez.js index e4f1f85..571b7a2 100644 --- a/lib/Bluez.js +++ b/lib/Bluez.js @@ -72,22 +72,13 @@ class Bluez extends EventEmitter { } close() { - let arr = [ - this.adapter, - this.devices, - this.mediacontrol, - this.mediaplayer, - this.mediatransport - ]; - arr.forEach((obj) => { - Object.keys(obj).forEach((key) => { - if (obj[key].removeAllListeners) { - obj[key].removeAllListeners(); - } - if (obj[key].destroy) { - obj[key].destroy(); - } - }); + Object.keys(this.adapter).forEach((key) => { + if (obj[key].removeAllListeners) { + obj[key].removeAllListeners(); + } + if (obj[key].destroy) { + obj[key].destroy(); + } }); this.objectManager.removeAllListeners(); this.profileManager.removeAllListeners(); From beb5bd02fc3540f9311f39d60dd0251e98957ef6 Mon Sep 17 00:00:00 2001 From: tstenel Date: Wed, 29 May 2019 14:50:00 +0200 Subject: [PATCH 19/22] Update Bluez.js --- lib/Bluez.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Bluez.js b/lib/Bluez.js index 571b7a2..a7c9821 100644 --- a/lib/Bluez.js +++ b/lib/Bluez.js @@ -73,11 +73,11 @@ class Bluez extends EventEmitter { close() { Object.keys(this.adapter).forEach((key) => { - if (obj[key].removeAllListeners) { - obj[key].removeAllListeners(); + if (this.adapter[key].removeAllListeners) { + this.adapter[key].removeAllListeners(); } - if (obj[key].destroy) { - obj[key].destroy(); + if (this.adapter[key].destroy) { + this.adapter[key].destroy(); } }); this.objectManager.removeAllListeners(); From 62abd5a323986f1fd7b77eaf7760c82d9309f97b Mon Sep 17 00:00:00 2001 From: tanguy stenel Date: Wed, 29 May 2019 15:08:09 +0200 Subject: [PATCH 20/22] didn't correctly remove listener --- lib/Bluez.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Bluez.js b/lib/Bluez.js index e4f1f85..88350c9 100644 --- a/lib/Bluez.js +++ b/lib/Bluez.js @@ -96,7 +96,7 @@ class Bluez extends EventEmitter { this.userService.removeObject(this.userServiceObject); this.userServiceObject = undefined; } - this.bus.removeListener('signal', this.signalHandler); + this.bus.removeAllListeners('signal'); } async getAdapter(dev) { From 1e4a330678599e404281659580843a585808c5fc Mon Sep 17 00:00:00 2001 From: tanguy stenel Date: Wed, 29 May 2019 15:14:30 +0200 Subject: [PATCH 21/22] conflicts --- lib/Bluez.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Bluez.js b/lib/Bluez.js index 88350c9..dec5505 100644 --- a/lib/Bluez.js +++ b/lib/Bluez.js @@ -89,6 +89,8 @@ class Bluez extends EventEmitter { } }); }); + this.objectManager.removeAllListeners('InterfacesAdded'); + this.objectManager.removeAllListeners('InterfacesRemoved'); this.objectManager.removeAllListeners(); this.profileManager.removeAllListeners(); this.agentManager.removeAllListeners(); From 6861f7ddc1fbbe459b1bfe51839d707ab84a7e7f Mon Sep 17 00:00:00 2001 From: tanguy stenel Date: Wed, 29 May 2019 15:41:38 +0200 Subject: [PATCH 22/22] forgot some ';' --- lib/Bluez.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Bluez.js b/lib/Bluez.js index 848d428..ff46cc5 100644 --- a/lib/Bluez.js +++ b/lib/Bluez.js @@ -55,16 +55,16 @@ class Bluez extends EventEmitter { let addr = objectPath.substr('/org/bluez/hci0/dev_'.length, 17).replace(/_/g, ':'); switch (args[0]) { case 'org.bluez.Device1': - this.emit('device_property', addr, key, value) + this.emit('device_property', addr, key, value); break; case 'org.bluez.MediaPlayer1': - this.emit('player_property', addr, key, value) + this.emit('player_property', addr, key, value); break; case 'org.bluez.MediaTransport1': - this.emit('transport_property', addr, key, value) + this.emit('transport_property', addr, key, value); break; case 'org.bluez.MediaControl1': - this.emit('control_property', addr, key, value) + this.emit('control_property', addr, key, value); break; } }