|
| 1 | +class BluetoothPluginController { |
| 2 | + constructor($scope, socketService, mockService, $log, $translate, $interval) { |
| 3 | + 'ngInject'; |
| 4 | + this.socketService = socketService; |
| 5 | + this.$scope = $scope; |
| 6 | + this.$log = $log; |
| 7 | + this.$translate = $translate; |
| 8 | + this.$interval = $interval; |
| 9 | + this.init(); |
| 10 | + } |
| 11 | + |
| 12 | + init() { |
| 13 | + this.registerListner(); |
| 14 | + this.initService(); |
| 15 | + } |
| 16 | + |
| 17 | + startScan() { |
| 18 | + this.socketService.emit('callMethod', { |
| 19 | + "endpoint" : "audio_interface/bluetooth_controller", |
| 20 | + "method" : "startScan", |
| 21 | + "data" : {} |
| 22 | + }); |
| 23 | + } |
| 24 | + |
| 25 | + refreshBluetoothDevices() { |
| 26 | + this.socketService.emit('callMethod', { |
| 27 | + "endpoint" : "audio_interface/bluetooth_controller", |
| 28 | + "method" : "getBluetoothDevices", |
| 29 | + "data" : {} |
| 30 | + }); |
| 31 | + } |
| 32 | + |
| 33 | + registerListner() { |
| 34 | + this.socketService.on('pushBluetoothDevices', (data) => { |
| 35 | + this.$log.debug('pushBluetoothDevices', data); |
| 36 | + this.bluetooth = data; |
| 37 | + }); |
| 38 | + this.$scope.$on('$destroy', () => { |
| 39 | + this.socketService.off('pushBluetoothDevices'); |
| 40 | + }); |
| 41 | + } |
| 42 | + |
| 43 | + initService() { |
| 44 | + this.startScan(); |
| 45 | + this.$interval( () => { this.refreshBluetoothDevices(); }, 5000); |
| 46 | + } |
| 47 | + |
| 48 | + connectDevice(mac) { |
| 49 | + this.socketService.emit("callMethod", { |
| 50 | + "endpoint" : "audio_interface/bluetooth_controller", |
| 51 | + "method" : "connectBluetoothDevice", |
| 52 | + "data" : {mac} |
| 53 | + }); |
| 54 | + } |
| 55 | + |
| 56 | + disconnectDevice(mac) { |
| 57 | + this.socketService.emit("callMethod", { |
| 58 | + "endpoint" : "audio_interface/bluetooth_controller", |
| 59 | + "method" : "disconnectBluetoothDevice", |
| 60 | + "data" : {mac} |
| 61 | + }); |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +export default BluetoothPluginController; |
0 commit comments