From 82ea9a86c21846211550d80561919de4249db40e Mon Sep 17 00:00:00 2001 From: Gagan Suie Date: Thu, 23 Mar 2023 20:59:18 -0500 Subject: [PATCH] Fix: updated codecov file and added streaming utils --- .github/codecov.yml | 2 +- src/lib/WHEPClient.ts | 79 +++++++++++ src/lib/WHIPClient.ts | 134 ++++++++++++++++++ src/lib/negotiateConnectionWithClientOffer.ts | 84 +++++++++++ 4 files changed, 298 insertions(+), 1 deletion(-) create mode 100644 src/lib/WHEPClient.ts create mode 100644 src/lib/WHIPClient.ts create mode 100644 src/lib/negotiateConnectionWithClientOffer.ts diff --git a/.github/codecov.yml b/.github/codecov.yml index 223e1875..dbf7cfc0 100644 --- a/.github/codecov.yml +++ b/.github/codecov.yml @@ -1,2 +1,2 @@ fixes: - - "::/mage-website" + - "/home/runner/work/mage-website/::" diff --git a/src/lib/WHEPClient.ts b/src/lib/WHEPClient.ts new file mode 100644 index 00000000..722e124d --- /dev/null +++ b/src/lib/WHEPClient.ts @@ -0,0 +1,79 @@ +import negotiateConnectionWithClientOffer from '$lib/negotiateConnectionWithClientOffer' + +/** + * Example implementation of a client that uses WHEP to playback video over WebRTC + * + * https://www.ietf.org/id/draft-murillo-whep-00.html + */ +export default class WHEPClient { + private peerConnection: RTCPeerConnection + private stream: MediaStream + + constructor(private endpoint: string, private videoElement: HTMLVideoElement) { + this.stream = new MediaStream() + + /** + * Create a new WebRTC connection, using public STUN servers with ICE, + * allowing the client to disover its own IP address. + * https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Protocols#ice + */ + this.peerConnection = new RTCPeerConnection({ + iceServers: [ + { + urls: 'stun:stun.cloudflare.com:3478' + } + ], + bundlePolicy: 'max-bundle' + }) + + /** https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addTransceiver */ + this.peerConnection.addTransceiver('video', { + direction: 'recvonly' + }) + this.peerConnection.addTransceiver('audio', { + direction: 'recvonly' + }) + + /** + * When new tracks are received in the connection, store local references, + * so that they can be added to a MediaStream, and to the