1.0.0 • Published 5 years ago

virtual-sockets v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

VirtualSockets 1.0.0

by Blaineworld

Make your users write the networking code for you.


News

VirtualSockets is technically ready for use! This is really still a beta, so I might make some incompatible changes that I see as improving the library, and if you find any bugs or have any suggestions, please let me know! Actually, if you're using this package please let me know. I've never had anyone try my stuff before.

Quick Docs

class VirtualServer extends EventEmitter
  new VirtualServer([formatter: string | function])

  VirtualServer.Socket: VirtualSocket constructor

  VirtualServer.version: string
   The version number of the library.

  VirtualServer.formatters() => array
   Get a list of valid formatter names.

  EVENT connection (socket: object VirtualSocket)
    Fires when a new connection is established.

  object VirtualServer
    format: string
     The ID of the message formatter, or "Custom" if it's
     a custom formatter function.

    formatter: null | function
     The custom message formatter, or null if this server
     uses one of the built-in message formatters.

    connections() => array
     Gets a list of all current connections to this server.

    connect() => object VirtualSocket
     Creates a new connection to this server.

    sendAll(messages ...) chainable
     Sends identical messages on all sockets.

class VirtualSocket extends EventEmitter
  new VirtualSocket(server: object VirtualServer)

  VirtualSocket.Server: VirtualServer constructor

  VirtualSocket.version: string
   The version number of the library.

  EVENT disconnect
    Fires when the socket disconnects. Unlike 'error', this
    event CAN fire for network errors, if applicable.

  EVENT error (error: *)
    Fires when an error is thrown during message transfer;
	this event is NOT for network errors!

  EVENT message (message: *)
    Fires when a message is received. The type of the
    message depends on what the server's formatter returns.

  object VirtualSocket
    format: string
     Always the same as the server's format property.

    formatter: null | function (read-only)
     Always the same as the server's formatter property.

    sender: function
     The function used by this socket to send messages.

    server: object VirtualServer (read-only)
     The server that has this connection.

    close() chainable
     Closes the connection. This socket's pipe and send
     methods will still work, but won't do anything.

    pipe(messages ...) chainable
     Receives a message on this socket.

    send(messages ...) chainable
     Sends a message on this socket.