@bunchtogether/braid-server

undefined

Braid Server

WebSocket-based key-value synchronization.

See also:

API

Table of Contents

Server

Extends EventEmitter

Class representing a Braid Server

Parameters

  • uwsServer UWSTemplatedApp uWebSockets.js server
  • websocketPattern UWSRecognizedString uWebSockets.js websocket pattern (optional, default '/*')
  • websocketBehavior UWSWebSocketBehavior uWebSockets.js websocket behavior and options (optional, default {compression:0,maxPayloadLength:8*1024*1024,idleTimeout:10})

throwOnLeakedReferences

Throw an error if any internal data exists. Intended for tests and debugging.

Returns void

publishToPeers

Publish objects to peers.

Parameters
  • obj (ProviderDump | DataDump | ActiveProviderDump | PeerDump | PeerSubscriptionDump) Object to send, should have "ids" property

Returns void

setCredentialsHandler

Set the credentials handler. The handler evaluates and modifies credentials provided by peers and clients when they are initially provided.

Parameters

Returns void

setPeerRequestHandler

Set the peer request handler. Approves or denies peer request handlers.

Parameters

Returns void

setSubscribeRequestHandler

Set the subscribe request handler. Approves or denies subscribe requests.

Parameters

Returns void

setEventSubscribeRequestHandler

Set the event subscribe request handler. Approves or denies event subscribe requests.

Parameters

Returns void

handleCredentialsRequest

Top level handler for incoming credentials messages. Uses the default/custom credentialsHandler method to validate.

Parameters
  • socketId number Socket ID from which the credentials were received
  • existingCredentials Object Existing credentials object
  • clientCredentials Object Credentials object provided by the client

Returns void

handlePeerRequest

Top level handler for incoming peer request messages. Uses the default/custom peerRequestHandler method to validate.

Parameters
  • socketId number Socket ID from which the request was received
  • credentials Object Credentials object
  • peerId Object Peer ID provided by the client

Returns void

handleSubscribeRequest

Top level handler for incoming subscribe request messages. Uses the default/custom subscribeRequestHandler method to validate.

Parameters
  • socketId number Socket ID from which the request was received
  • credentials Object Credentials object
  • key string Key the subscriber is requesting updates on

Returns void

handleEventSubscribeRequest

Top level handler for incoming event subscribe request messages. Uses the default/custom eventSubscribeRequestHandler method to validate.

Parameters
  • socketId number Socket ID from which the request was received
  • credentials Object Credentials object
  • name string Event name the subscriber is requesting updates on

Returns void

handleMessage

Top level message handler, used by both sockets and connections.

Parameters
  • message (DataDump | ProviderDump | ActiveProviderDump | PeerDump | PeerSubscriptionDump | PeerSync | PeerSyncResponse | BraidEvent) Message to handle

Returns void

publishEvent

Publish event to subscribers.

Parameters

Returns void

publishData

Publish data to subscribers.

Parameters

Returns void

addEventSubscription

Add an event subscription to a socket.

Parameters
  • socketId number Socket ID of the subscriber
  • name string Name of the event to send

Returns void

removeEventSubscription

Remove a subscription from a socket.

Parameters
  • socketId number Socket ID of the subscriber
  • name string Name on which the subscriber should stop receiving events

Returns void

removeEventSubscriptions

Remove all subscriptions from a socket, for example after the socket disconnects

Parameters
  • socketId number Socket ID of the subscriber

Returns void

addSubscription

Add a subscription to a socket.

Parameters
  • socketId number Socket ID of the subscriber
  • key string Key to provide the subscriber with updates

Returns void

removeSubscription

Remove a subscription from a socket.

Parameters
  • socketId number Socket ID of the subscriber
  • key string Key on which the subscriber should stop receiving updates

Returns void

removeSubscriptions

Remove all subscriptions from a socket, for example after the socket disconnects

Parameters
  • socketId number Socket ID of the subscriber

Returns void

assignProvider

Assign a provider to a key.

Parameters
  • key string Key to provide peers with updates, which peers will then disseminate to subscribers

Returns void

provide

Indicate this server instance is providing for keys matching the regex string.

Parameters

Returns void

unprovide

Indicate this server instance is no longer providing for keys matching the regex string.

Parameters
  • regexString string Regex to match keys with

Returns void

closePeerConnections

Close all outgoing peer connections.

Returns Promise<void>

updatePeers

Update the peers Observed remove map with local peer IDs

Returns void

connectedPeers

Traverse through the peers Observed remove map to find all peers through which the specified peer is connected to

Parameters
  • id number Peer ID of the root peer
  • peerIds Set<number> Set to add connected peers to. (Passed by reference.)

Returns void

prunePeers

Traverse through connected peers and remove any peers without a direct path. Used after a peer disconnects.

Returns void

removePeer

Removes a peer, reassigning any active providers.

Parameters
  • peerId number Peer ID of the peer

Returns void

addPeer

Adds a peer.

Parameters
  • socketId number Socket ID of the peer
  • peerId number Peer ID of the peer

Returns void

close

Stops the server by gracefully closing all sockets and outgoing connections

Returns Promise<void>

connectToPeer

Connects to a peer

Parameters
  • address string Websocket URL of the peer
  • credentials Object? Credentials to send during the peer request
  • attempt number? Number of previous reconnect attempts (optional, default 0)

Returns Promise<number>

disconnectFromPeer

Disconnect from a peer

Parameters

Returns Promise<void>

reconnectToPeer

Send a peer sync message to an (outgoing) peer connection

Parameters
  • peerId number Peer ID to reconnect to
  • attempt number? Number of previous reconnect attempts
  • address string Websocket URL of the peer
  • credentials Object? Credentials to send during the peer reconnect request

Returns void

handlePeerSync

Handle a peer sync message, updating all shared maps with the provided data

Parameters
  • peerSync PeerSync Peer sync object

Returns void

syncPeerConnection

Send a peer sync message to an (outgoing) peer connection

Parameters
  • peerId number Peer ID to send sync message to

Returns Promise<void>

syncPeerSocket

Send a peer sync message to an (incoming) peer socket

Parameters
  • socketId number
  • peerId number Peer ID to send sync message to
  • socketID number Socket ID of peer to send sync message to

Returns Promise<void>

hasPeer

Check if peer exists

Parameters

Returns boolean

Repository

https://github.com/bunchtogether/braid-server.git


上一篇:@bunchtogether/hash-object
下一篇:你们要的Web前沿技术PWA在这里

相关推荐

  • eslint-config-bunchtogether

    Bunch's base JS ESLint config eslint-config-bunchtogether CDN by js...

    5 个月前
  • braid-client

    service proxies for Braid JsonRPC services braid-client NPM module Short Example npm install --save ...

    5 个月前
  • @bunchtogether/hash-object

    undefined Hash Object Performant object hashing. Supports native maps, sets, classes, and typed arra...

    7 个月前
  • @bunchtogether/braid-messagepack

    undefined Braid MessagePack Definitions WebSocket-based key-value synchronization. See also: Ser...

    5 个月前
  • @bunchtogether/braid-client

    undefined Braid Client WebSocket-based key-value synchronization. See also: Server MessagePack D...

    5 个月前

官方社区

扫码加入 JavaScript 社区