2.6 KiB

@xviz/server

The @xviz/server module provides a framework for serving XVIZ data over a Websocket.

The XVIZServer will delegate a request to the array of XVIZHandlers that have been passed into when it is constructed. The XVIZHandlers will attempt to handle the request and if it can will return an instance of an XVIZSession. The rest of the client communication is then handled by the XVIZSession, specifically the XVIZ Protocol.

@xviz/server diagram

Diagram of the @xviz/server class relationships and data flow

Usage

To use the XVIZServer we provide a command-line tool xvizserver. This tool provides the ability to host XVIZ data from multiple directories at once.

Extending the XVIZServer

The design of the XVIZServer and XVIZHandler allow anyone to connect customized Handlers for their use-case in a simple manner following the existing implementation of the handler as a guide.

Module Classes

XVIZServer

The XVIZServer is the main class that will start listening for connection and delegate to the XVIZHandlers registered.

XVIZHandler Interface

An XVIZHandler serves the single role to determine if a connection can be handled and if so return an XVIZSession to manage that request.

XVIZSession Interface

XVIZSession has the role to respond to websocket events and route the messages through the XVIZServerMiddlewareStack

XVIZServerMiddlewareStack

The XVIZServerMiddlewareStack provides the structure for the middleware components and manages the routing of messages through the registered components.

Middleware components

The middleware components are objects that will only define methods for the XVIZ messages they need to act upon. The interface for these methods is derived from the XVIZServerMiddlewareStack.

These components could operate on the messages and response, store session state in a shared context, and make calls to the middleware stack in response to an event.