« get me outta code hell

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:
Diffstat (limited to 'index.js')
-rwxr-xr-xindex.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/index.js b/index.js
index 444d579..d628a20 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,9 @@ async function main() {
     },
     'player-options': {type: 'series'},
     'stress-test': {type: 'flag'},
+    'socket-client': {type: 'value'},
+    'socket-name': {type: 'value'},
+    'socket-server': {type: 'value'},
     'telnet-server': {type: 'flag'},
     [parseOptions.handleDashless](option) {
       playlistSources.push(option)
@@ -138,6 +148,37 @@ async function main() {
     appElement.attachAsServerHost(telnetServer)
   }
 
+  let socketClient
+  let socketServer
+  if (options['socket-server']) {
+    socketServer = makeSocketServer()
+    attachSocketServerToBackend(socketServer, backend)
+    socketServer.listen(options['socket-server'])
+
+    socketClient = makeSocketClient()
+    socketClient.socket.connect(options['socket-server'])
+  }
+
+  if (options['socket-client']) {
+    socketClient = makeSocketClient()
+    const [ p1, p2 ] = options['socket-client'].split(':')
+    const host = p2 && p1
+    const port = p2 ? p2 : p1
+    socketClient.socket.connect(port, host)
+  }
+
+  if (socketClient) {
+    attachBackendToSocketClient(backend, socketClient, {
+      getPlaylistSources: () => appElement.playlistSources
+    })
+
+    let nickname = process.env.USER
+    if (options['socket-name']) {
+      nickname = options['socket-name']
+    }
+    socketClient.setNickname(nickname)
+  }
+
   if (options['stress-test']) {
     await loadPlaylistPromise