-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: peer connection events; helper functions (#23)
* feat: add 'getLocalDescription' method on PeerConnection * feat: derive PeerConnection from EventEmitter; proxy icegatheringstatechange event * feat: add function to wait for description with ice candidates * fix: fix spelling errors * refactor: use reject instead of throw
- Loading branch information
Showing
4 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { PeerConnection } from 'peer-connection'; | ||
|
||
/** | ||
* Wait until the given peer connection has finished gathering ICE candidates and, when it has, | ||
* return the local description with the candidates. | ||
* | ||
* @param peerConnection - The PeerConnection to use. | ||
* @returns A Promise that resolves with the local description with the ICE candidates in it. | ||
*/ | ||
export function getLocalDescriptionWithIceCandidates( | ||
peerConnection: PeerConnection | ||
): Promise<RTCSessionDescription> { | ||
return new Promise((resolve, reject) => { | ||
peerConnection.on(PeerConnection.Events.IceGatheringStateChange, (e) => { | ||
if (e.target.iceGatheringState === 'complete') { | ||
const localDesc = peerConnection.getLocalDescription(); | ||
if (localDesc) { | ||
resolve(localDesc); | ||
} else { | ||
reject(new Error('Local description was null')); | ||
} | ||
} | ||
// TODO(brian): throw an error if we see an error iceGatheringState | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters