-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathsennheiser-lib.js
72 lines (59 loc) · 1.68 KB
/
sennheiser-lib.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* HTTP API Driver for Sennheiser ceiling mic
*
* Remember to enable third party api access and set username / password in the Sennheiser TCCM app
* Usage:
*
* import Sennheiser from './sennheiser-lib'
*
* const mic = new Sennheiser('10.192.12.35', 'admin', 'mypassword')
*
* mic.setLed(on)
* .catch(e => console.warn(e))
*
* mic.setBrightness(55)
* .catch(e => console.warn(e))
*/
import xapi from 'xapi'
const LED_API_PATH = '/api/device/leds/ring'
function http(url, username, password, body) {
const token = btoa(`${username}:${password}`)
const auth = `Authorization: Basic ${token}`
const type = 'Content-Type: application/json'
const options = {
AllowInsecureHTTPS: true,
Url: url,
Header: [type, auth],
ResultBody: 'PlainText'
}
if (!body) {
return xapi.Command.HttpClient.Get(options)
}
return xapi.Command.HttpClient.Put(options, JSON.stringify(body))
}
class Driver {
constructor(ip, username, password) {
this.ip = ip
this.username = username
this.password = password
}
setLed(muted) {
const url = 'https://' + this.ip + LED_API_PATH
const body = { micOn: { color: muted ? 'Red' : 'Green' } }
return http(url, this.username, this.password, body)
}
getStatus() {
const url = 'https://' + this.ip + LED_API_PATH
return http(url, this.username, this.password)
}
setBrightness(brightness) {
const bri = Number(brightness)
if (bri < 0 || bri > 5) {
throw new Error('Brightness should be btw 0 and 5')
}
const url = 'https://' + this.ip + LED_API_PATH
const body = { brightness: bri }
return http(url, this.username, this.password, body)
}
}
export default Driver