« get me outta code hell

basic working backend save/restore & socket server - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/index.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2020-07-10 11:28:34 -0300
committerFlorrie <towerofnix@gmail.com>2020-07-10 11:28:34 -0300
commit503a37ba4d7550f9c2ed1602e589a0142a20d10d (patch)
treebadb7a7638672c14ddea4f4c28a6c232f1c4a0f4 /index.js
parentc625099a05f4e4dd8b998a9469f016d649982b50 (diff)
basic working backend save/restore & socket server
Backend save/restore code (living in serialized-backend.js) has been
well tested and shouldn't need much change going forward. Now we get to
begin working on the actual synchronized-over-socket-server commands!
Diffstat (limited to 'index.js')
-rwxr-xr-xindex.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/index.js b/index.js
index 444d579..b0db6cd 100755
--- a/index.js
+++ b/index.js
@@ -12,6 +12,13 @@ const processSmartPlaylist = require('./smart-playlist')
 const setupClient = require('./client')
 
 const {
+  makeSocketServer,
+  makeSocketClient,
+  attachBackendToSocketClient,
+  attachSocketServerToBackend
+} = require('./socket')
+
+const {
   getItemPathString,
   updatePlaylistFormat
 } = require('./playlist-utils')
@@ -67,6 +74,8 @@ async function main() {
     },
     'player-options': {type: 'series'},
     'stress-test': {type: 'flag'},
+    'socket-client': {type: 'value'},
+    'socket-server': {type: 'flag'},
     'telnet-server': {type: 'flag'},
     [parseOptions.handleDashless](option) {
       playlistSources.push(option)
@@ -138,6 +147,22 @@ async function main() {
     appElement.attachAsServerHost(telnetServer)
   }
 
+  let socketServer
+  if (options['socket-server']) {
+    socketServer = makeSocketServer()
+    attachSocketServerToBackend(socketServer, backend)
+    socketServer.listen(1255)
+  }
+
+  let socketClient
+  if (options['socket-client']) {
+    socketClient = makeSocketClient()
+    attachBackendToSocketClient(backend, socketClient, {
+      getPlaylistSources: () => appElement.playlistSources
+    })
+    socketClient.socket.connect(1255)
+  }
+
   if (options['stress-test']) {
     await loadPlaylistPromise