Implement stubs to remind us what to do next
We need a way to message our peers easily and flexibly.
This commit is contained in:
parent
cf7451dcf2
commit
61bf2a27db
1 changed files with 27 additions and 0 deletions
|
@ -8,6 +8,10 @@ import ErrorWrapper from '../core/ErrorWrapper.mjs';
|
|||
|
||||
import Peer from './Peer.mjs';
|
||||
|
||||
/**
|
||||
* A server that handles connections to many peers.
|
||||
* @extends EventEmitter
|
||||
*/
|
||||
class PeerServer extends EventEmitter {
|
||||
constructor(our_id, secret_join) {
|
||||
super();
|
||||
|
@ -126,6 +130,29 @@ class PeerServer extends EventEmitter {
|
|||
return conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to 1 or more peers.
|
||||
* @param {string|Peer|string[]|Peer[]} peer_id Either the peer id or the peer itself to which we should send the message. May also be an array of arbitrarily mixed items - in which case the message will be sent to all the specified peers in parallel. The order which peers are messaged is undefined.
|
||||
* @param {string} event_name The name of the event to send.
|
||||
* @param {Object} msg The message itself to send.
|
||||
* @return {Promise} A Promise that resolves (or potentially rejects) when the message has been sent.
|
||||
*/
|
||||
async send(peer_id, event_name, msg) {
|
||||
throw new Error(`Not implemented yet`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message in parallel to all peers to which we have an established
|
||||
* connection.
|
||||
* The order which peers are messaged is undefined.
|
||||
* @param {string} event_name The name of the event to send.
|
||||
* @param {Object} msg The message itself to send.
|
||||
* @return {Promise} A Promise that resolves (or potentially rejects) when the message has been sent.
|
||||
*/
|
||||
async broadcast(event_name, msg) {
|
||||
await this.send(this.connected_peers, event_name, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuts the server down.
|
||||
* This does not disconnect any existing peers!
|
||||
|
|
Loading…
Reference in a new issue