Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • IMageCore

Index

Properties

State

State: object

State class

The state library exposes a constructor that constructs objects which form an interface between an actor, a session and the archivist. Virtually any command that involves reading and modification of data should be managed by a state object.

When you’re done using the state class, always make sure to clean it up by calling close() on it. MAGE’s module and command center systems that bridge the communication between client and server use the State object for API responses and server-sent events.

type

{{ new(): mage.core.IState }}

Type declaration

archivist

archivist: object

Archivist core module

This module can be used to access things such as topic configuration and vault backends.

Type declaration

  • assertTopicAbilities: function
    • assertTopicAbilities(topicName: string, index?: string[], requiredOperations?: string[], isIndexPartial?: boolean): any
    • Used to confirm the abilities of the topic on this configured system

      Not all vaults can implement the full spectrum of internals required by the higher level APIs; this method allows developers to verify whether a given vault backend support the functionalities it needs.

      Parameters

      • topicName: string
      • Optional index: string[]
      • Optional requiredOperations: string[]
      • Optional isIndexPartial: boolean

      Returns any

  • closeVaults: function
    • closeVaults(): any
    • Close all vaults instances

      Returns any

  • getPersistentVaults: function
    • getPersistentVaults(): object
    • Retrieve an object containing all the existing vault backend instances

      Returns object

      • [vaultName: string]: any
  • getTopicApi: function
    • getTopicApi(topicName: string, vaultName: string): ITopicApi | null
  • getTopics: function
    • getTopics(): object
    • Retrieve a map of all existing topics

      Returns object

  • migrateToVersion: function
    • migrateToVersion(targetVersion: string, callback: function): any
    • Migrate all current vaults to a given version

      This will look at the list of available migration scripts and execute them if needed.

      Parameters

      • targetVersion: string
      • callback: function
          • (error: Error | null): void
          • Parameters

            • error: Error | null

            Returns void

      Returns any

  • topicExists: function
    • topicExists(topicName: string): boolean
    • Check if a topic is defined

      Parameters

      • topicName: string

      Returns boolean

config

config: Config

Configuration core module

httpServer

httpServer: object

HTTP Server

This API can be used to add your own custom routes if needed, as well as to serve files. This can be useful during the development of an HTML5 game.

Type declaration

  • addRoute: function
    • addRoute(pathMatch: string | RegExp, handlerFunction: function, type: "simple" | "callback" | "websocket" | "proxy"): void
    • Register a route (a string or a regular expression) on the HTTP server

      Incoming requests will be expected to be handled by the handler function you pass. Based on the type you specify, your handler function will receive different arguments.

      "simple": handler(req, res, path, query, urlInfo)

      • req: the IncomingMessage object.
      • res: the ServerResponse object.
      • path: the path part of the URL.
      • query: the parsed query string.
      • urlInfo: all information that came out of url.parse().

      "callback": handler(req, path, query, callback)

      • req: the IncomingMessage object.
      • path: the path part of the URL.
      • query: the parsed query string.
      • callback: call this when you've constructed your HTTP response.

      The callback accepts the following arguments in order:

      • httpCode: the HTTP status code you want to return.
      • out: a string or buffer that you want to send to the client.
      • headers: an object with headers.

      "websocket": handler(client, urlInfo)

      • client: a WebSocket client connection object. See the ws documentation.
      • urlInfo: all information that came out of url.parse().

      "proxy": endpoint handler(req, urlInfo)

      • req: the IncomingMessage object.
      • urlInfo: all information that came out of url.parse().

      Your handler function must return an endpoint object to connect to. For syntax, please read the net.createConnection() documentation.

      Parameters

      • pathMatch: string | RegExp
      • handlerFunction: function
          • (...args: any[]): any
          • Parameters

            • Rest ...args: any[]

            Returns any

      • type: "simple" | "callback" | "websocket" | "proxy"

      Returns void

  • delRoute: function
    • delRoute(pathMatch: string | RegExp): void
    • Removes the handler function registered on the given route.

      Parameters

      • pathMatch: string | RegExp

      Returns void

  • serveFile: function
    • serveFile(route: string | RegExp, filePath: string, onFinish?: function): void
    • Registers a route to lead directly to a file on disk

      If you want to be notified when a request finishes, you may pass an onFinish function. It may receive an error as its first argument.

      If you decide to pass this function, logging the error will be your responsibility.

      Parameters

      • route: string | RegExp
      • filePath: string
      • Optional onFinish: function
          • (error?: Error): void
          • Parameters

            • Optional error: Error

            Returns void

      Returns void

  • serveFolder: function
    • serveFolder(route: string | RegExp, folderPath: string, defaultFile?: string, onFinish?: function): void
    • Registers a route to lead directly to a folder on disk

      If you want to be notified when a request finishes, you may pass an onFinish function. It may receive an error as its first argument. If you decide to pass this function, logging the error will be your responsibility.

      Example:

      mage.core.httpServer.serveFolder('/source', './lib');
      

      If you provide a defaultFile file name argument, serving up a folder by its name will serve up a default file if it exists.

      Example:

      mage.core.httpServer.serveFolder('/source', './lib', 'index.html');
      

      Parameters

      • route: string | RegExp
      • folderPath: string
      • Optional defaultFile: string
      • Optional onFinish: function
          • (error?: Error): void
          • Parameters

            • Optional error: Error

            Returns void

      Returns void

  • setFavicon: function
    • setFavicon(buffer: Buffer, mimetype?: string): void
    • Registers a route "/favicon.ico" and serves the given buffer as content

      The mime type defaults to image/x-icon and may be overridden.

      Parameters

      • buffer: Buffer
      • Optional mimetype: string

      Returns void

logger

logger: Logger

The core logger is the logger instance used internally by MAGE to log different events; for your application, you should most likely use mage.logger instead

msgServer

msgServer: object

Message Server

The message server is used for state propagation across multiple MAGE servers in a cluster; it can also be used directly by MAGE developer to transfer data across servers.

memberof

Mage

Type declaration

  • mmrp: object

    Message Server

  • broadcast: function
    • Broadcast a message to all connected Message Server instance

      Parameters

      Returns void

  • close: function
    • close(): void
    • Close the network connection for this Message Server

      Returns void

  • confirm: function
    • confirm(address: string, clusterId: string, msgIds: string[]): void
    • Send a confirmation message

      Parameters

      • address: string
      • clusterId: string
      • msgIds: string[]

      Returns void

  • connect: function
    • connect(address: string, clusterId: string, disconnects?: "never" | "always" | "ondelivery"): void
    • Mark a given address as connected

      Parameters

      • address: string
      • clusterId: string
      • Optional disconnects: "never" | "always" | "ondelivery"

      Returns void

  • disconnect: function
    • disconnect(address: string, clusterId: string): void
    • Mark a given address as disconnected

      Parameters

      • address: string
      • clusterId: string

      Returns void

  • getClusterId: function
    • getClusterId(): string
    • Retrieve the unique cluster identifier

      Returns string

  • getMmrpNode: function
    • Retrieve the underlying MMRP Node instance used by this Message Server instance.

      Returns MmrpNode

  • getPublicConfig: function
    • getPublicConfig(): any
    • Retrieve the configuration used by this Message Server instance

      Returns any

  • isEnabled: function
    • isEnabled(): boolean
  • send: function
    • send(address: string, clusterId: string, message: MmrpEnvelope): void
    • Send a message to a remote Message Server instance

      Parameters

      Returns void

sampler

sampler: object

Sampler core module

Used for keeping tracks of local server metrics. This is useful for when you wish to expose some information about your server in production (for Zabbix, Nagios, Grafana, etc).

See https://mage.github.io/mage/#metrics for more details.

Type declaration

  • inc: function
    • inc(path: string[], id: string, increment: number): void
    • Increment a given metric

      Parameters

      • path: string[]
      • id: string
      • increment: number

      Returns void

  • sample: function
    • sample(path: string[], id: string, value: number): void
  • set: function
    • set(path: string[], id: string, value: number): void
    • Set the value of a given metric

      Parameters

      • path: string[]
      • id: string
      • value: number

      Returns void

  • timedSample: function
    • timedSample(path: string[], id: string, delta: number): void

serviceDiscovery

serviceDiscovery: object

The Service Discovery library is a library that allows you to announce and discover services on the local network, through different types of engines.

To use service discovery, configuration is mandatory; See https://mage.github.io/mage/#service-discovery to learn how to configure service discovery.

memberof

Mage

Type declaration

  • createService: function
    • createService(name: string, type: "tcp" | "udp"): IService
    • Create a service instance

      Service instances can be used to announce services as well as listen for service instance appearing and disappearing.

      Parameters

      • name: string
      • type: "tcp" | "udp"

      Returns IService