* * Setup connection to a remote peer. * * @param remotePeerID valid remote peer ID in the p2p network. * @returns Promise that either resolves when a connection is established * or throws and exception if connectiion attempt fails.
(remotePeerID: string)
| 102 | * or throws and exception if connectiion attempt fails. |
| 103 | */ |
| 104 | async connect(remotePeerID: string) { |
| 105 | if (!remotePeerID) { |
| 106 | const msg = "Valid remote Peer ID required!" |
| 107 | throw new Error(msg) |
| 108 | } |
| 109 | this._signalingConnectionStatus = ConnectionStatus.CONNECTING |
| 110 | this._remotePeerID = remotePeerID |
| 111 | if (this._config && !this._config.debug) { |
| 112 | // set PeerJS at debug level by default |
| 113 | this._config.debug = 3 |
| 114 | } |
| 115 | let newPeer = new Peer(this._config) |
| 116 | this._peer = newPeer |
| 117 | // return a promise that will be resolved when the peer connection is ready. |
| 118 | const setupReady = new Promise((connectionSetupResolve, connectionSetupReject) => { |
| 119 | this._setSignalingServiceConnectionHandlers(newPeer, connectionSetupResolve, connectionSetupReject) |
| 120 | }) |
| 121 | return setupReady |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Tead down connections to remote peer and signaling server. |
no test coverage detected