MusicDB Websocket Server

This is the main module to run the MusicDB Server.

To start and run the server, the following sequence of function calls is necessary:

Initialize(mdbconfig, musicdatabase)
StartWebSocketServer()
Run()

This module maintain global instances of the following classes. Those objects can be used inside the thread the server runs. Usually the main thread. Using these objects saves a lot of memory. If the server is not started, the objects are all None.

musicdb.mdbapi.server.Initialize(configobj, databaseobj)[source]

This function initializes the whole server. It initializes lots of global objects that get shared between multiple connections.

The following things happen when this method gets called:

  1. Assign the configobj and databaseobj to global variables cfg and database to share them between multiple connections

  2. Seed Python’s random number generator

  3. Instantiate a global musicdb.mdbapi.mise.MusicDBMicroSearchEngine() object

  4. Starting the upload, integration and import management via musicdb.taskmanagement.managementthread.StartTaskManagementThread()

  5. Start the Audio Streaming Thread via musicdb.mdbapi.audiostream.StartAudioStreamingThread() (see Audio Streaming Server for details)

  6. Start the Video Streaming Thread via musicdb.mdbapi.videostream.StartVideoStreamingThread() (see Audio Streaming Server for details)

  7. Update MiSE cache via musicdb.mdbapi.mise.MusicDBMicroSearchEngine.UpdateCache()

Parameters
  • configobjMusicDBConfig that gets shared between connections

  • databaseobjMusicDatabase that gets shared between connections

Returns

None

Raises
  • TypeError – When configobj is not of type MusicDBConfig

  • TypeError – When databaseobj is not of type MusicDatabase

musicdb.mdbapi.server.Run()[source]

This is the servers main loop.

Inside the loop all MusicDB Websocket Server events get handled by calling musicdb.lib.ws.server.MusicDBWebSocketServer.HandleEvents(). When a shutdown gets triggered the Shutdown() function gets called and the server stops.

The Shutdown() gets also called the user presses Ctrl-C This leads to a regular shutdown.

In as an exception occurs the Shutdown() gets called, too. In this case the exit-code will be 1.

musicdb.mdbapi.server.SIGTERM_Handler()[source]

This function is the handler for the system signal TERM. It signals the server to shut down.

musicdb.mdbapi.server.Shutdown()[source]

This function stops the server and all its dependent threads.

The following things happen when this function gets called:

  1. Stopping task management via musicdb.taskmanagement.managementthread.StopTaskManagementThread()

  2. Stop the Audio Streaming Thread via musicdb.mdbapi.audiostream.StopAudioStreamingThread()

  3. Stop the Video Streaming Thread via musicdb.mdbapi.videostream.StopVideoStreamingThread()

  4. Stop the websocket server

At the end, the program gets terminated. So, this function gets never left.

The exit code will be 0 if this was a regular shutdown. If the shutdown got forced, for example due to a critical error, the exit code is 1.

This function should also be called when Initialize() fails or when it raises an exception.

musicdb.mdbapi.server.SignalHandler(signum, stack)[source]

This is the general signal handle for the MusicDB Server. This function reacts on system signals and calls the handler of a specific signal.

Parameters
  • signum – signal number

  • stack – current stack frame

Returns: Nothing

musicdb.mdbapi.server.StartWebSocketServer()[source]

This function creates and starts the actual MusicDB Websocket Server.

Returns

True on success, otherwise False

musicdb.mdbapi.server.UpdateCaches()[source]

This function handles the signal to refresh the server cache. Its task is to trigger updating the servers cache and to inform the clients to update.

On server side:

To inform the clients a broadcast packet get sent with the following content: {method:"broadcast", fncname:"sys:refresh", fncsig:"UpdateCaches", arguments:null, pass:null}

Example

if(fnc == "sys:refresh" && sig == "UpdateCaches") {
    MusicDB_Request("GetTags", "UpdateTagsCache");                  // Update tag cache
    MusicDB_Request("GetFilteredArtistsWithAlbums", "ShowArtists"); // Update artist view
}