11const _ = require ( "lodash" ) ;
2- const { discoveries} = require ( "./discovery" ) ;
32const { getPlaylistFromDB, addPatternToPlaylist, removeAllPatterns} = require ( "../db/controllers/playlist" ) ;
4-
3+ const { discoverPixelBlazes , sendCommand } = require ( "./pixelBlazeUtils" ) ;
54let currentPlaylistData = [ ]
65let currentPlaylist = [ ]
76let initInterval
@@ -27,13 +26,7 @@ init = async () => {
2726 pixelBlazeData = discoverPixelBlazes ( )
2827 pixelBlazeIds = _ . map ( pixelBlazeData , 'id' )
2928}
30- discoverPixelBlazes = ( ) => {
31- return _ . map ( discoveries , function ( v , k ) {
32- let res = _ . pick ( v , [ 'lastSeen' , 'address' ] ) ;
33- _ . assign ( res , v . controller . props ) ;
34- return res ;
35- } )
36- }
29+
3730initInterval = setInterval ( init , 100 )
3831
3932class Playlist {
@@ -48,7 +41,6 @@ class Playlist {
4841 await new Promise ( resolve => {
4942 this . playlistLoopTimeout = setTimeout ( resolve , 100 )
5043 } ) ;
51- console . log ( { currentPlaylist} )
5244 if ( pixelBlazeIds . length ) {
5345 await this . iterateOnPlaylist ( )
5446 }
@@ -126,23 +118,13 @@ class Playlist {
126118 }
127119 sendPattern = ( pattern ) => {
128120 const name = pattern . name
129- _ . each ( pixelBlazeIds , async id => {
130- id = String ( id ) ;
131- let controller = discoveries [ id ] && discoveries [ id ] . controller ;
132- if ( controller ) {
133- const command = {
134- programName : pattern . name
135- }
136- await controller . setCommand ( command ) ;
137- }
138- } )
121+ sendCommand ( pixelBlazeIds , name )
139122 // skipping this if utils is not initialized due to no websocket connections
123+ let message = {
124+ currentRunningPattern : name ,
125+ currentPlaylist : currentPlaylist
126+ }
140127 if ( this . utils ) {
141- let message = {
142- currentRunningPattern : name ,
143- currentPlaylist : currentPlaylist
144- }
145- console . log ( message )
146128 this . utils . broadcastMessage ( message )
147129 }
148130 }
0 commit comments