Преглед изворни кода

docs(ts): copy the old .d.ts comments to the source

Jonas Gloning пре 3 година
родитељ
комит
a43193fbcd
1 измењених фајлова са 54 додато и 5 уклоњено
  1. 54 5
      lib/peer.ts

+ 54 - 5
lib/peer.ts

@@ -33,11 +33,29 @@ class PeerOptions implements PeerJSOption {
 }
 
 type PeerEvents = {
+	/**
+	 * Emitted when a connection to the PeerServer is established.
+	 */
 	open: (id: string) => void;
+	/**
+	 * Emitted when a new data connection is established from a remote peer.
+	 */
 	connection: (dataConnection: DataConnection) => void;
+	/**
+	 * Emitted when a remote peer attempts to call you.
+	 */
 	call: (mediaConnection: MediaConnection) => void;
+	/**
+	 * Emitted when the peer is destroyed and can no longer accept or create any new connections.
+	 */
 	close: () => void;
+	/**
+	 * Emitted when the peer is disconnected from the signalling server
+	 */
 	disconnected: (currentId: string) => void;
+	/**
+	 * Errors on the peer are almost always fatal and will destroy the peer.
+	 */
 	error: (error: Error) => void;
 };
 /**
@@ -59,7 +77,9 @@ export class Peer extends EventEmitter<PeerEvents> {
 	private _open = false; // Sockets and such are not yet open.
 	private readonly _connections: Map<string, BaseConnection[]> = new Map(); // All connections for this peer.
 	private readonly _lostMessages: Map<string, ServerMessage[]> = new Map(); // src => [list of messages]
-
+	/**
+	 * The brokering ID of this peer
+	 */
 	get id() {
 		return this._id;
 	}
@@ -77,6 +97,7 @@ export class Peer extends EventEmitter<PeerEvents> {
 	}
 
 	/**
+	 * A hash of all connections associated with this peer, keyed by the remote peer's ID.
 	 * @deprecated
 	 * Return type will change from Object to Map<string,[]>
 	 */
@@ -90,13 +111,38 @@ export class Peer extends EventEmitter<PeerEvents> {
 		return plainConnections;
 	}
 
+	/**
+	 * true if this peer and all of its connections can no longer be used.
+	 */
 	get destroyed() {
 		return this._destroyed;
 	}
+	/**
+	 * false if there is an active connection to the PeerServer.
+	 */
 	get disconnected() {
 		return this._disconnected;
 	}
 
+	/**
+	 * A peer can connect to other peers and listen for connections.
+	 */
+	constructor();
+
+	/**
+	 * A peer can connect to other peers and listen for connections.
+	 * @param options for specifying details about PeerServer
+	 */
+	constructor(options: PeerOptions);
+
+	/**
+	 * A peer can connect to other peers and listen for connections.
+	 * @param id Other peers can connect to this peer using the provided ID.
+	 *     If no ID is given, one will be generated by the brokering server.
+	 * @param options for specifying details about PeerServer
+	 */
+	constructor(id: string, options?: PeerOptions);
+
 	constructor(id?: string | PeerOptions, options?: PeerOptions) {
 		super();
 
@@ -359,8 +405,9 @@ export class Peer extends EventEmitter<PeerEvents> {
 	}
 
 	/**
-	 * Returns a DataConnection to the specified peer. See documentation for a
-	 * complete list of options.
+	 * Connects to the remote peer specified by id and returns a data connection.
+	 * @param peer The brokering ID of the remote peer (their peer.id).
+	 * @param options for specifying details about Peer Connection
 	 */
 	connect(peer: string, options: PeerConnectOption = {}): DataConnection {
 		if (this.disconnected) {
@@ -383,8 +430,10 @@ export class Peer extends EventEmitter<PeerEvents> {
 	}
 
 	/**
-	 * Returns a MediaConnection to the specified peer. See documentation for a
-	 * complete list of options.
+	 * Calls the remote peer specified by id and returns a media connection.
+	 * @param peer The brokering ID of the remote peer (their peer.id).
+	 * @param stream The caller's media stream
+	 * @param options Metadata associated with the connection, passed in by whoever initiated the connection.
 	 */
 	call(
 		peer: string,