Skip to content

Commit

Permalink
additional variables
Browse files Browse the repository at this point in the history
  • Loading branch information
daniep01 committed Aug 17, 2022
1 parent 87215a8 commit 97cd3f5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
3 changes: 3 additions & 0 deletions HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ Add help text

## Version 1.0.6
Add streaming control 'Toggle' option

Added variables for stream duration, bitrate and cache level

45 changes: 42 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,23 @@ instance.prototype.deviceInformation = function (key, data) {
}

if (key == 'STREAM STATE') {
// self.log('debug','data = ' + data);
console.log('stream state = ' + data);

if (data['Status'] !== undefined) {

self.streaming = data['Status']
self.setVariable('stream_state', self.streaming)
self.checkFeedbacks('streaming_state')

self.duration = data['Duration']
self.setVariable('stream_duration', self.duration)

self.bitrate = data['Bitrate']
self.setVariable('stream_bitrate', self.bitrate)

self.cache = data['Cache Used']
self.setVariable('cache', self.cache)

self.has_data = true
}
}
Expand All @@ -155,13 +166,27 @@ instance.prototype.init = function () {

debug = self.debug
log = self.log

self.timer = undefined
self.init_tcp()

self.update_variables() // export variables
self.init_presets()
}

instance.prototype.dataPoller = function () {
const self = this

if (self.socket === undefined) {
return
}

if (self.socket.connected) {
self.socket.send('STREAM STATE:\n\n')
} else {
debug('Socket not connected')
}
}

instance.prototype.init_tcp = function () {
var self = this
var receivebuffer = ''
Expand All @@ -187,6 +212,8 @@ instance.prototype.init_tcp = function () {

self.socket.on('connect', function () {
debug('Connected')
// poll every second
self.timer = setInterval(self.dataPoller.bind(self), 1000)
})

// separate buffered stream into lines with responses
Expand Down Expand Up @@ -312,6 +339,18 @@ instance.prototype.update_variables = function (system) {
{
label: 'Streaming State',
name: 'stream_state',
},
{
label: 'Streaming Duration',
name: 'stream_duration',
},
{
label: 'Stream Bitrate',
name: 'stream_bitrate',
},
{
label: 'Cache Used',
name: 'cache',
}
)

Expand Down Expand Up @@ -507,7 +546,7 @@ instance.prototype.action = function (action) {

if (action.action === 'stream') {
if (action.options.stream_control === 'Toggle') {
if (self.streaming === 'Streaming') {
if (self.streaming === 'Streaming' || self.streaming === 'Connecting') {
cmd = 'STREAM STATE:\nAction: Stop\n\n'
} else {
cmd = 'STREAM STATE:\nAction: Start\n\n'
Expand Down

0 comments on commit 97cd3f5

Please sign in to comment.