diff --git a/.gitignore b/.gitignore index 4d009c7d3..71b36944e 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,5 @@ examples/GumTestApp_macOS/package-lock.json *.jar *.tgz *.zip -lib/ src/*.js diff --git a/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java b/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java index 55560942e..39279b893 100644 --- a/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java +++ b/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java @@ -87,6 +87,55 @@ public void setOnDimensionsChange(WebRTCView view, boolean onDimensionsChange) { view.setOnDimensionsChange(onDimensionsChange); } + /** + * Sets custom scale for video rendering. + * + * @param view The {@code WebRTCView} on which the scale is to be set. + * @param scale The scale factor (1.0 = original size). + */ + @ReactProp(name = "customScale") + public void setCustomScale(WebRTCView view, float scale) { + view.setCustomScale(scale); + } + + /** + * Sets custom X translation for video rendering. + * + * @param view The {@code WebRTCView} on which the translation is to be set. + * @param translateX Translation as fraction of container width (-1 to 1). + */ + @ReactProp(name = "customTranslateX") + public void setCustomTranslateX(WebRTCView view, float translateX) { + view.setCustomTranslateX(translateX); + } + + /** + * Sets custom Y translation for video rendering. + * + * @param view The {@code WebRTCView} on which the translation is to be set. + * @param translateY Translation as fraction of container height (-1 to 1). + */ + @ReactProp(name = "customTranslateY") + public void setCustomTranslateY(WebRTCView view, float translateY) { + view.setCustomTranslateY(translateY); + } + + /** + * Enables or disables custom transformation mode. + * + * @param view The {@code WebRTCView} on which the mode is to be set. + * @param enabled Whether custom transformations should be used. + */ + @ReactProp(name = "useCustomTransform") + public void setUseCustomTransform(WebRTCView view, boolean enabled) { + view.setUseCustomTransform(enabled); + } + + @ReactProp(name = "useTextureView") + public void setUseTextureView(WebRTCView view, boolean useTextureView) { + view.setUseTextureView(useTextureView); + } + @Override public Map getExportedCustomDirectEventTypeConstants() { Map eventTypeConstants = new HashMap<>(); diff --git a/android/src/main/java/com/oney/WebRTCModule/TextureViewRenderer.java b/android/src/main/java/com/oney/WebRTCModule/TextureViewRenderer.java new file mode 100644 index 000000000..23c2eed79 --- /dev/null +++ b/android/src/main/java/com/oney/WebRTCModule/TextureViewRenderer.java @@ -0,0 +1,143 @@ +package com.oney.WebRTCModule; + +import android.content.Context; +import android.graphics.SurfaceTexture; +import android.util.Log; +import android.view.TextureView; + +import org.webrtc.EglBase; +import org.webrtc.EglRenderer; +import org.webrtc.RendererCommon; +import org.webrtc.RendererCommon.RendererEvents; +import org.webrtc.RendererCommon.ScalingType; +import org.webrtc.VideoFrame; +import org.webrtc.VideoSink; + +/** + * A TextureView-based video renderer for WebRTC. + * Unlike SurfaceViewRenderer, TextureView renders in the normal View hierarchy + * and supports borderRadius, overflow:hidden, alpha, and other standard View operations. + * + * Uses EglRenderer internally for OpenGL rendering to the TextureView's SurfaceTexture. + */ +public class TextureViewRenderer extends TextureView + implements TextureView.SurfaceTextureListener, VideoSink { + + private static final String TAG = "TextureViewRenderer"; + + private final EglRenderer eglRenderer; + private RendererEvents rendererEvents; + private boolean isInitialized = false; + private boolean isFirstFrameRendered = false; + private int rotatedFrameWidth; + private int rotatedFrameHeight; + private int frameRotation; + + public TextureViewRenderer(Context context) { + super(context); + eglRenderer = new EglRenderer(TAG); + setSurfaceTextureListener(this); + setOpaque(false); + } + + public void init(EglBase.Context sharedContext, RendererEvents rendererEvents) { + init(sharedContext, rendererEvents, EglBase.CONFIG_PLAIN, new org.webrtc.GlRectDrawer()); + } + + public void init(EglBase.Context sharedContext, RendererEvents rendererEvents, + int[] configAttributes, RendererCommon.GlDrawer drawer) { + this.rendererEvents = rendererEvents; + eglRenderer.init(sharedContext, configAttributes, drawer); + isInitialized = true; + isFirstFrameRendered = false; + + // If the SurfaceTexture is already available, create the EGL surface now + SurfaceTexture surfaceTexture = getSurfaceTexture(); + if (surfaceTexture != null) { + eglRenderer.createEglSurface(surfaceTexture); + } + } + + public void release() { + if (isInitialized) { + eglRenderer.release(); + isInitialized = false; + } + } + + public void setMirror(boolean mirror) { + eglRenderer.setMirror(mirror); + } + + public void setScalingType(ScalingType scalingType) { + // EglRenderer doesn't have setScalingType directly — it relies on layout. + // For TextureView, scaling is handled by the parent WebRTCView's onLayout. + } + + public void clearImage() { + eglRenderer.clearImage(); + } + + // VideoSink implementation + @Override + public void onFrame(VideoFrame videoFrame) { + eglRenderer.onFrame(videoFrame); + + if (!isFirstFrameRendered) { + isFirstFrameRendered = true; + if (rendererEvents != null) { + rendererEvents.onFirstFrameRendered(); + } + } + + // Check for resolution changes + int rotation = videoFrame.getRotation(); + int width = (rotation % 180 == 0) + ? videoFrame.getRotatedWidth() + : videoFrame.getRotatedHeight(); + int height = (rotation % 180 == 0) + ? videoFrame.getRotatedHeight() + : videoFrame.getRotatedWidth(); + + if (width != rotatedFrameWidth || height != rotatedFrameHeight || rotation != frameRotation) { + rotatedFrameWidth = width; + rotatedFrameHeight = height; + frameRotation = rotation; + if (rendererEvents != null) { + rendererEvents.onFrameResolutionChanged( + videoFrame.getBuffer().getWidth(), + videoFrame.getBuffer().getHeight(), + rotation); + } + } + } + + // TextureView.SurfaceTextureListener implementation + @Override + public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) { + if (isInitialized) { + eglRenderer.createEglSurface(surfaceTexture); + } + } + + @Override + public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, int height) { + // EglRenderer handles size changes through the layout mechanism + } + + @Override + public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) { + if (isInitialized) { + // Return false = we take ownership of the SurfaceTexture and release it + // asynchronously after EGL is done. This avoids blocking the UI thread. + eglRenderer.releaseEglSurface(() -> surfaceTexture.release()); + return false; + } + return true; + } + + @Override + public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) { + // No-op + } +} diff --git a/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java b/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java index 5d14d0f76..92b2dde28 100644 --- a/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +++ b/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java @@ -24,6 +24,7 @@ import org.webrtc.RendererCommon.RendererEvents; import org.webrtc.RendererCommon.ScalingType; import org.webrtc.SurfaceViewRenderer; + import org.webrtc.VideoTrack; import java.lang.reflect.InvocationTargetException; @@ -154,6 +155,23 @@ public void run() { */ private boolean onDimensionsChangeEnabled = false; + /** + * Custom video frame transformation values + * These affect how the video is rendered INSIDE the SurfaceView + */ + private float customScale = 1.0f; + private float customTranslateX = 0f; // as fraction of width (-1 to 1) + private float customTranslateY = 0f; // as fraction of height (-1 to 1) + private boolean useCustomTransform = false; + + /** + * When true, uses TextureViewRenderer instead of SurfaceViewRenderer. + * TextureView renders in the normal View hierarchy and supports + * borderRadius, overflow:hidden, and other clipping. + */ + private boolean useTextureView = false; + private TextureViewRenderer textureViewRenderer; + public WebRTCView(Context context) { super(context); @@ -169,8 +187,13 @@ public WebRTCView(Context context) { * opaque black and the surface part to transparent. */ private void cleanSurfaceViewRenderer() { - surfaceViewRenderer.setBackgroundColor(Color.BLACK); - surfaceViewRenderer.clearImage(); + if (useTextureView && textureViewRenderer != null) { + // TextureView doesn't support setBackgroundColor/setBackgroundDrawable + textureViewRenderer.clearImage(); + } else { + surfaceViewRenderer.setBackgroundColor(Color.BLACK); + surfaceViewRenderer.clearImage(); + } } private VideoTrack getVideoTrackForStreamURL(String streamURL) { @@ -234,7 +257,10 @@ protected void onDetachedFromWindow() { private void onFirstFrameRendered() { post(() -> { Log.d(TAG, "First frame rendered."); - surfaceViewRenderer.setBackgroundColor(Color.TRANSPARENT); + // TextureView doesn't support setBackgroundColor/setBackgroundDrawable + if (!useTextureView) { + surfaceViewRenderer.setBackgroundColor(Color.TRANSPARENT); + } }); } @@ -308,40 +334,87 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { scalingType = this.scalingType; } - switch (scalingType) { - case SCALE_ASPECT_FILL: - // Fill this ViewGroup with surfaceViewRenderer and the latter - // will take care of filling itself with the video similarly to - // the cover value the CSS property object-fit. - r = width; - l = 0; - b = height; - t = 0; - break; - case SCALE_ASPECT_FIT: - default: - // Lay surfaceViewRenderer out inside this ViewGroup in accord - // with the contain value of the CSS property object-fit. - // SurfaceViewRenderer will fill itself with the video similarly - // to the cover or contain value of the CSS property object-fit - // (which will not matter, eventually). - if (frameHeight == 0 || frameWidth == 0) { - l = t = r = b = 0; - } else { - float frameAspectRatio = (frameRotation % 180 == 0) ? frameWidth / (float) frameHeight - : frameHeight / (float) frameWidth; - Point frameDisplaySize = - RendererCommon.getDisplaySize(scalingType, frameAspectRatio, width, height); - - l = (width - frameDisplaySize.x) / 2; - t = (height - frameDisplaySize.y) / 2; - r = l + frameDisplaySize.x; - b = t + frameDisplaySize.y; - } - break; + if (useCustomTransform && frameHeight > 0 && frameWidth > 0) { + // Custom transformation mode + // We keep SCALE_ASPECT_FIT (contain) so video is not cropped + // and we control the size/position via layout bounds + if (useTextureView && textureViewRenderer != null) { + textureViewRenderer.setScalingType(ScalingType.SCALE_ASPECT_FIT); + } else { + surfaceViewRenderer.setScalingType(ScalingType.SCALE_ASPECT_FIT); + } + + float frameAspectRatio = (frameRotation % 180 == 0) ? frameWidth / (float) frameHeight + : frameHeight / (float) frameWidth; + + // Start with SCALE_ASPECT_FIT size (100% visible, no cropping) + Point baseSize = RendererCommon.getDisplaySize( + ScalingType.SCALE_ASPECT_FIT, frameAspectRatio, width, height); + + // Apply custom scale to the fitted size + int scaledWidth = (int)(baseSize.x * customScale); + int scaledHeight = (int)(baseSize.y * customScale); + + // Calculate base position (centered) + int centerX = width / 2; + int centerY = height / 2; + + // Apply custom translation (as fraction of container size) + int offsetX = (int)(width * customTranslateX); + int offsetY = (int)(height * customTranslateY); + + // Calculate final bounds + int rawL = centerX - scaledWidth / 2 + offsetX; + int rawT = centerY - scaledHeight / 2 + offsetY; + int rawR = rawL + scaledWidth; + int rawB = rawT + scaledHeight; + + // Clamp bounds to container to prevent overflow onto other views + // SurfaceView ignores parent's overflow:hidden, so we must clip here + l = Math.max(0, rawL); + t = Math.max(0, rawT); + r = Math.min(width, rawR); + b = Math.min(height, rawB); + } else { + switch (scalingType) { + case SCALE_ASPECT_FILL: + // Fill this ViewGroup with surfaceViewRenderer and the latter + // will take care of filling itself with the video similarly to + // the cover value the CSS property object-fit. + r = width; + l = 0; + b = height; + t = 0; + break; + case SCALE_ASPECT_FIT: + default: + // Lay surfaceViewRenderer out inside this ViewGroup in accord + // with the contain value of the CSS property object-fit. + // SurfaceViewRenderer will fill itself with the video similarly + // to the cover or contain value of the CSS property object-fit + // (which will not matter, eventually). + if (frameHeight == 0 || frameWidth == 0) { + l = t = r = b = 0; + } else { + float frameAspectRatio = (frameRotation % 180 == 0) ? frameWidth / (float) frameHeight + : frameHeight / (float) frameWidth; + Point frameDisplaySize = + RendererCommon.getDisplaySize(scalingType, frameAspectRatio, width, height); + + l = (width - frameDisplaySize.x) / 2; + t = (height - frameDisplaySize.y) / 2; + r = l + frameDisplaySize.x; + b = t + frameDisplaySize.y; + } + break; + } } } - surfaceViewRenderer.layout(l, t, r, b); + if (useTextureView && textureViewRenderer != null) { + textureViewRenderer.layout(l, t, r, b); + } else { + surfaceViewRenderer.layout(l, t, r, b); + } } /** @@ -351,9 +424,14 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { private void removeRendererFromVideoTrack() { if (rendererAttached) { if (videoTrack != null) { + final boolean isTexture = useTextureView && textureViewRenderer != null; ThreadUtils.runOnExecutor(() -> { try { - videoTrack.removeSink(surfaceViewRenderer); + if (isTexture) { + videoTrack.removeSink(textureViewRenderer); + } else { + videoTrack.removeSink(surfaceViewRenderer); + } } catch (Throwable tr) { // XXX If WebRTCModule#mediaStreamTrackRelease has already been // invoked on videoTrack, then it is no longer safe to call removeSink @@ -362,12 +440,16 @@ private void removeRendererFromVideoTrack() { }); } - surfaceViewRenderer.release(); + if (useTextureView && textureViewRenderer != null) { + textureViewRenderer.release(); + } else { + surfaceViewRenderer.release(); + } surfaceViewRendererInstances--; rendererAttached = false; // Since this WebRTCView is no longer rendering anything, make sure - // surfaceViewRenderer displays nothing as well. + // the renderer displays nothing as well. synchronized (layoutSyncRoot) { frameHeight = 0; frameRotation = 0; @@ -384,9 +466,13 @@ private void removeRendererFromVideoTrack() { */ @SuppressLint("WrongCall") private void requestSurfaceViewRendererLayout() { - // Google/WebRTC just call requestLayout() on surfaceViewRenderer when + // Google/WebRTC just call requestLayout() on the renderer when // they change the value of its mirror or surfaceType property. - surfaceViewRenderer.requestLayout(); + if (useTextureView && textureViewRenderer != null) { + textureViewRenderer.requestLayout(); + } else { + surfaceViewRenderer.requestLayout(); + } // The above is not enough though when the video frame's dimensions or // rotation change. The following will suffice. if (!ViewCompat.isInLayout(this)) { @@ -406,9 +492,11 @@ private void requestSurfaceViewRendererLayout() { public void setMirror(boolean mirror) { if (this.mirror != mirror) { this.mirror = mirror; - surfaceViewRenderer.setMirror(mirror); - // SurfaceViewRenderer takes the value of its mirror property into - // account upon its layout. + if (useTextureView && textureViewRenderer != null) { + textureViewRenderer.setMirror(mirror); + } else { + surfaceViewRenderer.setMirror(mirror); + } requestSurfaceViewRendererLayout(); } } @@ -436,10 +524,12 @@ private void setScalingType(ScalingType scalingType) { return; } this.scalingType = scalingType; - surfaceViewRenderer.setScalingType(scalingType); + if (useTextureView && textureViewRenderer != null) { + textureViewRenderer.setScalingType(scalingType); + } else { + surfaceViewRenderer.setScalingType(scalingType); + } } - // Both this instance ant its SurfaceViewRenderer take the value of - // their scalingType properties into account upon their layouts. requestSurfaceViewRendererLayout(); } @@ -519,6 +609,10 @@ private void setVideoTrack(VideoTrack videoTrack) { * @param zOrder The z-order to set on this {@code WebRTCView}. */ public void setZOrder(int zOrder) { + // TextureView uses normal View z-ordering, no special handling needed + if (useTextureView) { + return; + } switch (zOrder) { case 0: surfaceViewRenderer.setZOrderMediaOverlay(false); @@ -541,32 +635,52 @@ private void tryAddRendererToVideoTrack() { EglBase.Context sharedContext = EglUtils.getRootEglBaseContext(); if (sharedContext == null) { - // If SurfaceViewRenderer#init() is invoked, it will throw a - // RuntimeException which will very likely kill the application. Log.e(TAG, "Failed to render a VideoTrack!"); return; } - try { - surfaceViewRenderer.init(sharedContext, rendererEvents); - surfaceViewRendererInstances++; - } catch (Exception e) { - Logging.e( - TAG, "Failed to initialize surfaceViewRenderer on instance " + surfaceViewRendererInstances, e); - return; - } + if (useTextureView) { + if (textureViewRenderer == null) { + textureViewRenderer = new TextureViewRenderer(getContext()); + addView(textureViewRenderer); + surfaceViewRenderer.setVisibility(View.GONE); + } - ThreadUtils.runOnExecutor(() -> { try { - videoTrack.addSink(surfaceViewRenderer); - } catch (Throwable tr) { - // XXX If WebRTCModule#mediaStreamTrackRelease has already been - // invoked on videoTrack, then it is no longer safe to call addSink - // on the instance, it will throw IllegalStateException. + textureViewRenderer.init(sharedContext, rendererEvents); + surfaceViewRendererInstances++; + } catch (Exception e) { + Logging.e(TAG, "Failed to initialize textureViewRenderer on instance " + surfaceViewRendererInstances, e); + return; + } + + textureViewRenderer.setScalingType(scalingType); + textureViewRenderer.setMirror(mirror); - Log.e(TAG, "Failed to add renderer", tr); + ThreadUtils.runOnExecutor(() -> { + try { + videoTrack.addSink(textureViewRenderer); + } catch (Throwable tr) { + Log.e(TAG, "Failed to add renderer", tr); + } + }); + } else { + try { + surfaceViewRenderer.init(sharedContext, rendererEvents); + surfaceViewRendererInstances++; + } catch (Exception e) { + Logging.e(TAG, "Failed to initialize surfaceViewRenderer on instance " + surfaceViewRendererInstances, e); + return; } - }); + + ThreadUtils.runOnExecutor(() -> { + try { + videoTrack.addSink(surfaceViewRenderer); + } catch (Throwable tr) { + Log.e(TAG, "Failed to add renderer", tr); + } + }); + } rendererAttached = true; } @@ -580,4 +694,87 @@ private void tryAddRendererToVideoTrack() { public void setOnDimensionsChange(boolean enabled) { this.onDimensionsChangeEnabled = enabled; } + + /** + * Sets custom scale for video rendering. + * + * @param scale The scale factor (1.0 = original size). + */ + public void setCustomScale(float scale) { + if (this.customScale != scale) { + this.customScale = scale; + requestSurfaceViewRendererLayout(); + } + } + + /** + * Sets custom X translation for video rendering. + * + * @param translateX Translation as fraction of container width (-1 to 1). + */ + public void setCustomTranslateX(float translateX) { + if (this.customTranslateX != translateX) { + this.customTranslateX = translateX; + requestSurfaceViewRendererLayout(); + } + } + + /** + * Sets custom Y translation for video rendering. + * + * @param translateY Translation as fraction of container height (-1 to 1). + */ + public void setCustomTranslateY(float translateY) { + if (this.customTranslateY != translateY) { + this.customTranslateY = translateY; + requestSurfaceViewRendererLayout(); + } + } + + /** + * Enables or disables custom transformation mode. + * + * @param enabled Whether custom transformations should be used. + */ + public void setUseCustomTransform(boolean enabled) { + if (this.useCustomTransform != enabled) { + this.useCustomTransform = enabled; + requestSurfaceViewRendererLayout(); + } + } + + /** + * Switches between SurfaceViewRenderer and TextureViewRenderer. + * TextureView renders in the normal View hierarchy and supports + * borderRadius, overflow:hidden, and other View clipping. + * + * @param useTextureView If true, use TextureViewRenderer. + */ + public void setUseTextureView(boolean useTextureView) { + if (this.useTextureView == useTextureView) { + return; + } + + // Detach current renderer from video track + removeRendererFromVideoTrack(); + + this.useTextureView = useTextureView; + + if (useTextureView) { + surfaceViewRenderer.setVisibility(View.GONE); + if (textureViewRenderer == null) { + textureViewRenderer = new TextureViewRenderer(getContext()); + addView(textureViewRenderer); + } + textureViewRenderer.setVisibility(View.VISIBLE); + } else { + if (textureViewRenderer != null) { + textureViewRenderer.setVisibility(View.GONE); + } + surfaceViewRenderer.setVisibility(View.VISIBLE); + } + + // Re-attach to video track with the new renderer + tryAddRendererToVideoTrack(); + } } diff --git a/lib/commonjs/Constraints.js b/lib/commonjs/Constraints.js new file mode 100644 index 000000000..b7550bdc8 --- /dev/null +++ b/lib/commonjs/Constraints.js @@ -0,0 +1,2 @@ +"use strict"; +//# sourceMappingURL=Constraints.js.map \ No newline at end of file diff --git a/lib/commonjs/Constraints.js.map b/lib/commonjs/Constraints.js.map new file mode 100644 index 000000000..6bcd02e43 --- /dev/null +++ b/lib/commonjs/Constraints.js.map @@ -0,0 +1 @@ +{"version":3,"names":[],"sources":["Constraints.ts"],"sourcesContent":["\nexport type MediaTrackConstraints = {\n width?: ConstrainNumber;\n height?: ConstrainNumber;\n frameRate?: ConstrainNumber;\n facingMode?: ConstrainString;\n deviceId?: ConstrainString;\n groupId?: ConstrainString;\n}\n\ntype ConstrainNumber = number | {\n exact?: number,\n ideal?: number,\n max?: number,\n min?: number,\n}\n\ntype ConstrainString = string | {\n exact?: string,\n ideal?: string,\n}"],"mappings":""} \ No newline at end of file diff --git a/lib/commonjs/EventEmitter.js b/lib/commonjs/EventEmitter.js new file mode 100644 index 000000000..9a28c7d1f --- /dev/null +++ b/lib/commonjs/EventEmitter.js @@ -0,0 +1,51 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.addListener = addListener; +exports.removeListener = removeListener; +exports.setupNativeEvents = setupNativeEvents; +var _reactNative = require("react-native"); +var _EventEmitter = _interopRequireDefault(require("react-native/Libraries/vendor/emitter/EventEmitter")); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +// @ts-ignore + +const { + WebRTCModule +} = _reactNative.NativeModules; + +// This emitter is going to be used to listen to all the native events (once) and then +// re-emit them on a JS-only emitter. +const nativeEmitter = new _reactNative.NativeEventEmitter(WebRTCModule); +const NATIVE_EVENTS = ['peerConnectionSignalingStateChanged', 'peerConnectionStateChanged', 'peerConnectionOnRenegotiationNeeded', 'peerConnectionIceConnectionChanged', 'peerConnectionIceGatheringChanged', 'peerConnectionGotICECandidate', 'peerConnectionDidOpenDataChannel', 'peerConnectionOnRemoveTrack', 'peerConnectionOnTrack', 'dataChannelStateChanged', 'dataChannelReceiveMessage', 'dataChannelDidChangeBufferedAmount', 'mediaStreamTrackMuteChanged', 'mediaStreamTrackEnded', 'frameCryptionStateChanged']; +const eventEmitter = new _EventEmitter.default(); +function setupNativeEvents() { + for (const eventName of NATIVE_EVENTS) { + nativeEmitter.addListener(eventName, function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + eventEmitter.emit(eventName, ...args); + }); + } +} +const _subscriptions = new Map(); +function addListener(listener, eventName, eventHandler) { + var _subscriptions$get; + if (!NATIVE_EVENTS.includes(eventName)) { + throw new Error(`Invalid event: ${eventName}`); + } + if (!_subscriptions.has(listener)) { + _subscriptions.set(listener, []); + } + (_subscriptions$get = _subscriptions.get(listener)) === null || _subscriptions$get === void 0 ? void 0 : _subscriptions$get.push(eventEmitter.addListener(eventName, eventHandler)); +} +function removeListener(listener) { + var _subscriptions$get2; + (_subscriptions$get2 = _subscriptions.get(listener)) === null || _subscriptions$get2 === void 0 ? void 0 : _subscriptions$get2.forEach(sub => { + sub.remove(); + }); + _subscriptions.delete(listener); +} +//# sourceMappingURL=EventEmitter.js.map \ No newline at end of file diff --git a/lib/commonjs/EventEmitter.js.map b/lib/commonjs/EventEmitter.js.map new file mode 100644 index 000000000..dd790f4b7 --- /dev/null +++ b/lib/commonjs/EventEmitter.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_reactNative","require","_EventEmitter","_interopRequireDefault","obj","__esModule","default","WebRTCModule","NativeModules","nativeEmitter","NativeEventEmitter","NATIVE_EVENTS","eventEmitter","EventEmitter","setupNativeEvents","eventName","addListener","_len","arguments","length","args","Array","_key","emit","_subscriptions","Map","listener","eventHandler","_subscriptions$get","includes","Error","has","set","get","push","removeListener","_subscriptions$get2","forEach","sub","remove","delete"],"sources":["EventEmitter.ts"],"sourcesContent":["import { NativeModules, NativeEventEmitter, EmitterSubscription } from 'react-native';\n// @ts-ignore\nimport EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter';\n\nconst { WebRTCModule } = NativeModules;\n\n// This emitter is going to be used to listen to all the native events (once) and then\n// re-emit them on a JS-only emitter.\nconst nativeEmitter = new NativeEventEmitter(WebRTCModule);\n\nconst NATIVE_EVENTS = [\n 'peerConnectionSignalingStateChanged',\n 'peerConnectionStateChanged',\n 'peerConnectionOnRenegotiationNeeded',\n 'peerConnectionIceConnectionChanged',\n 'peerConnectionIceGatheringChanged',\n 'peerConnectionGotICECandidate',\n 'peerConnectionDidOpenDataChannel',\n 'peerConnectionOnRemoveTrack',\n 'peerConnectionOnTrack',\n 'dataChannelStateChanged',\n 'dataChannelReceiveMessage',\n 'dataChannelDidChangeBufferedAmount',\n 'mediaStreamTrackMuteChanged',\n 'mediaStreamTrackEnded',\n 'frameCryptionStateChanged',\n];\n\nconst eventEmitter = new EventEmitter();\n\nexport function setupNativeEvents() {\n for (const eventName of NATIVE_EVENTS) {\n nativeEmitter.addListener(eventName, (...args) => {\n eventEmitter.emit(eventName, ...args);\n });\n }\n}\n\ntype EventHandler = (event: unknown) => void;\ntype Listener = unknown;\n\nconst _subscriptions: Map = new Map();\n\nexport function addListener(listener: Listener, eventName: string, eventHandler: EventHandler): void {\n if (!NATIVE_EVENTS.includes(eventName)) {\n throw new Error(`Invalid event: ${eventName}`);\n }\n\n if (!_subscriptions.has(listener)) {\n _subscriptions.set(listener, []);\n }\n\n _subscriptions.get(listener)?.push(eventEmitter.addListener(eventName, eventHandler));\n}\n\nexport function removeListener(listener: Listener): void {\n _subscriptions.get(listener)?.forEach(sub => {\n sub.remove();\n });\n\n _subscriptions.delete(listener);\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAC,sBAAA,CAAAF,OAAA;AAA8E,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAD9E;;AAGA,MAAM;EAAEG;AAAa,CAAC,GAAGC,0BAAa;;AAEtC;AACA;AACA,MAAMC,aAAa,GAAG,IAAIC,+BAAkB,CAACH,YAAY,CAAC;AAE1D,MAAMI,aAAa,GAAG,CAClB,qCAAqC,EACrC,4BAA4B,EAC5B,qCA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AACzF;AAEO,SAASQ,cAAcA,CAACT,QAAkB,EAAQ;EAAA,IAAAU,mBAAA;EACrD,CAAAA,mBAAA,GAAAZ,cAAc,CAACS,GAAG,CAACP,QAAQ,CAAC,cAAAU,mBAAA,uBAA5BA,mBAAA,CAA8BC,OAAO,CAACC,GAAG,IAAI;IACzCA,GAAG,CAACC,MAAM,CAAC,CAAC;EAChB,CAAC,CAAC;EAEFf,cAAc,CAACgB,MAAM,CAACd,QAAQ,CAAC;AACnC"} \ No newline at end of file diff --git a/lib/commonjs/Logger.js b/lib/commonjs/Logger.js new file mode 100644 index 000000000..1782e2405 --- /dev/null +++ b/lib/commonjs/Logger.js @@ -0,0 +1,47 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _debug = _interopRequireDefault(require("debug")); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +class Logger { + static enable(ns) { + _debug.default.enable(ns); + } + constructor(prefix) { + _defineProperty(this, "_debug", void 0); + _defineProperty(this, "_info", void 0); + _defineProperty(this, "_warn", void 0); + _defineProperty(this, "_error", void 0); + const _prefix = `${Logger.ROOT_PREFIX}:${prefix}`; + this._debug = (0, _debug.default)(`${_prefix}:DEBUG`); + this._info = (0, _debug.default)(`${_prefix}:INFO`); + this._warn = (0, _debug.default)(`${_prefix}:WARN`); + this._error = (0, _debug.default)(`${_prefix}:ERROR`); + const log = console.log.bind(console); + this._debug.log = log; + this._info.log = log; + this._warn.log = log; + this._error.log = log; + } + debug(msg) { + this._debug(msg); + } + info(msg) { + this._info(msg); + } + warn(msg) { + this._warn(msg); + } + error(msg, err) { + var _err$stack; + const trace = (_err$stack = err === null || err === void 0 ? void 0 : err.stack) !== null && _err$stack !== void 0 ? _err$stack : 'N/A'; + this._error(`${msg} Trace: ${trace}`); + } +} +exports.default = Logger; +_defineProperty(Logger, "ROOT_PREFIX", 'rn-webrtc'); +//# sourceMappingURL=Logger.js.map \ No newline at end of file diff --git a/lib/commonjs/Logger.js.map b/lib/commonjs/Logger.js.map new file mode 100644 index 000000000..b4c7999cd --- /dev/null +++ b/lib/commonjs/Logger.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_debug","_interopRequireDefault","require","obj","__esModule","default","_defineProperty","key","value","Object","defineProperty","enumerable","configurable","writable","Logger","enable","ns","debug","constructor","prefix","_prefix","ROOT_PREFIX","_info","_warn","_error","log","console","bind","msg","info","warn","error","err","_err$stack","trace","stack","exports"],"sources":["Logger.ts"],"sourcesContent":["import debug from 'debug';\n\n\nexport default class Logger {\n static ROOT_PREFIX = 'rn-webrtc';\n\n private _debug: debug.Debugger;\n private _info: debug.Debugger;\n private _warn: debug.Debugger;\n private _error: debug.Debugger;\n\n static enable(ns: string): void {\n debug.enable(ns);\n }\n\n constructor(prefix: string) {\n const _prefix = `${Logger.ROOT_PREFIX}:${prefix}`;\n\n this._debug = debug(`${_prefix}:DEBUG`);\n this._info = debug(`${_prefix}:INFO`);\n this._warn = debug(`${_prefix}:WARN`);\n this._error = debug(`${_prefix}:ERROR`);\n\n const log = console.log.bind(console);\n\n this._debug.log = log;\n this._info.log = log;\n this._warn.log = log;\n this._error.log = log;\n }\n\n debug(msg: string): void {\n this._debug(msg);\n }\n\n info(msg: string): void {\n this._info(msg);\n }\n\n warn(msg: string): void {\n this._warn(msg);\n }\n\n error(msg: string, err?: Error): void {\n const trace = err?.stack ?? 'N/A';\n\n this._error(`${msg} Trace: ${trace}`);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA0B,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,Q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EAE,IAAIA,CAACF,GAAW,EAAQ;IACpB,IAAI,CAACL,KAAK,CAACK,GAAG,CAAC;EACnB;EAEAG,KAAKA,CAACH,GAAW,EAAEI,GAAW,EAAQ;IAAA,IAAAC,UAAA;IAClC,MAAMC,KAAK,IAAAD,UAAA,GAAGD,GAAG,aAAHA,GAAG,uBAAHA,GAAG,CAAEG,KAAK,cAAAF,UAAA,cAAAA,UAAA,GAAI,KAAK;IAEjC,IAAI,CAACT,MAAM,CAAE,GAAEI,GAAI,WAAUM,KAAM,EAAC,CAAC;EACzC;AACJ;AAACE,OAAA,CAAA/B,OAAA,GAAAS,MAAA;AAAAR,eAAA,CA7CoBQ,MAAM,iBACF,WAAW"} \ No newline at end of file diff --git a/lib/commonjs/MediaDevices.js b/lib/commonjs/MediaDevices.js new file mode 100644 index 000000000..10a51e519 --- /dev/null +++ b/lib/commonjs/MediaDevices.js @@ -0,0 +1,54 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _index = require("event-target-shim/index"); +var _reactNative = require("react-native"); +var _getDisplayMedia = _interopRequireDefault(require("./getDisplayMedia")); +var _getUserMedia = _interopRequireDefault(require("./getUserMedia")); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +const { + WebRTCModule +} = _reactNative.NativeModules; +class MediaDevices extends _index.EventTarget { + /** + * W3C "Media Capture and Streams" compatible {@code enumerateDevices} + * implementation. + */ + enumerateDevices() { + return new Promise(resolve => WebRTCModule.enumerateDevices(resolve)); + } + + /** + * W3C "Screen Capture" compatible {@code getDisplayMedia} implementation. + * See: https://w3c.github.io/mediacapture-screen-share/ + * + * @returns {Promise} + */ + getDisplayMedia() { + return (0, _getDisplayMedia.default)(); + } + + /** + * W3C "Media Capture and Streams" compatible {@code getUserMedia} + * implementation. + * See: https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-enumeratedevices + * + * @param {*} constraints + * @returns {Promise} + */ + getUserMedia(constraints) { + return (0, _getUserMedia.default)(constraints); + } +} + +/** + * Define the `onxxx` event handlers. + */ +const proto = MediaDevices.prototype; +(0, _index.defineEventAttribute)(proto, 'devicechange'); +var _default = new MediaDevices(); +exports.default = _default; +//# sourceMappingURL=MediaDevices.js.map \ No newline at end of file diff --git a/lib/commonjs/MediaDevices.js.map b/lib/commonjs/MediaDevices.js.map new file mode 100644 index 000000000..94974dcba --- /dev/null +++ b/lib/commonjs/MediaDevices.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_index","require","_reactNative","_getDisplayMedia","_interopRequireDefault","_getUserMedia","obj","__esModule","default","WebRTCModule","NativeModules","MediaDevices","EventTarget","enumerateDevices","Promise","resolve","getDisplayMedia","getUserMedia","constraints","proto","prototype","defineEventAttribute","_default","exports"],"sources":["MediaDevices.ts"],"sourcesContent":["import { EventTarget, Event, defineEventAttribute } from 'event-target-shim/index';\nimport { NativeModules } from 'react-native';\n\nimport getDisplayMedia from './getDisplayMedia';\nimport getUserMedia, { Constraints } from './getUserMedia';\n\nconst { WebRTCModule } = NativeModules;\n\ntype MediaDevicesEventMap = {\n devicechange: Event<'devicechange'>\n}\n\nclass MediaDevices extends EventTarget {\n /**\n * W3C \"Media Capture and Streams\" compatible {@code enumerateDevices}\n * implementation.\n */\n enumerateDevices() {\n return new Promise(resolve => WebRTCModule.enumerateDevices(resolve));\n }\n\n /**\n * W3C \"Screen Capture\" compatible {@code getDisplayMedia} implementation.\n * See: https://w3c.github.io/mediacapture-screen-share/\n *\n * @returns {Promise}\n */\n getDisplayMedia() {\n return getDisplayMedia();\n }\n\n /**\n * W3C \"Media Capture and Streams\" compatible {@code getUserMedia}\n * implementation.\n * See: https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-enumeratedevices\n *\n * @param {*} constraints\n * @returns {Promise}\n */\n getUserMedia(constraints: Constraints) {\n return getUserMedia(constraints);\n }\n}\n\n/**\n * Define the `onxxx` event handlers.\n */\nconst proto = MediaDevices.prototype;\n\ndefineEventAttribute(proto, 'devicechange');\n\n\nexport default new MediaDevices();\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,aAAA,GAAAD,sBAAA,CAAAH,OAAA;AAA2D,SAAAG,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE3D,MAAM;EAAEG;AAAa,CAAC,GAAGC,0BAAa;AAMtC,MAAMC,YAAY,SAASC,kBAAW,CAAuB;EACzD;AACJ;AACA;AACA;EACIC,gBAAgBA,CAAA,EAAG;IACf,OAAO,IAAIC,OAAO,CAACC,OAAO,IAAIN,YAAY,CAACI,gBAAgB,CAACE,OAAO,CAAC,CAAC;EACzE;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACIC,eAAeA,CAAA,EAAG;IACd,OAAO,IAAAA,wBAAe,EAAC,CAAC;EAC5B;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;EACIC,YAAYA,CAACC,WAAwB,EAAE;IACnC,OAAO,IAAAD,qBAAY,EAACC,WAAW,CAAC;EACpC;AACJ;;AAEA;AACA;AACA;AACA,MAAMC,KAAK,GAAGR,YAAY,CAACS,SAAS;AAEpC,IAAAC,2BAAoB,EAACF,KAAK,EAAE,cAAc,CAAC;AAAC,IAAAG,QAAA,GAG7B,IAAIX,YAAY,CAAC,CAAC;AAAAY,OAAA,CAAAf,OAAA,GAAAc,QAAA"} \ No newline at end of file diff --git a/lib/commonjs/MediaStream.js b/lib/commonjs/MediaStream.js new file mode 100644 index 000000000..4c9653fc6 --- /dev/null +++ b/lib/commonjs/MediaStream.js @@ -0,0 +1,137 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _index = require("event-target-shim/index"); +var _reactNative = require("react-native"); +var _MediaStreamTrack = _interopRequireDefault(require("./MediaStreamTrack")); +var _RTCUtil = require("./RTCUtil"); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +const { + WebRTCModule +} = _reactNative.NativeModules; +class MediaStream extends _index.EventTarget { + /** + * The identifier of this MediaStream unique within the associated + * WebRTCModule instance. As the id of a remote MediaStream instance is unique + * only within the associated RTCPeerConnection, it is not sufficiently unique + * to identify this MediaStream across multiple RTCPeerConnections and to + * unambiguously differentiate it from a local MediaStream instance not added + * to an RTCPeerConnection. + */ + + /** + * A MediaStream can be constructed in several ways, depending on the parameters + * that are passed here. + * + * - undefined: just a new stream, with no tracks. + * - MediaStream instance: a new stream, with a copy of the tracks of the passed stream. + * - Array of MediaStreamTrack: a new stream with a copy of the tracks in the array. + * - object: a new stream instance, represented by the passed info object, this is always + * done internally, when the stream is first created in native and the JS wrapper is + * built afterwards. + */ + constructor(arg) { + super(); + + // Assign a UUID to start with. It will get overridden for remote streams. + _defineProperty(this, "_tracks", []); + _defineProperty(this, "_id", void 0); + _defineProperty(this, "_reactTag", void 0); + this._id = (0, _RTCUtil.uniqueID)(); + + // Local MediaStreams are created by WebRTCModule to have their id and + // reactTag equal because WebRTCModule follows the respective standard's + // recommendation for id generation i.e. uses UUID which is unique enough + // for the purposes of reactTag. + this._reactTag = this._id; + if (typeof arg === 'undefined') { + WebRTCModule.mediaStreamCreate(this.id); + } else if (arg instanceof MediaStream) { + WebRTCModule.mediaStreamCreate(this.id); + for (const track of arg.getTracks()) { + this.addTrack(track); + } + } else if (Array.isArray(arg)) { + WebRTCModule.mediaStreamCreate(this.id); + for (const track of arg) { + this.addTrack(track); + } + } else if (typeof arg === 'object' && arg.streamId && arg.streamReactTag && arg.tracks) { + this._id = arg.streamId; + this._reactTag = arg.streamReactTag; + for (const trackInfo of arg.tracks) { + // We are not using addTrack here because the track is already part of the + // stream, so there is no need to add it on the native side. + this._tracks.push(new _MediaStreamTrack.default(trackInfo)); + } + } else { + throw new TypeError(`invalid type: ${typeof arg}`); + } + } + get id() { + return this._id; + } + get active() { + // TODO: can we reliably report this value? + + return true; + } + addTrack(track) { + const index = this._tracks.indexOf(track); + if (index !== -1) { + return; + } + this._tracks.push(track); + WebRTCModule.mediaStreamAddTrack(this._reactTag, track.remote ? track._peerConnectionId : -1, track.id); + } + removeTrack(track) { + const index = this._tracks.indexOf(track); + if (index === -1) { + return; + } + this._tracks.splice(index, 1); + WebRTCModule.mediaStreamRemoveTrack(this._reactTag, track.remote ? track._peerConnectionId : -1, track.id); + } + getTracks() { + return this._tracks.slice(); + } + getTrackById(trackId) { + return this._tracks.find(track => track.id === trackId); + } + getAudioTracks() { + return this._tracks.filter(track => track.kind === 'audio'); + } + getVideoTracks() { + return this._tracks.filter(track => track.kind === 'video'); + } + clone() { + throw new Error('Not implemented.'); + } + toURL() { + return this._reactTag; + } + release() { + let releaseTracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + const tracks = [...this._tracks]; + for (const track of tracks) { + this.removeTrack(track); + if (releaseTracks) { + track.release(); + } + } + WebRTCModule.mediaStreamRelease(this._reactTag); + } +} + +/** + * Define the `onxxx` event handlers. + */ +exports.default = MediaStream; +const proto = MediaStream.prototype; +(0, _index.defineEventAttribute)(proto, 'addtrack'); +(0, _index.defineEventAttribute)(proto, 'removetrack'); +//# sourceMappingURL=MediaStream.js.map \ No newline at end of file diff --git a/lib/commonjs/MediaStream.js.map b/lib/commonjs/MediaStream.js.map new file mode 100644 index 000000000..3b0d3e39d --- /dev/null +++ b/lib/commonjs/MediaStream.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_index","require","_reactNative","_MediaStreamTrack","_interopRequireDefault","_RTCUtil","obj","__esModule","default","_defineProperty","key","value","Object","defineProperty","enumerable","configurable","writable","WebRTCModule","NativeModules","MediaStream","EventTarget","constructor","arg","_id","uniqueID","_reactTag","mediaStreamCreate","id","track","getTracks","addTrack","Array","isArray","streamId","streamReactTag","tracks","trackInfo","_tracks","push","MediaStreamTrack","TypeError","active","index","indexOf","mediaStreamAddTrack","remote","_peerConnectionId","removeTrack","splice","mediaStreamRemoveTrack","slice","getTrackById","trackId","find","getAudioTracks","filter","kind","getVideoTracks","clone","Error","toURL","release","releaseTracks","arguments","length","undefined","mediaStreamRelease","exports","proto","prototype","defineEventAttribute"],"sources":["MediaStream.ts"],"sourcesContent":["import { EventTarget, defineEventAttribute } from 'event-target-shim/index';\nimport { NativeModules } from 'react-native';\n\nimport MediaStreamTrack, { MediaStreamTrackInfo } from './MediaStreamTrack';\nimport MediaStreamTrackEvent from './MediaStreamTrackEvent';\nimport { uniqueID } from './RTCUtil';\n\nconst { WebRTCModule } = NativeModules;\n\ntype MediaStreamEventMap = {\n addtrack: MediaStreamTrackEvent<'addtrack'>\n removetrack: MediaStreamTrackEvent<'removetrack'>\n}\n\nexport default class MediaStream extends EventTarget {\n _tracks: MediaStreamTrack[] = [];\n _id: string;\n\n /**\n * The identifier of this MediaStream unique within the associated\n * WebRTCModule instance. As the id of a remote MediaStream instance is unique\n * only within the associated RTCPeerConnection, it is not sufficiently unique\n * to identify this MediaStream across multiple RTCPeerConnections and to\n * unambiguously differentiate it from a local MediaStream instance not added\n * to an RTCPeerConnection.\n */\n _reactTag: string;\n\n /**\n * A MediaStream can be constructed in several ways, depending on the parameters\n * that are passed here.\n *\n * - undefined: just a new stream, with no tracks.\n * - MediaStream instance: a new stream, with a copy of the tracks of the passed stream.\n * - Array of MediaStreamTrack: a new stream with a copy of the tracks in the array.\n * - object: a new stream instance, represented by the passed info object, this is always\n * done internally, when the stream is first created in native and the JS wrapper is\n * built afterwards.\n */\n constructor(arg?:\n MediaStream |\n MediaStreamTrack[] |\n { streamId: string, streamReactTag: string, tracks: MediaStreamTrackInfo[] }\n ) {\n super();\n\n // Assign a UUID to start with. It will get overridden for remote streams.\n this._id = uniqueID();\n\n // Local MediaStreams are created by WebRTCModule to have their id and\n // reactTag equal because WebRTCModule follows the respective standard's\n // recommendation for id generation i.e. uses UUID which is unique enough\n // for the purposes of reactTag.\n this._reactTag = this._id;\n\n if (typeof arg === 'undefined') {\n WebRTCModule.mediaStreamCreate(this.id);\n } else if (arg instanceof MediaStream) {\n WebRTCModule.mediaStreamCreate(this.id);\n\n for (const track of arg.getTracks()) {\n this.addTrack(track);\n }\n } else if (Array.isArray(arg)) {\n WebRTCModule.mediaStreamCreate(this.id);\n\n for (const track of arg) {\n this.addTrack(track);\n }\n } else if (typeof arg === 'object' && arg.streamId && arg.streamReactTag && arg.tracks) {\n this._id = arg.streamId;\n this._reactTag = arg.streamReactTag;\n\n for (const trackInfo of arg.tracks) {\n // We are not using addTrack here because the track is already part of the\n // stream, so there is no need to add it on the native side.\n this._tracks.push(new MediaStreamTrack(trackInfo));\n }\n } else {\n throw new TypeError(`invalid type: ${typeof arg}`);\n }\n }\n\n get id(): string {\n return this._id;\n }\n\n get active(): boolean {\n // TODO: can we reliably report this value?\n\n return true;\n }\n\n addTrack(track: MediaStreamTrack): void {\n const index = this._tracks.indexOf(track);\n\n if (index !== -1) {\n return;\n }\n\n this._tracks.push(track);\n WebRTCModule.mediaStreamAddTrack(this._reactTag, track.remote ? track._peerConnectionId : -1, track.id);\n }\n\n removeTrack(track: MediaStreamTrack): void {\n const index = this._tracks.indexOf(track);\n\n if (index === -1) {\n return;\n }\n\n this._tracks.splice(index, 1);\n WebRTCModule.mediaStreamRemoveTrack(this._reactTag, track.remote ? track._peerConnectionId : -1, track.id);\n }\n\n getTracks(): MediaStreamTrack[] {\n return this._tracks.slice();\n }\n\n getTrackById(trackId): MediaStreamTrack | undefined {\n return this._tracks.find(track => track.id === trackId);\n }\n\n getAudioTracks(): MediaStreamTrack[] {\n return this._tracks.filter(track => track.kind === 'audio');\n }\n\n getVideoTracks(): MediaStreamTrack[] {\n return this._tracks.filter(track => track.kind === 'video');\n }\n\n clone(): never {\n throw new Error('Not implemented.');\n }\n\n toURL(): string {\n return this._reactTag;\n }\n\n release(releaseTracks = true): void {\n const tracks = [ ...this._tracks ];\n\n for (const track of tracks) {\n this.removeTrack(track);\n\n if (releaseTracks) {\n track.release();\n }\n }\n\n WebRTCModule.mediaStreamRelease(this._reactTag);\n }\n}\n\n/**\n * Define the `onxxx` event handlers.\n */\nconst proto = MediaStream.prototype;\n\ndefineEventAttribute(proto, 'addtrack');\ndefineEventAttribute(proto, 'removetrack');\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,iBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,IAAAI,QAAA,GAAAJ,OAAA;AAAqC,SAAAG,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,QAAAD,GAAA,IAAAJ,GAAA,IAAAM,MAAA,CAAAC,cAAA,CAAAP,GAAA,EAAAI,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAG,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAV,GAAA,CAAAI,GAAA,IAAAC,KAAA,WAAAL,GAAA;AAErC,MAAM;EAAEW;AAAa,CAAC,GAAGC,0BAAa;AAOvB,MAAMC,WAAW,SAASC,kBAAW,CAAsB;EAItE;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;;EAGI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACIC,WAAWA,CAACC,GAGoE,EAC9E;IACE,KAAK,CAAC,CAAC;;IAEP;IAAAb,eAAA,kBA/B0B,EAAE;IAAAA,eAAA;IAAAA,eAAA;IAgC5B,IAAI,CAACc,GAAG,GAAG,IAAAC,iBAAQ,EAAC,CAAC;;IAErB;IACA;IACA;IACA;IACA,IAAI,CAACC,SAAS,GAAG,IAAI,CAACF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AAC;EAC/D;EAEAE,KAAKA,CAAA,EAAU;IACX,MAAM,IAAIC,KAAK,CAAC,kBAAkB,CAAC;EACvC;EAEAC,KAAKA,CAAA,EAAW;IACZ,OAAO,IAAI,CAACnC,SAAS;EACzB;EAEAoC,OAAOA,CAAA,EAA6B;IAAA,IAA5BC,aAAa,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;IACxB,MAAM5B,MAAM,GAAG,CAAE,GAAG,IAAI,CAACE,OAAO,CAAE;IAElC,KAAK,MAAMT,KAAK,IAAIO,MAAM,EAAE;MACxB,IAAI,CAACY,WAAW,CAACnB,KAAK,CAAC;MAEvB,IAAIkC,aAAa,EAAE;QACflC,KAAK,CAACiC,OAAO,CAAC,CAAC;MACnB;IACJ;IAEA5C,YAAY,CAACiD,kBAAkB,CAAC,IAAI,CAACzC,SAAS,CAAC;EACnD;AACJ;;AAEA;AACA;AACA;AAFA0C,OAAA,CAAA3D,OAAA,GAAAW,WAAA;AAGA,MAAMiD,KAAK,GAAGjD,WAAW,CAACkD,SAAS;AAEnC,IAAAC,2BAAoB,EAACF,KAAK,EAAE,UAAU,CAAC;AACvC,IAAAE,2BAAoB,EAACF,KAAK,EAAE,aAAa,CAAC"} \ No newline at end of file diff --git a/lib/commonjs/MediaStreamError.js b/lib/commonjs/MediaStreamError.js new file mode 100644 index 000000000..a6e52cdef --- /dev/null +++ b/lib/commonjs/MediaStreamError.js @@ -0,0 +1,19 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +class MediaStreamError { + constructor(error) { + _defineProperty(this, "name", void 0); + _defineProperty(this, "message", void 0); + _defineProperty(this, "constraintName", void 0); + this.name = error.name; + this.message = error.message; + this.constraintName = error.constraintName; + } +} +exports.default = MediaStreamError; +//# sourceMappingURL=MediaStreamError.js.map \ No newline at end of file diff --git a/lib/commonjs/MediaStreamError.js.map b/lib/commonjs/MediaStreamError.js.map new file mode 100644 index 000000000..bfc1be46f --- /dev/null +++ b/lib/commonjs/MediaStreamError.js.map @@ -0,0 +1 @@ +{"version":3,"names":["MediaStreamError","constructor","error","_defineProperty","name","message","constraintName","exports","default"],"sources":["MediaStreamError.ts"],"sourcesContent":["\nexport default class MediaStreamError {\n name: string;\n message?: string;\n constraintName?: string;\n\n constructor(error) {\n this.name = error.name;\n this.message = error.message;\n this.constraintName = error.constraintName;\n }\n}\n"],"mappings":";;;;;;;AACe,MAAMA,gBAAgB,CAAC;EAKlCC,WAAWA,CAACC,KAAK,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACf,IAAI,CAACC,IAAI,GAAGF,KAAK,CAACE,IAAI;IACtB,IAAI,CAACC,OAAO,GAAGH,KAAK,CAACG,OAAO;IAC5B,IAAI,CAACC,cAAc,GAAGJ,KAAK,CAACI,cAAc;EAC9C;AACJ;AAACC,OAAA,CAAAC,OAAA,GAAAR,gBAAA"} \ No newline at end of file diff --git a/lib/commonjs/MediaStreamErrorEvent.js b/lib/commonjs/MediaStreamErrorEvent.js new file mode 100644 index 000000000..5bb5b7c13 --- /dev/null +++ b/lib/commonjs/MediaStreamErrorEvent.js @@ -0,0 +1,17 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +class MediaStreamErrorEvent { + constructor(type, eventInitDict) { + _defineProperty(this, "type", void 0); + _defineProperty(this, "error", void 0); + this.type = type.toString(); + Object.assign(this, eventInitDict); + } +} +exports.default = MediaStreamErrorEvent; +//# sourceMappingURL=MediaStreamErrorEvent.js.map \ No newline at end of file diff --git a/lib/commonjs/MediaStreamErrorEvent.js.map b/lib/commonjs/MediaStreamErrorEvent.js.map new file mode 100644 index 000000000..3b9730d36 --- /dev/null +++ b/lib/commonjs/MediaStreamErrorEvent.js.map @@ -0,0 +1 @@ +{"version":3,"names":["MediaStreamErrorEvent","constructor","type","eventInitDict","_defineProperty","toString","Object","assign","exports","default"],"sources":["MediaStreamErrorEvent.ts"],"sourcesContent":["\nimport type MediaStreamError from './MediaStreamError';\n\nexport default class MediaStreamErrorEvent {\n type: string;\n error?: MediaStreamError;\n constructor(type, eventInitDict) {\n this.type = type.toString();\n Object.assign(this, eventInitDict);\n }\n}\n"],"mappings":";;;;;;;AAGe,MAAMA,qBAAqB,CAAC;EAGvCC,WAAWA,CAACC,IAAI,EAAEC,aAAa,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAC7B,IAAI,CAACF,IAAI,GAAGA,IAAI,CAACG,QAAQ,CAAC,CAAC;IAC3BC,MAAM,CAACC,MAAM,CAAC,IAAI,EAAEJ,aAAa,CAAC;EACtC;AACJ;AAACK,OAAA,CAAAC,OAAA,GAAAT,qBAAA"} \ No newline at end of file diff --git a/lib/commonjs/MediaStreamTrack.js b/lib/commonjs/MediaStreamTrack.js new file mode 100644 index 000000000..3af4c1367 --- /dev/null +++ b/lib/commonjs/MediaStreamTrack.js @@ -0,0 +1,188 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _index = require("event-target-shim/index"); +var _reactNative = require("react-native"); +var _EventEmitter = require("./EventEmitter"); +var _Logger = _interopRequireDefault(require("./Logger")); +var _RTCUtil = require("./RTCUtil"); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +const log = new _Logger.default('pc'); +const { + WebRTCModule +} = _reactNative.NativeModules; +class MediaStreamTrack extends _index.EventTarget { + constructor(info) { + super(); + _defineProperty(this, "_constraints", void 0); + _defineProperty(this, "_enabled", void 0); + _defineProperty(this, "_settings", void 0); + _defineProperty(this, "_muted", void 0); + _defineProperty(this, "_peerConnectionId", void 0); + _defineProperty(this, "_readyState", void 0); + _defineProperty(this, "id", void 0); + _defineProperty(this, "kind", void 0); + _defineProperty(this, "label", ''); + _defineProperty(this, "remote", void 0); + this._constraints = info.constraints || {}; + this._enabled = info.enabled; + this._settings = info.settings || {}; + this._muted = false; + this._peerConnectionId = info.peerConnectionId; + this._readyState = info.readyState; + this.id = info.id; + this.kind = info.kind; + this.remote = info.remote; + if (!this.remote) { + this._registerEvents(); + } + } + get enabled() { + return this._enabled; + } + set enabled(enabled) { + if (enabled === this._enabled) { + return; + } + this._enabled = Boolean(enabled); + if (this._readyState === 'ended') { + return; + } + WebRTCModule.mediaStreamTrackSetEnabled(this.remote ? this._peerConnectionId : -1, this.id, this._enabled); + } + get muted() { + return this._muted; + } + get readyState() { + return this._readyState; + } + stop() { + this.enabled = false; + this._readyState = 'ended'; + } + + /** + * Private / custom API for switching the cameras on the fly, without the + * need for adding / removing tracks or doing any SDP renegotiation. + * + * This is how the reference application (AppRTCMobile) implements camera + * switching. + * + * @deprecated Use applyConstraints instead. + */ + _switchCamera() { + if (this.remote) { + throw new Error('Not implemented for remote tracks'); + } + if (this.kind !== 'video') { + throw new Error('Only implemented for video tracks'); + } + const constraints = (0, _RTCUtil.deepClone)(this._settings); + delete constraints.deviceId; + constraints.facingMode = this._settings.facingMode === 'user' ? 'environment' : 'user'; + this.applyConstraints(constraints); + } + _setVideoEffects(names) { + if (this.remote) { + throw new Error('Not implemented for remote tracks'); + } + if (this.kind !== 'video') { + throw new Error('Only implemented for video tracks'); + } + WebRTCModule.mediaStreamTrackSetVideoEffects(this.id, names); + } + _setVideoEffect(name) { + this._setVideoEffects([name]); + } + + /** + * Internal function which is used to set the muted state on remote tracks and + * emit the mute / unmute event. + * + * @param muted Whether the track should be marked as muted / unmuted. + */ + _setMutedInternal(muted) { + if (!this.remote) { + throw new Error('Track is not remote!'); + } + this._muted = muted; + this.dispatchEvent(new _index.Event(muted ? 'mute' : 'unmute')); + } + + /** + * Custom API for setting the volume on an individual audio track. + * + * @param volume a gain value in the range of 0-10. defaults to 1.0 + */ + _setVolume(volume) { + if (this.kind !== 'audio') { + throw new Error('Only implemented for audio tracks'); + } + WebRTCModule.mediaStreamTrackSetVolume(this.remote ? this._peerConnectionId : -1, this.id, volume); + } + + /** + * Applies a new set of constraints to the track. + * + * @param constraints An object listing the constraints + * to apply to the track's constrainable properties; any existing + * constraints are replaced with the new values specified, and any + * constrainable properties not included are restored to their default + * constraints. If this parameter is omitted, all currently set custom + * constraints are cleared. + */ + async applyConstraints(constraints) { + if (this.kind !== 'video') { + log.info(`Only implemented for video tracks, ignoring applyConstraints for ${this.id}`); + return; + } + const normalized = (0, _RTCUtil.normalizeConstraints)({ + video: constraints !== null && constraints !== void 0 ? constraints : true + }); + this._settings = await WebRTCModule.mediaStreamTrackApplyConstraints(this.id, normalized.video); + this._constraints = constraints !== null && constraints !== void 0 ? constraints : {}; + } + clone() { + throw new Error('Not implemented.'); + } + getCapabilities() { + throw new Error('Not implemented.'); + } + getConstraints() { + return (0, _RTCUtil.deepClone)(this._constraints); + } + getSettings() { + return (0, _RTCUtil.deepClone)(this._settings); + } + _registerEvents() { + (0, _EventEmitter.addListener)(this, 'mediaStreamTrackEnded', ev => { + if (ev.trackId !== this.id || this._readyState === 'ended') { + return; + } + log.debug(`${this.id} mediaStreamTrackEnded`); + this._readyState = 'ended'; + this.dispatchEvent(new _index.Event('ended')); + }); + } + release() { + if (this.remote) { + return; + } + (0, _EventEmitter.removeListener)(this); + WebRTCModule.mediaStreamTrackRelease(this.id); + } +} + +/** + * Define the `onxxx` event handlers. + */ +exports.default = MediaStreamTrack; +const proto = MediaStreamTrack.prototype; +(0, _index.defineEventAttribute)(proto, 'ended'); +(0, _index.defineEventAttribute)(proto, 'mute'); +(0, _index.defineEventAttribute)(proto, 'unmute'); +//# sourceMappingURL=MediaStreamTrack.js.map \ No newline at end of file diff --git a/lib/commonjs/MediaStreamTrack.js.map b/lib/commonjs/MediaStreamTrack.js.map new file mode 100644 index 000000000..e7dc6fca6 --- /dev/null +++ b/lib/commonjs/MediaStreamTrack.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_index","require","_reactNative","_EventEmitter","_Logger","_interopRequireDefault","_RTCUtil","obj","__esModule","default","_defineProperty","key","value","Object","defineProperty","enumerable","configurable","writable","log","Logger","WebRTCModule","NativeModules","MediaStreamTrack","EventTarget","constructor","info","_constraints","constraints","_enabled","enabled","_settings","settings","_muted","_peerConnectionId","peerConnectionId","_readyState","readyState","id","kind","remote","_registerEvents","Boolean","mediaStreamTrackSetEnabled","muted","stop","_switchCamera","Error","deepClone","deviceId","facingMode","applyConstraints","_setVideoEffects","names","mediaStreamTrackSetVideoEffects","_setVideoEffect","name","_setMutedInternal","dispatchEvent","Event","_setVolume","volume","mediaStreamTrackSetVolume","normalized","normalizeConstraints","video","mediaStreamTrackApplyConstraints","clone","getCapabilities","getConstraints","getSettings","addListener","ev","trackId","debug","release","removeListener","mediaStreamTrackRelease","exports","proto","prototype","defineEventAttribute"],"sources":["MediaStreamTrack.ts"],"sourcesContent":["import { EventTarget, Event, defineEventAttribute } from 'event-target-shim/index';\nimport { NativeModules } from 'react-native';\n\nimport { MediaTrackConstraints } from './Constraints';\nimport { addListener, removeListener } from './EventEmitter';\nimport Logger from './Logger';\nimport { deepClone, normalizeConstraints } from './RTCUtil';\n\nconst log = new Logger('pc');\nconst { WebRTCModule } = NativeModules;\n\n\ntype MediaStreamTrackState = 'live' | 'ended';\n\nexport type MediaStreamTrackInfo = {\n id: string;\n kind: string;\n remote: boolean;\n constraints: object;\n enabled: boolean;\n settings: object;\n peerConnectionId: number;\n readyState: MediaStreamTrackState;\n}\n\nexport type MediaTrackSettings = {\n width?: number;\n height?: number;\n frameRate?: number;\n facingMode?: string;\n deviceId?: string;\n groupId?: string;\n}\n\ntype MediaStreamTrackEventMap = {\n ended: Event<'ended'>;\n mute: Event<'mute'>;\n unmute: Event<'unmute'>;\n}\n\nexport default class MediaStreamTrack extends EventTarget {\n _constraints: MediaTrackConstraints;\n _enabled: boolean;\n _settings: MediaTrackSettings;\n _muted: boolean;\n _peerConnectionId: number;\n _readyState: MediaStreamTrackState;\n\n readonly id: string;\n readonly kind: string;\n readonly label: string = '';\n readonly remote: boolean;\n\n constructor(info: MediaStreamTrackInfo) {\n super();\n\n this._constraints = info.constraints || {};\n this._enabled = info.enabled;\n this._settings = info.settings || {};\n this._muted = false;\n this._peerConnectionId = info.peerConnectionId;\n this._readyState = info.readyState;\n\n this.id = info.id;\n this.kind = info.kind;\n this.remote = info.remote;\n\n if (!this.remote) {\n this._registerEvents();\n }\n }\n\n get enabled(): boolean {\n return this._enabled;\n }\n\n set enabled(enabled: boolean) {\n if (enabled === this._enabled) {\n return;\n }\n\n this._enabled = Boolean(enabled);\n\n if (this._readyState === 'ended') {\n return;\n }\n\n WebRTCModule.mediaStreamTrackSetEnabled(this.remote ? this._peerConnectionId : -1, this.id, this._enabled);\n }\n\n get muted(): boolean {\n return this._muted;\n }\n\n get readyState(): string {\n return this._readyState;\n }\n\n stop(): void {\n this.enabled = false;\n this._readyState = 'ended';\n }\n\n /**\n * Private / custom API for switching the cameras on the fly, without the\n * need for adding / removing tracks or doing any SDP renegotiation.\n *\n * This is how the reference application (AppRTCMobile) implements camera\n * switching.\n *\n * @deprecated Use applyConstraints instead.\n */\n _switchCamera(): void {\n if (this.remote) {\n throw new Error('Not implemented for remote tracks');\n }\n\n if (this.kind !== 'video') {\n throw new Error('Only implemented for video tracks');\n }\n\n const constraints = deepClone(this._settings);\n\n delete constraints.deviceId;\n constraints.facingMode = this._settings.facingMode === 'user' ? 'environment' : 'user';\n\n this.applyConstraints(constraints);\n }\n\n _setVideoEffects(names: string[]) {\n if (this.remote) {\n throw new Error('Not implemented for remote tracks');\n }\n\n if (this.kind !== 'video') {\n throw new Error('Only implemented for video tracks');\n }\n\n WebRTCModule.mediaStreamTrackSetVideoEffects(this.id, names);\n }\n\n _setVideoEffect(name: string) {\n this._setVideoEffects([ name ]);\n }\n\n /**\n * Internal function which is used to set the muted state on remote tracks and\n * emit the mute / unmute event.\n *\n * @param muted Whether the track should be marked as muted / unmuted.\n */\n _setMutedInternal(muted: boolean) {\n if (!this.remote) {\n throw new Error('Track is not remote!');\n }\n\n this._muted = muted;\n this.dispatchEvent(new Event(muted ? 'mute' : 'unmute'));\n }\n\n /**\n * Custom API for setting the volume on an individual audio track.\n *\n * @param volume a gain value in the range of 0-10. defaults to 1.0\n */\n _setVolume(volume: number) {\n if (this.kind !== 'audio') {\n throw new Error('Only implemented for audio tracks');\n }\n\n WebRTCModule.mediaStreamTrackSetVolume(this.remote ? this._peerConnectionId : -1, this.id, volume);\n }\n\n /**\n * Applies a new set of constraints to the track.\n *\n * @param constraints An object listing the constraints\n * to apply to the track's constrainable properties; any existing\n * constraints are replaced with the new values specified, and any\n * constrainable properties not included are restored to their default\n * constraints. If this parameter is omitted, all currently set custom\n * constraints are cleared.\n */\n async applyConstraints(constraints?: MediaTrackConstraints): Promise {\n if (this.kind !== 'video') {\n log.info(`Only implemented for video tracks, ignoring applyConstraints for ${this.id}`);\n\n return;\n }\n\n const normalized = normalizeConstraints({ video: constraints ?? true });\n\n this._settings = await WebRTCModule.mediaStreamTrackApplyConstraints(this.id, normalized.video);\n this._constraints = constraints ?? {};\n }\n\n clone(): never {\n throw new Error('Not implemented.');\n }\n\n getCapabilities(): never {\n throw new Error('Not implemented.');\n }\n\n getConstraints() {\n return deepClone(this._constraints);\n }\n\n getSettings(): MediaTrackSettings {\n return deepClone(this._settings);\n }\n\n _registerEvents(): void {\n addListener(this, 'mediaStreamTrackEnded', (ev: any) => {\n if (ev.trackId !== this.id || this._readyState === 'ended') {\n return;\n }\n\n log.debug(`${this.id} mediaStreamTrackEnded`);\n this._readyState = 'ended';\n\n this.dispatchEvent(new Event('ended'));\n });\n }\n\n release(): void {\n if (this.remote) {\n return;\n }\n\n removeListener(this);\n WebRTCModule.mediaStreamTrackRelease(this.id);\n }\n}\n\n/**\n * Define the `onxxx` event handlers.\n */\nconst proto = MediaStreamTrack.prototype;\n\ndefineEventAttribute(proto, 'ended');\ndefineEventAttribute(proto, 'mute');\ndefineEventAttribute(proto, 'unmute');\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAGA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AAA4D,SAAAI,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,QAAAD,GAAA,IAAAJ,GAAA,IAAAM,MAAA,CAAAC,cAAA,CAAAP,GAAA,EAAAI,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAG,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAV,GAAA,CAAAI,GAAA,IAAAC,KAAA,WAAAL,GAAA;AAE5D,MAAMW,GAAG,GAAG,IAAIC,eAAM,CAAC,IAAI,CAAC;AAC5B,MAAM;EAAEC;AAAa,CAAC,GAAGC,0BAAa;AA+BvB,MAAMC,gBAAgB,SAASC,kBAAW,CAA2B;EAahFC,WAAWA,CAACC,IAA0B,EAAE;IACpC,KAAK,CAAC,CAAC;IAACf,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA,gBAJa,EAAE;IAAAA,eAAA;IAMvB,IAAI,CAACgB,YAAY,GAAGD,IAAI,CAACE,WAAW,IAAI,CAAC,CAAC;IAC1C,IAAI,CAACC,QAAQ,GAAGH,IAAI,CAACI,OAAO;IAC5B,IAAI,C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CAACC,OAAO,KAAK,IAAI,CAACnC,EAAE,IAAI,IAAI,CAACF,WAAW,KAAK,OAAO,EAAE;QACxD;MACJ;MAEAjB,GAAG,CAACuD,KAAK,CAAE,GAAE,IAAI,CAACpC,EAAG,wBAAuB,CAAC;MAC7C,IAAI,CAACF,WAAW,GAAG,OAAO;MAE1B,IAAI,CAACsB,aAAa,CAAC,IAAIC,YAAK,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC,CAAC;EACN;EAEAgB,OAAOA,CAAA,EAAS;IACZ,IAAI,IAAI,CAACnC,MAAM,EAAE;MACb;IACJ;IAEA,IAAAoC,4BAAc,EAAC,IAAI,CAAC;IACpBvD,YAAY,CAACwD,uBAAuB,CAAC,IAAI,CAACvC,EAAE,CAAC;EACjD;AACJ;;AAEA;AACA;AACA;AAFAwC,OAAA,CAAApE,OAAA,GAAAa,gBAAA;AAGA,MAAMwD,KAAK,GAAGxD,gBAAgB,CAACyD,SAAS;AAExC,IAAAC,2BAAoB,EAACF,KAAK,EAAE,OAAO,CAAC;AACpC,IAAAE,2BAAoB,EAACF,KAAK,EAAE,MAAM,CAAC;AACnC,IAAAE,2BAAoB,EAACF,KAAK,EAAE,QAAQ,CAAC"} \ No newline at end of file diff --git a/lib/commonjs/MediaStreamTrackEvent.js b/lib/commonjs/MediaStreamTrackEvent.js new file mode 100644 index 000000000..c90f7c34b --- /dev/null +++ b/lib/commonjs/MediaStreamTrackEvent.js @@ -0,0 +1,26 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _index = require("event-target-shim/index"); +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +/** + * @eventClass + * This event is fired whenever the MediaStreamTrack has changed in any way. + * @param {MEDIA_STREAM_EVENTS} type - The type of event. + * @param {IMediaStreamTrackEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaStream#events MDN} for details. + */ +class MediaStreamTrackEvent extends _index.Event { + /** @eventProperty */ + + constructor(type, eventInitDict) { + super(type, eventInitDict); + _defineProperty(this, "track", void 0); + this.track = eventInitDict.track; + } +} +exports.default = MediaStreamTrackEvent; +//# sourceMappingURL=MediaStreamTrackEvent.js.map \ No newline at end of file diff --git a/lib/commonjs/MediaStreamTrackEvent.js.map b/lib/commonjs/MediaStreamTrackEvent.js.map new file mode 100644 index 000000000..95e6a5eee --- /dev/null +++ b/lib/commonjs/MediaStreamTrackEvent.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_index","require","_defineProperty","obj","key","value","Object","defineProperty","enumerable","configurable","writable","MediaStreamTrackEvent","Event","constructor","type","eventInitDict","track","exports","default"],"sources":["MediaStreamTrackEvent.ts"],"sourcesContent":["import { Event } from 'event-target-shim/index';\n\nimport type MediaStreamTrack from './MediaStreamTrack';\n\ntype MEDIA_STREAM_EVENTS = 'addtrack'| 'removetrack'\n\ninterface IMediaStreamTrackEventInitDict extends Event.EventInit {\n track: MediaStreamTrack;\n}\n\n/**\n * @eventClass\n * This event is fired whenever the MediaStreamTrack has changed in any way.\n * @param {MEDIA_STREAM_EVENTS} type - The type of event.\n * @param {IMediaStreamTrackEventInitDict} eventInitDict - The event init properties.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaStream#events MDN} for details.\n */\nexport default class MediaStreamTrackEvent extends Event {\n /** @eventProperty */\n track: MediaStreamTrack;\n constructor(type: TEventType, eventInitDict: IMediaStreamTrackEventInitDict) {\n super(type, eventInitDict);\n this.track = eventInitDict.track;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAgD,SAAAC,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,QAAAD,GAAA,IAAAD,GAAA,IAAAG,MAAA,CAAAC,cAAA,CAAAJ,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAG,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAP,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAUhD;AACA;AACA;AACA;AACA;AACA;AACA;AACe,MAAMQ,qBAAqB,SAAiDC,YAAK,CAAa;EACzG;;EAEAC,WAAWA,CAACC,IAAgB,EAAEC,aAA6C,EAAE;IACzE,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAACb,eAAA;IAC3B,IAAI,CAACc,KAAK,GAAGD,aAAa,CAACC,KAAK;EACpC;AACJ;AAACC,OAAA,CAAAC,OAAA,GAAAP,qBAAA"} \ No newline at end of file diff --git a/lib/commonjs/MessageEvent.js b/lib/commonjs/MessageEvent.js new file mode 100644 index 000000000..a4d4a53dd --- /dev/null +++ b/lib/commonjs/MessageEvent.js @@ -0,0 +1,27 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _index = require("event-target-shim/index"); +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +/** + * @eventClass + * This event is fired whenever the RTCDataChannel send message. + * @param {MESSAGE_EVENTS} type - The type of event. + * @param {IMessageEventInitDict} eventInitDict - The event init properties. + * @see + * {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/message_event#event_type MDN} for details. + */ +class MessageEvent extends _index.Event { + /** @eventProperty */ + + constructor(type, eventInitDict) { + super(type, eventInitDict); + _defineProperty(this, "data", void 0); + this.data = eventInitDict.data; + } +} +exports.default = MessageEvent; +//# sourceMappingURL=MessageEvent.js.map \ No newline at end of file diff --git a/lib/commonjs/MessageEvent.js.map b/lib/commonjs/MessageEvent.js.map new file mode 100644 index 000000000..3c23f7281 --- /dev/null +++ b/lib/commonjs/MessageEvent.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_index","require","_defineProperty","obj","key","value","Object","defineProperty","enumerable","configurable","writable","MessageEvent","Event","constructor","type","eventInitDict","data","exports","default"],"sources":["MessageEvent.ts"],"sourcesContent":["import { Event } from 'event-target-shim/index';\n\nexport type MessageEventData = string | ArrayBuffer | Blob;\n\ntype MESSAGE_EVENTS = 'message' | 'messageerror';\n\ninterface IMessageEventInitDict extends Event.EventInit {\n data: MessageEventData;\n}\n\n/**\n * @eventClass\n * This event is fired whenever the RTCDataChannel send message.\n * @param {MESSAGE_EVENTS} type - The type of event.\n * @param {IMessageEventInitDict} eventInitDict - The event init properties.\n * @see\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/message_event#event_type MDN} for details.\n */\nexport default class MessageEvent extends Event {\n /** @eventProperty */\n data: MessageEventData;\n constructor(type: TEventType, eventInitDict: IMessageEventInitDict) {\n super(type, eventInitDict);\n this.data = eventInitDict.data;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAgD,SAAAC,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,QAAAD,GAAA,IAAAD,GAAA,IAAAG,MAAA,CAAAC,cAAA,CAAAJ,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAG,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAP,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAUhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,MAAMQ,YAAY,SAA4CC,YAAK,CAAa;EAC3F;;EAEAC,WAAWA,CAACC,IAAgB,EAAEC,aAAoC,EAAE;IAChE,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAACb,eAAA;IAC3B,IAAI,CAACc,IAAI,GAAGD,aAAa,CAACC,IAAI;EAClC;AACJ;AAACC,OAAA,CAAAC,OAAA,GAAAP,YAAA"} \ No newline at end of file diff --git a/lib/commonjs/Permissions.js b/lib/commonjs/Permissions.js new file mode 100644 index 000000000..57558ba10 --- /dev/null +++ b/lib/commonjs/Permissions.js @@ -0,0 +1,116 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _reactNative = require("react-native"); +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +const { + WebRTCModule +} = _reactNative.NativeModules; + +/** + * Type declaration for a permissions descriptor. + */ + +/** + * Class implementing a subset of W3C's Permissions API as defined by: + * https://www.w3.org/TR/permissions/ + */ +class Permissions { + constructor() { + _defineProperty(this, "RESULT", { + DENIED: 'denied', + GRANTED: 'granted', + PROMPT: 'prompt' + }); + _defineProperty(this, "VALID_PERMISSIONS", ['camera', 'microphone']); + _defineProperty(this, "_lastReq", Promise.resolve()); + } + /** + * Possible result values for {@link query}, in accordance with: + * https://www.w3.org/TR/permissions/#status-of-a-permission + */ + /** + * This implementation only supports requesting these permissions, a subset + * of: https://www.w3.org/TR/permissions/#permission-registry + */ + /** + * Helper for requesting Android permissions. On Android only one permission + * can be requested at a time (unless the multi-permission API is used, + * but we are not using that for symmetry with the W3C API for querying) + * so we'll queue them up. + * + * @param perm - The requested permission from + * {@link PermissionsAndroid.PERMISSIONS} + * https://facebook.github.io/react-native/docs/permissionsandroid#permissions-that-require-prompting-the-user + */ + _requestPermissionAndroid(perm) { + return new Promise(resolve => { + _reactNative.PermissionsAndroid.request(perm).then(granted => resolve(granted === _reactNative.PermissionsAndroid.RESULTS.GRANTED), () => resolve(false)); + }); + } + + /** + * Validates the given permission descriptor. + */ + _validatePermissionDescriptior(permissionDesc) { + if (typeof permissionDesc !== 'object') { + throw new TypeError('Argument 1 of Permissions.query is not an object.'); + } + if (typeof permissionDesc.name === 'undefined') { + throw new TypeError('Missing required \'name\' member of PermissionDescriptor.'); + } + if (this.VALID_PERMISSIONS.indexOf(permissionDesc.name) === -1) { + throw new TypeError('\'name\' member of PermissionDescriptor is not a valid value for enumeration PermissionName.'); + } + } + + /** + * Method for querying the status of a permission, according to: + * https://www.w3.org/TR/permissions/#permissions-interface + */ + query(permissionDesc) { + try { + this._validatePermissionDescriptior(permissionDesc); + } catch (e) { + return Promise.reject(e); + } + if (_reactNative.Platform.OS === 'android') { + const perm = permissionDesc.name === 'camera' ? _reactNative.PermissionsAndroid.PERMISSIONS.CAMERA : _reactNative.PermissionsAndroid.PERMISSIONS.RECORD_AUDIO; + return new Promise(resolve => { + _reactNative.PermissionsAndroid.check(perm).then(granted => resolve(granted ? this.RESULT.GRANTED : this.RESULT.PROMPT), () => resolve(this.RESULT.PROMPT)); + }); + } else if (_reactNative.Platform.OS === 'ios' || _reactNative.Platform.OS === 'macos') { + return WebRTCModule.checkPermission(permissionDesc.name); + } else { + return Promise.reject(new TypeError('Unsupported platform.')); + } + } + + /** + * Custom method NOT defined by W3C's permissions API, which allows the + * caller to request a permission. + */ + request(permissionDesc) { + try { + this._validatePermissionDescriptior(permissionDesc); + } catch (e) { + return Promise.reject(e); + } + if (_reactNative.Platform.OS === 'android') { + const perm = permissionDesc.name === 'camera' ? _reactNative.PermissionsAndroid.PERMISSIONS.CAMERA : _reactNative.PermissionsAndroid.PERMISSIONS.RECORD_AUDIO; + const requestPermission = () => this._requestPermissionAndroid(perm); + this._lastReq = this._lastReq.then(requestPermission, requestPermission); + return this._lastReq; + } else if (_reactNative.Platform.OS === 'ios' || _reactNative.Platform.OS === 'macos') { + return WebRTCModule.requestPermission(permissionDesc.name); + } else { + return Promise.reject(new TypeError('Unsupported platform.')); + } + } +} +var _default = new Permissions(); +exports.default = _default; +//# sourceMappingURL=Permissions.js.map \ No newline at end of file diff --git a/lib/commonjs/Permissions.js.map b/lib/commonjs/Permissions.js.map new file mode 100644 index 000000000..ae9fef92a --- /dev/null +++ b/lib/commonjs/Permissions.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_reactNative","require","_defineProperty","obj","key","value","Object","defineProperty","enumerable","configurable","writable","WebRTCModule","NativeModules","Permissions","constructor","DENIED","GRANTED","PROMPT","Promise","resolve","_requestPermissionAndroid","perm","PermissionsAndroid","request","then","granted","RESULTS","_validatePermissionDescriptior","permissionDesc","TypeError","name","VALID_PERMISSIONS","indexOf","query","e","reject","Platform","OS","PERMISSIONS","CAMERA","RECORD_AUDIO","check","RESULT","checkPermission","requestPermission","_lastReq","_default","exports","default"],"sources":["Permissions.ts"],"sourcesContent":["\nimport { NativeModules, Permission, PermissionsAndroid, Platform } from 'react-native';\n\nconst { WebRTCModule } = NativeModules;\n\n/**\n * Type declaration for a permissions descriptor.\n */\ntype PermissionDescriptor = {\n name: string;\n};\n\n/**\n * Class implementing a subset of W3C's Permissions API as defined by:\n * https://www.w3.org/TR/permissions/\n */\nclass Permissions {\n /**\n * Possible result values for {@link query}, in accordance with:\n * https://www.w3.org/TR/permissions/#status-of-a-permission\n */\n RESULT = {\n DENIED: 'denied',\n GRANTED: 'granted',\n PROMPT: 'prompt'\n };\n\n /**\n * This implementation only supports requesting these permissions, a subset\n * of: https://www.w3.org/TR/permissions/#permission-registry\n */\n VALID_PERMISSIONS = [ 'camera', 'microphone' ];\n\n _lastReq: Promise = Promise.resolve();\n\n /**\n * Helper for requesting Android permissions. On Android only one permission\n * can be requested at a time (unless the multi-permission API is used,\n * but we are not using that for symmetry with the W3C API for querying)\n * so we'll queue them up.\n *\n * @param perm - The requested permission from\n * {@link PermissionsAndroid.PERMISSIONS}\n * https://facebook.github.io/react-native/docs/permissionsandroid#permissions-that-require-prompting-the-user\n */\n _requestPermissionAndroid(perm: Permission) {\n return new Promise(resolve => {\n PermissionsAndroid.request(perm).then(\n granted => resolve(granted === PermissionsAndroid.RESULTS.GRANTED),\n () => resolve(false)\n );\n });\n }\n\n /**\n * Validates the given permission descriptor.\n */\n _validatePermissionDescriptior(permissionDesc) {\n if (typeof permissionDesc !== 'object') {\n throw new TypeError('Argument 1 of Permissions.query is not an object.');\n }\n\n if (typeof permissionDesc.name === 'undefined') {\n throw new TypeError('Missing required \\'name\\' member of PermissionDescriptor.');\n }\n\n if (this.VALID_PERMISSIONS.indexOf(permissionDesc.name) === -1) {\n throw new TypeError(\n '\\'name\\' member of PermissionDescriptor is not a valid value for enumeration PermissionName.'\n );\n }\n }\n\n /**\n * Method for querying the status of a permission, according to:\n * https://www.w3.org/TR/permissions/#permissions-interface\n */\n query(permissionDesc: PermissionDescriptor) {\n try {\n this._validatePermissionDescriptior(permissionDesc);\n } catch (e) {\n return Promise.reject(e);\n }\n\n if (Platform.OS === 'android') {\n const perm =\n permissionDesc.name === 'camera'\n ? PermissionsAndroid.PERMISSIONS.CAMERA\n : PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;\n\n return new Promise(resolve => {\n PermissionsAndroid.check(perm).then(\n granted => resolve(granted ? this.RESULT.GRANTED : this.RESULT.PROMPT),\n () => resolve(this.RESULT.PROMPT)\n );\n });\n } else if (Platform.OS === 'ios' || Platform.OS === 'macos') {\n return WebRTCModule.checkPermission(permissionDesc.name);\n } else {\n return Promise.reject(new TypeError('Unsupported platform.'));\n }\n }\n\n /**\n * Custom method NOT defined by W3C's permissions API, which allows the\n * caller to request a permission.\n */\n request(permissionDesc: PermissionDescriptor) {\n try {\n this._validatePermissionDescriptior(permissionDesc);\n } catch (e) {\n return Promise.reject(e);\n }\n\n if (Platform.OS === 'android') {\n const perm =\n permissionDesc.name === 'camera'\n ? PermissionsAndroid.PERMISSIONS.CAMERA\n : PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;\n const requestPermission = () => this._requestPermissionAndroid(perm);\n\n this._lastReq = this._lastReq.then(requestPermission, requestPermission);\n\n return this._lastReq;\n } else if (Platform.OS === 'ios' || Platform.OS === 'macos') {\n return WebRTCModule.requestPermission(permissionDesc.name);\n } else {\n return Promise.reject(new TypeError('Unsupported platform.'));\n }\n }\n}\n\nexport default new Permissions();\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAuF,SAAAC,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,QAAAD,GAAA,IAAAD,GAAA,IAAAG,MAAA,CAAAC,cAAA,CAAAJ,GAAA,E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;IAEA,IAAIE,qBAAQ,CAACC,EAAE,KAAK,SAAS,EAAE;MAC3B,MAAMhB,IAAI,GACNO,cAAc,CAACE,IAAI,KAAK,QAAQ,GAC1BR,+BAAkB,CAACgB,WAAW,CAACC,MAAM,GACrCjB,+BAAkB,CAACgB,WAAW,CAACE,YAAY;MACrD,MAAMI,iBAAiB,GAAGA,CAAA,KAAM,IAAI,CAACxB,yBAAyB,CAACC,IAAI,CAAC;MAEpE,IAAI,CAACwB,QAAQ,GAAG,IAAI,CAACA,QAAQ,CAACrB,IAAI,CAACoB,iBAAiB,EAAEA,iBAAiB,CAAC;MAExE,OAAO,IAAI,CAACC,QAAQ;IACxB,CAAC,MAAM,IAAIT,qBAAQ,CAACC,EAAE,KAAK,KAAK,IAAID,qBAAQ,CAACC,EAAE,KAAK,OAAO,EAAE;MACzD,OAAO1B,YAAY,CAACiC,iBAAiB,CAAChB,cAAc,CAACE,IAAI,CAAC;IAC9D,CAAC,MAAM;MACH,OAAOZ,OAAO,CAACiB,MAAM,CAAC,IAAIN,SAAS,CAAC,uBAAuB,CAAC,CAAC;IACjE;EACJ;AACJ;AAAC,IAAAiB,QAAA,GAEc,IAAIjC,WAAW,CAAC,CAAC;AAAAkC,OAAA,CAAAC,OAAA,GAAAF,QAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCAudioSession.js b/lib/commonjs/RTCAudioSession.js new file mode 100644 index 000000000..4d4eafdc5 --- /dev/null +++ b/lib/commonjs/RTCAudioSession.js @@ -0,0 +1,33 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _reactNative = require("react-native"); +const { + WebRTCModule +} = _reactNative.NativeModules; +class RTCAudioSession { + /** + * To be called when CallKit activates the audio session. + */ + static audioSessionDidActivate() { + // Only valid for iOS + if (_reactNative.Platform.OS === 'ios') { + WebRTCModule.audioSessionDidActivate(); + } + } + + /** + * To be called when CallKit deactivates the audio session. + */ + static audioSessionDidDeactivate() { + // Only valid for iOS + if (_reactNative.Platform.OS === 'ios') { + WebRTCModule.audioSessionDidDeactivate(); + } + } +} +exports.default = RTCAudioSession; +//# sourceMappingURL=RTCAudioSession.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCAudioSession.js.map b/lib/commonjs/RTCAudioSession.js.map new file mode 100644 index 000000000..3ac249e51 --- /dev/null +++ b/lib/commonjs/RTCAudioSession.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_reactNative","require","WebRTCModule","NativeModules","RTCAudioSession","audioSessionDidActivate","Platform","OS","audioSessionDidDeactivate","exports","default"],"sources":["RTCAudioSession.ts"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\n\nconst { WebRTCModule } = NativeModules;\n\nexport default class RTCAudioSession {\n /**\n * To be called when CallKit activates the audio session.\n */\n static audioSessionDidActivate() {\n // Only valid for iOS\n if (Platform.OS === 'ios') {\n WebRTCModule.audioSessionDidActivate();\n }\n }\n\n /**\n * To be called when CallKit deactivates the audio session.\n */\n static audioSessionDidDeactivate() {\n // Only valid for iOS\n if (Platform.OS === 'ios') {\n WebRTCModule.audioSessionDidDeactivate();\n }\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAM;EAAEC;AAAa,CAAC,GAAGC,0BAAa;AAEvB,MAAMC,eAAe,CAAC;EACjC;AACJ;AACA;EACI,OAAOC,uBAAuBA,CAAA,EAAG;IAC7B;IACA,IAAIC,qBAAQ,CAACC,EAAE,KAAK,KAAK,EAAE;MACvBL,YAAY,CAACG,uBAAuB,CAAC,CAAC;IAC1C;EACJ;;EAEA;AACJ;AACA;EACI,OAAOG,yBAAyBA,CAAA,EAAG;IAC/B;IACA,IAAIF,qBAAQ,CAACC,EAAE,KAAK,KAAK,EAAE;MACvBL,YAAY,CAACM,yBAAyB,CAAC,CAAC;IAC5C;EACJ;AACJ;AAACC,OAAA,CAAAC,OAAA,GAAAN,eAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCDataChannel.js b/lib/commonjs/RTCDataChannel.js new file mode 100644 index 000000000..51fc497bf --- /dev/null +++ b/lib/commonjs/RTCDataChannel.js @@ -0,0 +1,165 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var base64 = _interopRequireWildcard(require("base64-js")); +var _index = require("event-target-shim/index"); +var _reactNative = require("react-native"); +var _EventEmitter = require("./EventEmitter"); +var _MessageEvent = _interopRequireDefault(require("./MessageEvent")); +var _RTCDataChannelEvent = _interopRequireDefault(require("./RTCDataChannelEvent")); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } +function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +const { + WebRTCModule +} = _reactNative.NativeModules; +class RTCDataChannel extends _index.EventTarget { + // we only support 'arraybuffer' + + constructor(info) { + super(); + _defineProperty(this, "_peerConnectionId", void 0); + _defineProperty(this, "_reactTag", void 0); + _defineProperty(this, "_bufferedAmount", void 0); + _defineProperty(this, "_id", void 0); + _defineProperty(this, "_label", void 0); + _defineProperty(this, "_maxPacketLifeTime", void 0); + _defineProperty(this, "_maxRetransmits", void 0); + _defineProperty(this, "_negotiated", void 0); + _defineProperty(this, "_ordered", void 0); + _defineProperty(this, "_protocol", void 0); + _defineProperty(this, "_readyState", void 0); + _defineProperty(this, "binaryType", 'arraybuffer'); + _defineProperty(this, "bufferedAmountLowThreshold", 0); + this._peerConnectionId = info.peerConnectionId; + this._reactTag = info.reactTag; + this._bufferedAmount = 0; + this._label = info.label; + this._id = info.id === -1 ? null : info.id; // null until negotiated. + this._ordered = Boolean(info.ordered); + this._maxPacketLifeTime = info.maxPacketLifeTime; + this._maxRetransmits = info.maxRetransmits; + this._protocol = info.protocol || ''; + this._negotiated = Boolean(info.negotiated); + this._readyState = info.readyState; + this._registerEvents(); + } + get bufferedAmount() { + return this._bufferedAmount; + } + get label() { + return this._label; + } + get id() { + return this._id; + } + get ordered() { + return this._ordered; + } + get maxPacketLifeTime() { + return this._maxPacketLifeTime; + } + get maxRetransmits() { + return this._maxRetransmits; + } + get protocol() { + return this._protocol; + } + get negotiated() { + return this._negotiated; + } + get readyState() { + return this._readyState; + } + send(data) { + if (typeof data === 'string') { + WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, data, 'text'); + return; + } + + // Safely convert the buffer object to an Uint8Array for base64-encoding + if (ArrayBuffer.isView(data)) { + data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength); + } else if (data instanceof ArrayBuffer) { + data = new Uint8Array(data); + } else { + throw new TypeError('Data must be either string, ArrayBuffer, or ArrayBufferView'); + } + const base64data = base64.fromByteArray(data); + WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, base64data, 'binary'); + } + close() { + if (this._readyState === 'closing' || this._readyState === 'closed') { + return; + } + WebRTCModule.dataChannelClose(this._peerConnectionId, this._reactTag); + } + _registerEvents() { + (0, _EventEmitter.addListener)(this, 'dataChannelStateChanged', ev => { + if (ev.reactTag !== this._reactTag) { + return; + } + this._readyState = ev.state; + if (this._id === null && ev.id !== -1) { + this._id = ev.id; + } + if (this._readyState === 'open') { + this.dispatchEvent(new _RTCDataChannelEvent.default('open', { + channel: this + })); + } else if (this._readyState === 'closing') { + this.dispatchEvent(new _RTCDataChannelEvent.default('closing', { + channel: this + })); + } else if (this._readyState === 'closed') { + this.dispatchEvent(new _RTCDataChannelEvent.default('close', { + channel: this + })); + + // This DataChannel is done, clean up event handlers. + (0, _EventEmitter.removeListener)(this); + WebRTCModule.dataChannelDispose(this._peerConnectionId, this._reactTag); + } + }); + (0, _EventEmitter.addListener)(this, 'dataChannelReceiveMessage', ev => { + if (ev.reactTag !== this._reactTag) { + return; + } + let data = ev.data; + if (ev.type === 'binary') { + data = base64.toByteArray(ev.data).buffer; + } + this.dispatchEvent(new _MessageEvent.default('message', { + data + })); + }); + (0, _EventEmitter.addListener)(this, 'dataChannelDidChangeBufferedAmount', ev => { + if (ev.reactTag !== this._reactTag) { + return; + } + this._bufferedAmount = ev.bufferedAmount; + if (this._bufferedAmount < this.bufferedAmountLowThreshold) { + this.dispatchEvent(new _RTCDataChannelEvent.default('bufferedamountlow', { + channel: this + })); + } + }); + } +} + +/** + * Define the `onxxx` event handlers. + */ +exports.default = RTCDataChannel; +const proto = RTCDataChannel.prototype; +(0, _index.defineEventAttribute)(proto, 'bufferedamountlow'); +(0, _index.defineEventAttribute)(proto, 'close'); +(0, _index.defineEventAttribute)(proto, 'closing'); +(0, _index.defineEventAttribute)(proto, 'error'); +(0, _index.defineEventAttribute)(proto, 'message'); +(0, _index.defineEventAttribute)(proto, 'open'); +//# sourceMappingURL=RTCDataChannel.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCDataChannel.js.map b/lib/commonjs/RTCDataChannel.js.map new file mode 100644 index 000000000..bcb62b30d --- /dev/null +++ b/lib/commonjs/RTCDataChannel.js.map @@ -0,0 +1 @@ +{"version":3,"names":["base64","_interopRequireWildcard","require","_index","_reactNative","_EventEmitter","_MessageEvent","_interopRequireDefault","_RTCDataChannelEvent","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_defineProperty","value","enumerable","configurable","writable","WebRTCModule","NativeModules","RTCDataChannel","EventTarget","constructor","info","_peerConnectionId","peerConnectionId","_reactTag","reactTag","_bufferedAmount","_label","label","_id","id","_ordered","Boolean","ordered","_maxPacketLifeTime","maxPacketLifeTime","_maxRetransmits","maxRetransmits","_protocol","protocol","_negotiated","negotiated","_readyState","readyState","_registerEvents","bufferedAmount","send","data","dataChannelSend","ArrayBuffer","isView","Uint8Array","buffer","byteOffset","byteLength","TypeError","base64data","fromByteArray","close","dataChannelClose","addListener","ev","state","dispatchEvent","RTCDataChannelEvent","channel","removeListener","dataChannelDispose","type","toByteArray","MessageEvent","bufferedAmountLowThreshold","exports","proto","defineEventAttribute"],"sources":["RTCDataChannel.ts"],"sourcesContent":["import * as base64 from 'base64-js';\nimport { EventTarget, defineEventAttribute } from 'event-target-shim/index';\nimport { NativeModules } from 'react-native';\n\nimport { addListener, removeListener } from './EventEmitter';\nimport MessageEvent from './MessageEvent';\nimport RTCDataChannelEvent from './RTCDataChannelEvent';\n\nconst { WebRTCModule } = NativeModules;\n\ntype RTCDataChannelState = 'connecting' | 'open' | 'closing' | 'closed';\n\ntype DataChannelEventMap = {\n bufferedamountlow: RTCDataChannelEvent<'bufferedamountlow'>;\n close: RTCDataChannelEvent<'close'>;\n closing: RTCDataChannelEvent<'closing'>;\n error: RTCDataChannelEvent<'error'>;\n message: MessageEvent<'message'>;\n open: RTCDataChannelEvent<'open'>;\n};\n\nexport default class RTCDataChannel extends EventTarget {\n _peerConnectionId: number;\n _reactTag: string;\n\n _bufferedAmount: number;\n _id: number;\n _label: string;\n _maxPacketLifeTime?: number;\n _maxRetransmits?: number;\n _negotiated: boolean;\n _ordered: boolean;\n _protocol: string;\n _readyState: RTCDataChannelState;\n\n binaryType = 'arraybuffer'; // we only support 'arraybuffer'\n bufferedAmountLowThreshold = 0;\n\n constructor(info) {\n super();\n\n this._peerConnectionId = info.peerConnectionId;\n this._reactTag = info.reactTag;\n\n this._bufferedAmount = 0;\n this._label = info.label;\n this._id = info.id === -1 ? null : info.id; // null until negotiated.\n this._ordered = Boolean(info.ordered);\n this._maxPacketLifeTime = info.maxPacketLifeTime;\n this._maxRetransmits = info.maxRetransmits;\n this._protocol = info.protocol || '';\n this._negotiated = Boolean(info.negotiated);\n this._readyState = info.readyState;\n\n this._registerEvents();\n }\n\n get bufferedAmount(): number {\n return this._bufferedAmount;\n }\n\n get label(): string {\n return this._label;\n }\n\n get id(): number {\n return this._id;\n }\n\n get ordered(): boolean {\n return this._ordered;\n }\n\n get maxPacketLifeTime(): number | undefined {\n return this._maxPacketLifeTime;\n }\n\n get maxRetransmits(): number | undefined {\n return this._maxRetransmits;\n }\n\n get protocol(): string {\n return this._protocol;\n }\n\n get negotiated(): boolean {\n return this._negotiated;\n }\n\n get readyState(): string {\n return this._readyState;\n }\n\n send(data: string): void;\n send(data: ArrayBuffer): void;\n send(data: ArrayBufferView): void;\n send(data: string | ArrayBuffer | ArrayBufferView): void {\n if (typeof data === 'string') {\n WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, data, 'text');\n\n return;\n }\n\n // Safely convert the buffer object to an Uint8Array for base64-encoding\n if (ArrayBuffer.isView(data)) {\n data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n } else if (data instanceof ArrayBuffer) {\n data = new Uint8Array(data);\n } else {\n throw new TypeError('Data must be either string, ArrayBuffer, or ArrayBufferView');\n }\n\n const base64data = base64.fromByteArray(data as Uint8Array);\n\n WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, base64data, 'binary');\n }\n\n close(): void {\n if (this._readyState === 'closing' || this._readyState === 'closed') {\n return;\n }\n\n WebRTCModule.dataChannelClose(this._peerConnectionId, this._reactTag);\n }\n\n _registerEvents(): void {\n addListener(this, 'dataChannelStateChanged', (ev: any) => {\n if (ev.reactTag !== this._reactTag) {\n return;\n }\n\n this._readyState = ev.state;\n\n if (this._id === null && ev.id !== -1) {\n this._id = ev.id;\n }\n\n if (this._readyState === 'open') {\n this.dispatchEvent(new RTCDataChannelEvent('open', { channel: this }));\n } else if (this._readyState === 'closing') {\n this.dispatchEvent(new RTCDataChannelEvent('closing', { channel: this }));\n } else if (this._readyState === 'closed') {\n this.dispatchEvent(new RTCDataChannelEvent('close', { channel: this }));\n\n // This DataChannel is done, clean up event handlers.\n removeListener(this);\n\n WebRTCModule.dataChannelDispose(this._peerConnectionId, this._reactTag);\n }\n });\n\n addListener(this, 'dataChannelReceiveMessage', (ev: any) => {\n if (ev.reactTag !== this._reactTag) {\n return;\n }\n\n let data = ev.data;\n\n if (ev.type === 'binary') {\n data = base64.toByteArray(ev.data).buffer;\n }\n\n this.dispatchEvent(new MessageEvent('message', { data }));\n });\n\n addListener(this, 'dataChannelDidChangeBufferedAmount', (ev: any) => {\n if (ev.reactTag !== this._reactTag) {\n return;\n }\n\n this._bufferedAmount = ev.bufferedAmount;\n\n if (this._bufferedAmount < this.bufferedAmountLowThreshold) {\n this.dispatchEvent(new RTCDataChannelEvent('bufferedamountlow', { channel: this }));\n }\n });\n }\n}\n\n/**\n * Define the `onxxx` event handlers.\n */\nconst proto = RTCDataChannel.prototype;\n\ndefineEventAttribute(proto, 'bufferedamountlow');\ndefineEventAttribute(proto, 'close');\ndefineEventAttribute(proto, 'closing');\ndefineEventAttribute(proto, 'error');\ndefineEventAttribute(proto, 'message');\ndefineEventAttribute(proto, 'open');\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,aAAA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AMuD,KAAK,GAAGvD,cAAc,CAACZ,SAAS;AAEtC,IAAAoE,2BAAoB,EAACD,KAAK,EAAE,mBAAmB,CAAC;AAChD,IAAAC,2BAAoB,EAACD,KAAK,EAAE,OAAO,CAAC;AACpC,IAAAC,2BAAoB,EAACD,KAAK,EAAE,SAAS,CAAC;AACtC,IAAAC,2BAAoB,EAACD,KAAK,EAAE,OAAO,CAAC;AACpC,IAAAC,2BAAoB,EAACD,KAAK,EAAE,SAAS,CAAC;AACtC,IAAAC,2BAAoB,EAACD,KAAK,EAAE,MAAM,CAAC"} \ No newline at end of file diff --git a/lib/commonjs/RTCDataChannelEvent.js b/lib/commonjs/RTCDataChannelEvent.js new file mode 100644 index 000000000..b41a908e9 --- /dev/null +++ b/lib/commonjs/RTCDataChannelEvent.js @@ -0,0 +1,26 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _index = require("event-target-shim/index"); +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +/** + * @eventClass + * This event is fired whenever the RTCDataChannel has changed in any way. + * @param {DATA_CHANNEL_EVENTS} type - The type of event. + * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel#events MDN} for details. + */ +class RTCDataChannelEvent extends _index.Event { + /** @eventProperty */ + + constructor(type, eventInitDict) { + super(type, eventInitDict); + _defineProperty(this, "channel", void 0); + this.channel = eventInitDict.channel; + } +} +exports.default = RTCDataChannelEvent; +//# sourceMappingURL=RTCDataChannelEvent.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCDataChannelEvent.js.map b/lib/commonjs/RTCDataChannelEvent.js.map new file mode 100644 index 000000000..2f8b5d1a3 --- /dev/null +++ b/lib/commonjs/RTCDataChannelEvent.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_index","require","_defineProperty","obj","key","value","Object","defineProperty","enumerable","configurable","writable","RTCDataChannelEvent","Event","constructor","type","eventInitDict","channel","exports","default"],"sources":["RTCDataChannelEvent.ts"],"sourcesContent":["import { Event } from 'event-target-shim/index';\n\nimport type RTCDataChannel from './RTCDataChannel';\n\ntype DATA_CHANNEL_EVENTS = 'open'| 'message'| 'bufferedamountlow'| 'closing'| 'close'| 'error' | 'datachannel';\n\ninterface IRTCDataChannelEventInitDict extends Event.EventInit {\n channel: RTCDataChannel;\n}\n\n\n/**\n * @eventClass\n * This event is fired whenever the RTCDataChannel has changed in any way.\n * @param {DATA_CHANNEL_EVENTS} type - The type of event.\n * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel#events MDN} for details.\n */\nexport default class RTCDataChannelEvent<\nTEventType extends DATA_CHANNEL_EVENTS\n> extends Event {\n /** @eventProperty */\n channel: RTCDataChannel;\n constructor(type: TEventType, eventInitDict: IRTCDataChannelEventInitDict) {\n super(type, eventInitDict);\n this.channel = eventInitDict.channel;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAgD,SAAAC,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,QAAAD,GAAA,IAAAD,GAAA,IAAAG,MAAA,CAAAC,cAAA,CAAAJ,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAG,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAP,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAWhD;AACA;AACA;AACA;AACA;AACA;AACA;AACe,MAAMQ,mBAAmB,SAE9BC,YAAK,CAAa;EACxB;;EAEAC,WAAWA,CAACC,IAAgB,EAAEC,aAA2C,EAAE;IACvE,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAACb,eAAA;IAC3B,IAAI,CAACc,OAAO,GAAGD,aAAa,CAACC,OAAO;EACxC;AACJ;AAACC,OAAA,CAAAC,OAAA,GAAAP,mBAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCErrorEvent.js b/lib/commonjs/RTCErrorEvent.js new file mode 100644 index 000000000..c62e94395 --- /dev/null +++ b/lib/commonjs/RTCErrorEvent.js @@ -0,0 +1,23 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _index = require("event-target-shim/index"); +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +/** + * @brief This class Represents internal error happening on the native side as + * part of asynchronous invocations to synchronous web APIs. + */ +class RTCErrorEvent extends _index.Event { + constructor(type, func, message) { + super(type); + _defineProperty(this, "func", void 0); + _defineProperty(this, "message", void 0); + this.func = func; + this.message = message; + } +} +exports.default = RTCErrorEvent; +//# sourceMappingURL=RTCErrorEvent.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCErrorEvent.js.map b/lib/commonjs/RTCErrorEvent.js.map new file mode 100644 index 000000000..7a9761aa1 --- /dev/null +++ b/lib/commonjs/RTCErrorEvent.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_index","require","_defineProperty","obj","key","value","Object","defineProperty","enumerable","configurable","writable","RTCErrorEvent","Event","constructor","type","func","message","exports","default"],"sources":["RTCErrorEvent.ts"],"sourcesContent":["import { Event } from 'event-target-shim/index';\n\ntype RTCPeerConnectionErrorFunc =\n | 'addTransceiver'\n | 'getTransceivers'\n | 'addTrack'\n | 'removeTrack';\n\n/**\n * @brief This class Represents internal error happening on the native side as\n * part of asynchronous invocations to synchronous web APIs.\n */\nexport default class RTCErrorEvent extends Event {\n readonly func: RTCPeerConnectionErrorFunc;\n readonly message: string;\n constructor(type: TEventType, func: RTCPeerConnectionErrorFunc, message: string) {\n super(type);\n this.func = func;\n this.message = message;\n }\n}"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAgD,SAAAC,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,QAAAD,GAAA,IAAAD,GAAA,IAAAG,MAAA,CAAAC,cAAA,CAAAJ,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAG,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAP,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAQhD;AACA;AACA;AACA;AACe,MAAMQ,aAAa,SAAwDC,YAAK,CAAa;EAGxGC,WAAWA,CAACC,IAAgB,EAAEC,IAAgC,EAAEC,OAAe,EAAE;IAC7E,KAAK,CAACF,IAAI,CAAC;IAACZ,eAAA;IAAAA,eAAA;IACZ,IAAI,CAACa,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,OAAO,GAAGA,OAAO;EAC1B;AACJ;AAACC,OAAA,CAAAC,OAAA,GAAAP,aAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCFrameCryptor.js b/lib/commonjs/RTCFrameCryptor.js new file mode 100644 index 000000000..f9e522c08 --- /dev/null +++ b/lib/commonjs/RTCFrameCryptor.js @@ -0,0 +1,138 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = exports.RTCFrameCryptorStateEvent = exports.RTCFrameCryptorState = void 0; +var _index = require("event-target-shim/index"); +var _reactNative = require("react-native"); +var _EventEmitter = require("./EventEmitter"); +var _Logger = _interopRequireDefault(require("./Logger")); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +const { + WebRTCModule +} = _reactNative.NativeModules; +const log = new _Logger.default('pc'); +/** + * @eventClass + * This event is fired whenever the RTCDataChannel has changed in any way. + * @param {FRAME_CRYPTOR_EVENTS} type - The type of event. + * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel#events MDN} for details. + */ +class RTCFrameCryptorStateEvent extends _index.Event { + /** @eventProperty */ + + /** @eventProperty */ + + constructor(type, eventInitDict) { + super(type, eventInitDict); + _defineProperty(this, "frameCryptor", void 0); + _defineProperty(this, "state", void 0); + this.frameCryptor = eventInitDict.frameCryptor; + this.state = eventInitDict.state; + } +} +exports.RTCFrameCryptorStateEvent = RTCFrameCryptorStateEvent; +let RTCFrameCryptorState; +exports.RTCFrameCryptorState = RTCFrameCryptorState; +(function (RTCFrameCryptorState) { + RTCFrameCryptorState[RTCFrameCryptorState["FrameCryptorStateNew"] = 0] = "FrameCryptorStateNew"; + RTCFrameCryptorState[RTCFrameCryptorState["FrameCryptorStateOk"] = 1] = "FrameCryptorStateOk"; + RTCFrameCryptorState[RTCFrameCryptorState["FrameCryptorStateEncryptionFailed"] = 2] = "FrameCryptorStateEncryptionFailed"; + RTCFrameCryptorState[RTCFrameCryptorState["FrameCryptorStateDecryptionFailed"] = 3] = "FrameCryptorStateDecryptionFailed"; + RTCFrameCryptorState[RTCFrameCryptorState["FrameCryptorStateMissingKey"] = 4] = "FrameCryptorStateMissingKey"; + RTCFrameCryptorState[RTCFrameCryptorState["FrameCryptorStateKeyRatcheted"] = 5] = "FrameCryptorStateKeyRatcheted"; + RTCFrameCryptorState[RTCFrameCryptorState["FrameCryptorStateInternalError"] = 6] = "FrameCryptorStateInternalError"; +})(RTCFrameCryptorState || (exports.RTCFrameCryptorState = RTCFrameCryptorState = {})); +class RTCFrameCryptor extends _index.EventTarget { + constructor(frameCryptorId, participantId) { + super(); + _defineProperty(this, "_frameCryptorId", void 0); + _defineProperty(this, "_participantId", void 0); + this._frameCryptorId = frameCryptorId; + this._participantId = participantId; + this._registerEvents(); + } + get id() { + return this._frameCryptorId; + } + get participantId() { + return this._participantId; + } + _cryptorStateFromString(str) { + switch (str) { + case 'new': + return RTCFrameCryptorState.FrameCryptorStateNew; + case 'ok': + return RTCFrameCryptorState.FrameCryptorStateOk; + case 'decryptionFailed': + return RTCFrameCryptorState.FrameCryptorStateDecryptionFailed; + case 'encryptionFailed': + return RTCFrameCryptorState.FrameCryptorStateEncryptionFailed; + case 'internalError': + return RTCFrameCryptorState.FrameCryptorStateInternalError; + case 'keyRatcheted': + return RTCFrameCryptorState.FrameCryptorStateKeyRatcheted; + case 'missingKey': + return RTCFrameCryptorState.FrameCryptorStateMissingKey; + default: + throw 'Unknown FrameCryptorState: $str'; + } + } + async setKeyIndex(keyIndex) { + const params = { + frameCryptorId: this._frameCryptorId, + keyIndex + }; + return WebRTCModule.frameCryptorSetKeyIndex(params).then(data => data['result']); + } + async getKeyIndex() { + const params = { + frameCryptorId: this._frameCryptorId + }; + return WebRTCModule.frameCryptorGetKeyIndex(params).then(data => data['keyIndex']); + } + async setEnabled(enabled) { + const params = { + frameCryptorId: this._frameCryptorId, + enabled + }; + return WebRTCModule.frameCryptorSetEnabled(params).then(data => data['result']); + } + async getEnabled() { + const params = { + frameCryptorId: this._frameCryptorId + }; + return WebRTCModule.frameCryptorGetEnabled(params).then(data => data['enabled']); + } + async dispose() { + const params = { + frameCryptorId: this._frameCryptorId + }; + await WebRTCModule.frameCryptorDispose(params); + (0, _EventEmitter.removeListener)(this); + } + _registerEvents() { + (0, _EventEmitter.addListener)(this, 'frameCryptionStateChanged', ev => { + if (ev.participantId !== this._participantId || ev.frameCryptorId !== this._frameCryptorId) { + return; + } + log.debug(`${this.id} frameCryptionStateChanged ${ev.state}`); + const initDict = { + frameCryptor: this, + state: ev.state + }; + this.dispatchEvent(new RTCFrameCryptorStateEvent('onframecryptorstatechanged', initDict)); + }); + } +} + +/** + * Define the `onxxx` event handlers. + */ +exports.default = RTCFrameCryptor; +const proto = RTCFrameCryptor.prototype; +(0, _index.defineEventAttribute)(proto, 'onframecryptorstatechanged'); +//# sourceMappingURL=RTCFrameCryptor.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCFrameCryptor.js.map b/lib/commonjs/RTCFrameCryptor.js.map new file mode 100644 index 000000000..92a3293e4 --- /dev/null +++ b/lib/commonjs/RTCFrameCryptor.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_index","require","_reactNative","_EventEmitter","_Logger","_interopRequireDefault","obj","__esModule","default","_defineProperty","key","value","Object","defineProperty","enumerable","configurable","writable","WebRTCModule","NativeModules","log","Logger","RTCFrameCryptorStateEvent","Event","constructor","type","eventInitDict","frameCryptor","state","exports","RTCFrameCryptorState","RTCFrameCryptor","EventTarget","frameCryptorId","participantId","_frameCryptorId","_participantId","_registerEvents","id","_cryptorStateFromString","str","FrameCryptorStateNew","FrameCryptorStateOk","FrameCryptorStateDecryptionFailed","FrameCryptorStateEncryptionFailed","FrameCryptorStateInternalError","FrameCryptorStateKeyRatcheted","FrameCryptorStateMissingKey","setKeyIndex","keyIndex","params","frameCryptorSetKeyIndex","then","data","getKeyIndex","frameCryptorGetKeyIndex","setEnabled","enabled","frameCryptorSetEnabled","getEnabled","frameCryptorGetEnabled","dispose","frameCryptorDispose","removeListener","addListener","ev","debug","initDict","dispatchEvent","proto","prototype","defineEventAttribute"],"sources":["RTCFrameCryptor.ts"],"sourcesContent":["import { Event, EventTarget, defineEventAttribute } from 'event-target-shim/index';\nimport { NativeModules } from 'react-native';\n\nimport { addListener, removeListener } from './EventEmitter';\nimport Logger from './Logger';\nconst { WebRTCModule } = NativeModules;\n\nconst log = new Logger('pc');\n\ntype FRAME_CRYPTOR_EVENTS = 'onframecryptorstatechanged';\n\ninterface IRTCDataChannelEventInitDict extends Event.EventInit {\n frameCryptor: RTCFrameCryptor;\n state: RTCFrameCryptorState;\n}\n\n/**\n * @eventClass\n * This event is fired whenever the RTCDataChannel has changed in any way.\n * @param {FRAME_CRYPTOR_EVENTS} type - The type of event.\n * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel#events MDN} for details.\n */\nexport class RTCFrameCryptorStateEvent<\nTEventType extends FRAME_CRYPTOR_EVENTS\n> extends Event {\n /** @eventProperty */\n frameCryptor: RTCFrameCryptor;\n /** @eventProperty */\n state: RTCFrameCryptorState;\n constructor(type: TEventType, eventInitDict: IRTCDataChannelEventInitDict) {\n super(type, eventInitDict);\n this.frameCryptor = eventInitDict.frameCryptor;\n this.state = eventInitDict.state;\n }\n}\n\ntype RTCFrameCryptorEventMap = {\n onframecryptorstatechanged: RTCFrameCryptorStateEvent<'onframecryptorstatechanged'>;\n}\n\nexport enum RTCFrameCryptorState {\n FrameCryptorStateNew,\n FrameCryptorStateOk,\n FrameCryptorStateEncryptionFailed,\n FrameCryptorStateDecryptionFailed,\n FrameCryptorStateMissingKey,\n FrameCryptorStateKeyRatcheted,\n FrameCryptorStateInternalError,\n}\n\nexport default class RTCFrameCryptor extends EventTarget {\n private _frameCryptorId: string;\n private _participantId: string;\n\n constructor(frameCryptorId: string, participantId: string) {\n super();\n this._frameCryptorId = frameCryptorId;\n this._participantId = participantId;\n this._registerEvents();\n }\n\n get id() {\n return this._frameCryptorId;\n }\n\n get participantId() {\n return this._participantId;\n }\n\n _cryptorStateFromString(str: string): RTCFrameCryptorState {\n switch (str) {\n case 'new':\n return RTCFrameCryptorState.FrameCryptorStateNew;\n case 'ok':\n return RTCFrameCryptorState.FrameCryptorStateOk;\n case 'decryptionFailed':\n return RTCFrameCryptorState.FrameCryptorStateDecryptionFailed;\n case 'encryptionFailed':\n return RTCFrameCryptorState.FrameCryptorStateEncryptionFailed;\n case 'internalError':\n return RTCFrameCryptorState.FrameCryptorStateInternalError;\n case 'keyRatcheted':\n return RTCFrameCryptorState.FrameCryptorStateKeyRatcheted;\n case 'missingKey':\n return RTCFrameCryptorState.FrameCryptorStateMissingKey;\n default:\n throw 'Unknown FrameCryptorState: $str';\n }\n }\n\n async setKeyIndex(keyIndex: number): Promise {\n const params = {\n frameCryptorId: this._frameCryptorId,\n keyIndex,\n };\n\n return WebRTCModule.frameCryptorSetKeyIndex(params)\n .then(data => data['result']);\n }\n\n async getKeyIndex(): Promise {\n const params = {\n frameCryptorId: this._frameCryptorId,\n };\n\n return WebRTCModule.frameCryptorGetKeyIndex(params)\n .then(data => data['keyIndex']);\n }\n\n async setEnabled(enabled: boolean): Promise {\n const params = {\n frameCryptorId: this._frameCryptorId,\n enabled,\n };\n\n return WebRTCModule.frameCryptorSetEnabled(params)\n .then(data => data['result']);\n }\n\n async getEnabled(): Promise {\n const params = {\n frameCryptorId: this._frameCryptorId,\n };\n\n return WebRTCModule.frameCryptorGetEnabled(params)\n .then(data => data['enabled']);\n }\n\n async dispose(): Promise {\n const params = {\n frameCryptorId: this._frameCryptorId,\n };\n\n await WebRTCModule.frameCryptorDispose(params);\n removeListener(this);\n }\n\n\n _registerEvents(): void {\n addListener(this, 'frameCryptionStateChanged', (ev: any) => {\n if (ev.participantId !== this._participantId || ev.frameCryptorId !== this._frameCryptorId) {\n return;\n }\n\n log.debug(`${this.id} frameCryptionStateChanged ${ev.state}`);\n\n const initDict = {\n frameCryptor: this,\n state: ev.state,\n };\n\n this.dispatchEvent(new RTCFrameCryptorStateEvent('onframecryptorstatechanged', initDict));\n });\n }\n}\n\n/**\n * Define the `onxxx` event handlers.\n */\nconst proto = RTCFrameCryptor.prototype;\n\ndefineEventAttribute(proto, 'onframecryptorstatechanged');"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAA8B,SAAAI,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,QAAAD,GAAA,IAAAJ,GAAA,IAAAM,MAAA,CAAAC,cAAA,CAAAP,GAAA,EAAAI,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAG,UAAA,QAAAC,YAAA,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onjs/RTCFrameCryptorFactory.js new file mode 100644 index 000000000..0c2c798a4 --- /dev/null +++ b/lib/commonjs/RTCFrameCryptorFactory.js @@ -0,0 +1,81 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = exports.RTCFrameCryptorAlgorithm = void 0; +var base64 = _interopRequireWildcard(require("base64-js")); +var _reactNative = require("react-native"); +var _RTCFrameCryptor = _interopRequireDefault(require("./RTCFrameCryptor")); +var _RTCKeyProvider = _interopRequireDefault(require("./RTCKeyProvider")); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } +function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } +const { + WebRTCModule +} = _reactNative.NativeModules; +let RTCFrameCryptorAlgorithm; // kAesCbc = 1, +exports.RTCFrameCryptorAlgorithm = RTCFrameCryptorAlgorithm; +(function (RTCFrameCryptorAlgorithm) { + RTCFrameCryptorAlgorithm[RTCFrameCryptorAlgorithm["kAesGcm"] = 0] = "kAesGcm"; +})(RTCFrameCryptorAlgorithm || (exports.RTCFrameCryptorAlgorithm = RTCFrameCryptorAlgorithm = {})); +class RTCFrameCryptorFactory { + static createFrameCryptorForRtpSender(participantId, sender, algorithm, keyProvider) { + const params = { + 'peerConnectionId': sender._peerConnectionId, + 'rtpSenderId': sender._id, + participantId, + 'keyProviderId': keyProvider._id, + 'type': 'sender', + 'algorithm': algorithm + }; + const result = WebRTCModule.frameCryptorFactoryCreateFrameCryptor(params); + if (!result) { + throw new Error('Error when creating frame cryptor for sender'); + } + return new _RTCFrameCryptor.default(result, participantId); + } + static createFrameCryptorForRtpReceiver(participantId, receiver, algorithm, keyProvider) { + const params = { + 'peerConnectionId': receiver._peerConnectionId, + 'rtpReceiverId': receiver._id, + participantId, + 'keyProviderId': keyProvider._id, + 'type': 'receiver', + 'algorithm': algorithm + }; + const result = WebRTCModule.frameCryptorFactoryCreateFrameCryptor(params); + if (!result) { + throw new Error('Error when creating frame cryptor for receiver'); + } + return new _RTCFrameCryptor.default(result, participantId); + } + static createDefaultKeyProvider(options) { + var _options$failureToler, _options$keyRingSize, _options$discardFrame; + const params = { + 'sharedKey': options.sharedKey, + 'ratchetWindowSize': options.ratchetWindowSize, + 'failureTolerance': (_options$failureToler = options.failureTolerance) !== null && _options$failureToler !== void 0 ? _options$failureToler : -1, + 'keyRingSize': (_options$keyRingSize = options.keyRingSize) !== null && _options$keyRingSize !== void 0 ? _options$keyRingSize : 16, + 'discardFrameWhenCryptorNotReady': (_options$discardFrame = options.discardFrameWhenCryptorNotReady) !== null && _options$discardFrame !== void 0 ? _options$discardFrame : false + }; + if (typeof options.ratchetSalt === 'string') { + params['ratchetSalt'] = options.ratchetSalt; + params['ratchetSaltIsBase64'] = false; + } else { + const bytes = options.ratchetSalt; + params['ratchetSalt'] = base64.fromByteArray(bytes); + params['ratchetSaltIsBase64'] = true; + } + if (options.uncryptedMagicBytes) { + params['uncryptedMagicBytes'] = base64.fromByteArray(options.uncryptedMagicBytes); + } + const result = WebRTCModule.frameCryptorFactoryCreateKeyProvider(params); + if (!result) { + throw new Error('Error when creating key provider!'); + } + return new _RTCKeyProvider.default(result); + } +} +exports.default = RTCFrameCryptorFactory; +//# sourceMappingURL=RTCFrameCryptorFactory.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCFrameCryptorFactory.js.map b/lib/commonjs/RTCFrameCryptorFactory.js.map new file mode 100644 index 000000000..d0d94b5cc --- /dev/null +++ b/lib/commonjs/RTCFrameCryptorFactory.js.map @@ -0,0 +1 @@ +{"version":3,"names":["base64","_interopRequireWildcard","require","_reactNative","_RTCFrameCryptor","_interopRequireDefault","_RTCKeyProvider","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","WebRTCModule","NativeModules","RTCFrameCryptorAlgorithm","exports","RTCFrameCryptorFactory","createFrameCryptorForRtpSender","participantId","sender","algorithm","keyProvider","params","_peerConnectionId","_id","result","frameCryptorFactoryCreateFrameCryptor","Error","RTCFrameCryptor","createFrameCryptorForRtpReceiver","receiver","createDefaultKeyProvider","options","_options$failureToler","_options$keyRingSize","_options$discardFrame","sharedKey","ratchetWindowSize","failureTolerance","keyRingSize","discardFrameWhenCryptorNotReady","ratchetSalt","bytes","fromByteArray","uncryptedMagicBytes","frameCryptorFactoryCreateKeyProvider","RTCKeyProvider"],"sources":["RTCFrameCryptorFactory.ts"],"sourcesContent":["import * as base64 from 'base64-js';\nimport { NativeModules } from 'react-native';\n\nimport RTCFrameCryptor from './RTCFrameCryptor';\nimport RTCKeyProvider from './RTCKeyProvider';\nimport RTCRtpReceiver from './RTCRtpReceiver';\nimport RTCRtpSender from './RTCRtpSender';\nconst { WebRTCModule } = NativeModules;\n\nexport enum RTCFrameCryptorAlgorithm {\n kAesGcm = 0,\n // kAesCbc = 1,\n}\n\nexport type RTCKeyProviderOptions = {\n sharedKey: boolean,\n ratchetSalt: string | Uint8Array,\n ratchetWindowSize: number,\n uncryptedMagicBytes?: Uint8Array,\n failureTolerance?: number,\n keyRingSize?: number,\n discardFrameWhenCryptorNotReady?: boolean\n}\n\nexport default class RTCFrameCryptorFactory {\n static createFrameCryptorForRtpSender(\n participantId: string,\n sender: RTCRtpSender,\n algorithm: RTCFrameCryptorAlgorithm,\n keyProvider: RTCKeyProvider\n ): RTCFrameCryptor {\n const params = {\n 'peerConnectionId': sender._peerConnectionId,\n 'rtpSenderId': sender._id,\n participantId,\n 'keyProviderId': keyProvider._id,\n 'type': 'sender',\n 'algorithm': algorithm\n };\n const result = WebRTCModule.frameCryptorFactoryCreateFrameCryptor(params);\n\n if (!result) {\n throw new Error('Error when creating frame cryptor for sender');\n }\n\n return new RTCFrameCryptor(result, participantId);\n }\n static createFrameCryptorForRtpReceiver(\n participantId: string,\n receiver: RTCRtpReceiver,\n algorithm: RTCFrameCryptorAlgorithm,\n keyProvider: RTCKeyProvider\n ): RTCFrameCryptor {\n const params = {\n 'peerConnectionId': receiver._peerConnectionId,\n 'rtpReceiverId': receiver._id,\n participantId,\n 'keyProviderId': keyProvider._id,\n 'type': 'receiver',\n 'algorithm': algorithm\n };\n const result = WebRTCModule.frameCryptorFactoryCreateFrameCryptor(params);\n\n if (!result) {\n throw new Error('Error when creating frame cryptor for receiver');\n }\n\n return new RTCFrameCryptor(result, participantId);\n }\n\n static createDefaultKeyProvider(options: RTCKeyProviderOptions): RTCKeyProvider {\n const params = {\n 'sharedKey': options.sharedKey,\n 'ratchetWindowSize': options.ratchetWindowSize,\n 'failureTolerance': options.failureTolerance ?? -1,\n 'keyRingSize': options.keyRingSize ?? 16,\n 'discardFrameWhenCryptorNotReady': options.discardFrameWhenCryptorNotReady ?? false\n };\n\n if (typeof options.ratchetSalt === 'string') {\n params['ratchetSalt'] = options.ratchetSalt;\n params['ratchetSaltIsBase64'] = false;\n } else {\n const bytes = options.ratchetSalt as Uint8Array;\n\n params['ratchetSalt'] = base64.fromByteArray(bytes);\n params['ratchetSaltIsBase64'] = true;\n }\n\n if (options.uncryptedMagicBytes) {\n params['uncryptedMagicBytes'] = base64.fromByteArray(options.uncryptedMagicBytes);\n }\n\n const result = WebRTCModule.frameCryptorFactoryCreateKeyProvider(params);\n\n if (!result) {\n throw new Error('Error when creating key provider!');\n }\n\n return new RTCKeyProvider(result);\n }\n}"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,eAAA,GAAAD,sBAAA,CAAAH,OAAA;AAA8C,SAAAG,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAV,wBAAAM,GAAA,EAAAI,WAAA,SAAAA,WAAA,IAAAJ,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAQ,KAAA,GAAAL,wBAAA,CAAAC,WAAA,OAAAI,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAT,GAAA,YAAAQ,KAAA,CAAAE,GAAA,CAAAV,GAAA,SAAAW,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAhB,GAAA,QAAAgB,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAnB,GAAA,EAAAgB,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,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CAAC,qBAAqB,CAAC,GAAG,IAAI;IACxC;IAEA,IAAIU,OAAO,CAACY,mBAAmB,EAAE;MAC7BtB,MAAM,CAAC,qBAAqB,CAAC,GAAGvC,MAAM,CAAC4D,aAAa,CAACX,OAAO,CAACY,mBAAmB,CAAC;IACrF;IAEA,MAAMnB,MAAM,GAAGb,YAAY,CAACiC,oCAAoC,CAACvB,MAAM,CAAC;IAExE,IAAI,CAACG,MAAM,EAAE;MACT,MAAM,IAAIE,KAAK,CAAC,mCAAmC,CAAC;IACxD;IAEA,OAAO,IAAImB,uBAAc,CAACrB,MAAM,CAAC;EACrC;AACJ;AAACV,OAAA,CAAAvB,OAAA,GAAAwB,sBAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCIceCandidate.js b/lib/commonjs/RTCIceCandidate.js new file mode 100644 index 000000000..9e637dffe --- /dev/null +++ b/lib/commonjs/RTCIceCandidate.js @@ -0,0 +1,34 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +class RTCIceCandidate { + constructor(_ref) { + let { + candidate = '', + sdpMLineIndex = null, + sdpMid = null + } = _ref; + _defineProperty(this, "candidate", void 0); + _defineProperty(this, "sdpMLineIndex", void 0); + _defineProperty(this, "sdpMid", void 0); + if (sdpMLineIndex === null && sdpMid === null) { + throw new TypeError('`sdpMLineIndex` and `sdpMid` must not be both null'); + } + this.candidate = candidate; + this.sdpMLineIndex = sdpMLineIndex; + this.sdpMid = sdpMid; + } + toJSON() { + return { + candidate: this.candidate, + sdpMLineIndex: this.sdpMLineIndex, + sdpMid: this.sdpMid + }; + } +} +exports.default = RTCIceCandidate; +//# sourceMappingURL=RTCIceCandidate.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCIceCandidate.js.map b/lib/commonjs/RTCIceCandidate.js.map new file mode 100644 index 000000000..204cf33fc --- /dev/null +++ b/lib/commonjs/RTCIceCandidate.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCIceCandidate","constructor","_ref","candidate","sdpMLineIndex","sdpMid","_defineProperty","TypeError","toJSON","exports","default"],"sources":["RTCIceCandidate.ts"],"sourcesContent":["interface RTCIceCandidateInfo {\n candidate?: string;\n sdpMLineIndex?: number | null;\n sdpMid?: string | null;\n}\n\nexport default class RTCIceCandidate {\n candidate: string;\n sdpMLineIndex?: number | null;\n sdpMid?: string | null;\n\n constructor({ candidate = '', sdpMLineIndex = null, sdpMid = null }: RTCIceCandidateInfo) {\n if (sdpMLineIndex === null && sdpMid === null) {\n throw new TypeError('`sdpMLineIndex` and `sdpMid` must not be both null');\n }\n\n this.candidate = candidate;\n this.sdpMLineIndex = sdpMLineIndex;\n this.sdpMid = sdpMid;\n }\n\n toJSON() {\n return {\n candidate: this.candidate,\n sdpMLineIndex: this.sdpMLineIndex,\n sdpMid: this.sdpMid\n };\n }\n}\n"],"mappings":";;;;;;;AAMe,MAAMA,eAAe,CAAC;EAKjCC,WAAWA,CAAAC,IAAA,EAA+E;IAAA,IAA9E;MAAEC,SAAS,GAAG,EAAE;MAAEC,aAAa,GAAG,IAAI;MAAEC,MAAM,GAAG;IAA0B,CAAC,GAAAH,IAAA;IAAAI,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACpF,IAAIF,aAAa,KAAK,IAAI,IAAIC,MAAM,KAAK,IAAI,EAAE;MAC3C,MAAM,IAAIE,SAAS,CAAC,oDAAoD,CAAC;IAC7E;IAEA,IAAI,CAACJ,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,aAAa,GAAGA,aAAa;IAClC,IAAI,CAACC,MAAM,GAAGA,MAAM;EACxB;EAEAG,MAAMA,CAAA,EAAG;IACL,OAAO;MACHL,SAAS,EAAE,IAAI,CAACA,SAAS;MACzBC,aAAa,EAAE,IAAI,CAACA,aAAa;MACjCC,MAAM,EAAE,IAAI,CAACA;IACjB,CAAC;EACL;AACJ;AAACI,OAAA,CAAAC,OAAA,GAAAV,eAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCIceCandidateEvent.js b/lib/commonjs/RTCIceCandidateEvent.js new file mode 100644 index 000000000..b09fa2249 --- /dev/null +++ b/lib/commonjs/RTCIceCandidateEvent.js @@ -0,0 +1,28 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _index = require("event-target-shim/index"); +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +/** + * @eventClass + * This event is fired whenever the icecandidate related RTC_EVENTS changed. + * @type {RTCIceCandidateEvent} for icecandidate related. + * @param {RTC_ICECANDIDATE_EVENTS} type - The type of event. + * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection#events MDN} for details. + */ +class RTCIceCandidateEvent extends _index.Event { + /** @eventProperty */ + + constructor(type, eventInitDict) { + var _eventInitDict$candid; + super(type, eventInitDict); + _defineProperty(this, "candidate", void 0); + this.candidate = (_eventInitDict$candid = eventInitDict === null || eventInitDict === void 0 ? void 0 : eventInitDict.candidate) !== null && _eventInitDict$candid !== void 0 ? _eventInitDict$candid : null; + } +} +exports.default = RTCIceCandidateEvent; +//# sourceMappingURL=RTCIceCandidateEvent.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCIceCandidateEvent.js.map b/lib/commonjs/RTCIceCandidateEvent.js.map new file mode 100644 index 000000000..24c2eb7c5 --- /dev/null +++ b/lib/commonjs/RTCIceCandidateEvent.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_index","require","_defineProperty","obj","key","value","Object","defineProperty","enumerable","configurable","writable","RTCIceCandidateEvent","Event","constructor","type","eventInitDict","_eventInitDict$candid","candidate","exports","default"],"sources":["RTCIceCandidateEvent.ts"],"sourcesContent":["import { Event } from 'event-target-shim/index';\n\nimport type RTCIceCandidate from './RTCIceCandidate';\n\ntype RTC_ICECANDIDATE_EVENTS = 'icecandidate' | 'icecandidateerror'\n\ninterface IRTCDataChannelEventInitDict extends Event.EventInit {\n candidate: RTCIceCandidate | null\n}\n\n/**\n * @eventClass\n * This event is fired whenever the icecandidate related RTC_EVENTS changed.\n * @type {RTCIceCandidateEvent} for icecandidate related.\n * @param {RTC_ICECANDIDATE_EVENTS} type - The type of event.\n * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection#events MDN} for details.\n */\nexport default class RTCIceCandidateEvent extends Event {\n /** @eventProperty */\n candidate: RTCIceCandidate | null;\n constructor(type: TEventType, eventInitDict: IRTCDataChannelEventInitDict) {\n super(type, eventInitDict);\n this.candidate = eventInitDict?.candidate ?? null;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAgD,SAAAC,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,QAAAD,GAAA,IAAAD,GAAA,IAAAG,MAAA,CAAAC,cAAA,CAAAJ,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAG,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAP,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAUhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,MAAMQ,oBAAoB,SAAqDC,YAAK,CAAa;EAC5G;;EAEAC,WAAWA,CAACC,IAAgB,EAAEC,aAA2C,EAAE;IAAA,IAAAC,qBAAA;IACvE,KAAK,CAACF,IAAI,EAAEC,aAAa,CAAC;IAACb,eAAA;IAC3B,IAAI,CAACe,SAAS,IAAAD,qBAAA,GAAGD,aAAa,aAAbA,aAAa,uBAAbA,aAAa,CAAEE,SAAS,cAAAD,qBAAA,cAAAA,qBAAA,GAAI,IAAI;EACrD;AACJ;AAACE,OAAA,CAAAC,OAAA,GAAAR,oBAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCKeyProvider.js b/lib/commonjs/RTCKeyProvider.js new file mode 100644 index 000000000..f26739fd3 --- /dev/null +++ b/lib/commonjs/RTCKeyProvider.js @@ -0,0 +1,111 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = exports.FrameCryptorState = void 0; +var base64 = _interopRequireWildcard(require("base64-js")); +var _reactNative = require("react-native"); +function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } +function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +const { + WebRTCModule +} = _reactNative.NativeModules; +let FrameCryptorState; +exports.FrameCryptorState = FrameCryptorState; +(function (FrameCryptorState) { + FrameCryptorState[FrameCryptorState["FrameCryptorStateNew"] = 0] = "FrameCryptorStateNew"; + FrameCryptorState[FrameCryptorState["FrameCryptorStateOk"] = 1] = "FrameCryptorStateOk"; + FrameCryptorState[FrameCryptorState["FrameCryptorStateEncryptionFailed"] = 2] = "FrameCryptorStateEncryptionFailed"; + FrameCryptorState[FrameCryptorState["FrameCryptorStateDecryptionFailed"] = 3] = "FrameCryptorStateDecryptionFailed"; + FrameCryptorState[FrameCryptorState["FrameCryptorStateMissingKey"] = 4] = "FrameCryptorStateMissingKey"; + FrameCryptorState[FrameCryptorState["FrameCryptorStateKeyRatcheted"] = 5] = "FrameCryptorStateKeyRatcheted"; + FrameCryptorState[FrameCryptorState["FrameCryptorStateInternalError"] = 6] = "FrameCryptorStateInternalError"; +})(FrameCryptorState || (exports.FrameCryptorState = FrameCryptorState = {})); +class RTCKeyProvider { + constructor(keyProviderId) { + _defineProperty(this, "_id", void 0); + this._id = keyProviderId; + } + async setSharedKey(key) { + let keyIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + const params = { + keyProviderId: this._id, + keyIndex + }; + if (typeof key === 'string') { + params['key'] = key; + params['keyIsBase64'] = false; + } else { + params['key'] = base64.fromByteArray(key); + params['keyIsBase64'] = true; + } + return WebRTCModule.keyProviderSetSharedKey(params).then(data => data['result']); + } + async ratchetSharedKey() { + let keyIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + const params = { + keyProviderId: this._id, + keyIndex + }; + return WebRTCModule.keyProviderRatchetSharedKey(params).then(data => base64.toByteArray(data['result'])); + } + async exportSharedKey() { + let keyIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + const params = { + keyProviderId: this._id, + keyIndex + }; + return WebRTCModule.keyProviderExportSharedKey(params).then(data => base64.toByteArray(data['result'])); + } + async setKey(participantId, key) { + let keyIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + const params = { + keyProviderId: this._id, + participantId, + keyIndex + }; + if (typeof key === 'string') { + params['key'] = key; + params['keyIsBase64'] = false; + } else { + params['key'] = base64.fromByteArray(key); + params['keyIsBase64'] = true; + } + return WebRTCModule.keyProviderSetKey(params).then(data => data['result']); + } + async ratchetKey(participantId) { + let keyIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + const params = { + keyProviderId: this._id, + participantId, + keyIndex + }; + return WebRTCModule.keyProviderRatchetKey(params).then(data => base64.toByteArray(data['result'])); + } + async exportKey(participantId) { + let keyIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + const params = { + keyProviderId: this._id, + participantId, + keyIndex + }; + return WebRTCModule.keyProviderExportKey(params).then(data => base64.toByteArray(data['result'])); + } + async setSifTrailer(trailer) { + const params = { + keyProviderId: this._id, + 'sifTrailer': base64.fromByteArray(trailer) + }; + return WebRTCModule.keyProviderSetSifTrailer(params); + } + async dispose() { + const params = { + keyProviderId: this._id + }; + return WebRTCModule.keyProviderDispose(params); + } +} +exports.default = RTCKeyProvider; +//# sourceMappingURL=RTCKeyProvider.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCKeyProvider.js.map b/lib/commonjs/RTCKeyProvider.js.map new file mode 100644 index 000000000..2b7deff9e --- /dev/null +++ b/lib/commonjs/RTCKeyProvider.js.map @@ -0,0 +1 @@ +{"version":3,"names":["base64","_interopRequireWildcard","require","_reactNative","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_defineProperty","value","enumerable","configurable","writable","WebRTCModule","NativeModules","FrameCryptorState","exports","RTCKeyProvider","constructor","keyProviderId","_id","setSharedKey","keyIndex","arguments","length","undefined","params","fromByteArray","keyProviderSetSharedKey","then","data","ratchetSharedKey","keyProviderRatchetSharedKey","toByteArray","exportSharedKey","keyProviderExportSharedKey","setKey","participantId","keyProviderSetKey","ratchetKey","keyProviderRatchetKey","exportKey","keyProviderExportKey","setSifTrailer","trailer","keyProviderSetSifTrailer","dispose","keyProviderDispose"],"sources":["RTCKeyProvider.ts"],"sourcesContent":["import * as base64 from 'base64-js';\nimport { NativeModules } from 'react-native';\nconst { WebRTCModule } = NativeModules;\n\nexport enum FrameCryptorState {\n FrameCryptorStateNew,\n FrameCryptorStateOk,\n FrameCryptorStateEncryptionFailed,\n FrameCryptorStateDecryptionFailed,\n FrameCryptorStateMissingKey,\n FrameCryptorStateKeyRatcheted,\n FrameCryptorStateInternalError,\n}\n\nexport default class RTCKeyProvider {\n _id: string;\n\n constructor(keyProviderId: string) {\n this._id = keyProviderId;\n }\n\n async setSharedKey(key: string | Uint8Array, keyIndex = 0) {\n const params = {\n keyProviderId: this._id,\n keyIndex,\n };\n\n if (typeof key === 'string') {\n params['key'] = key;\n params['keyIsBase64'] = false;\n } else {\n params['key'] = base64.fromByteArray(key as Uint8Array);\n params['keyIsBase64'] = true;\n }\n\n return WebRTCModule.keyProviderSetSharedKey(params)\n .then(data => data['result']);\n }\n\n async ratchetSharedKey(keyIndex = 0): Promise {\n const params = {\n keyProviderId: this._id,\n keyIndex,\n };\n\n return WebRTCModule.keyProviderRatchetSharedKey(params)\n .then(data => base64.toByteArray(data['result']));\n }\n\n async exportSharedKey(keyIndex = 0): Promise {\n const params = {\n keyProviderId: this._id,\n keyIndex,\n };\n\n return WebRTCModule.keyProviderExportSharedKey(params)\n .then(data => base64.toByteArray(data['result']));\n }\n\n async setKey(participantId: string, key: string | Uint8Array, keyIndex = 0): Promise {\n const params = {\n keyProviderId: this._id,\n participantId,\n keyIndex,\n };\n\n if (typeof key === 'string') {\n params['key'] = key;\n params['keyIsBase64'] = false;\n } else {\n params['key'] = base64.fromByteArray(key as Uint8Array);\n params['keyIsBase64'] = true;\n }\n\n return WebRTCModule.keyProviderSetKey(params)\n .then(data => data['result']);\n }\n\n async ratchetKey(participantId: string, keyIndex = 0): Promise {\n const params = {\n keyProviderId: this._id,\n participantId,\n keyIndex,\n };\n\n return WebRTCModule.keyProviderRatchetKey(params)\n .then(data => base64.toByteArray(data['result']));\n }\n\n async exportKey(participantId: string, keyIndex = 0): Promise {\n const params = {\n keyProviderId: this._id,\n participantId,\n keyIndex,\n };\n\n return WebRTCModule.keyProviderExportKey(params)\n .then(data => base64.toByteArray(data['result']));\n }\n\n async setSifTrailer(trailer: Uint8Array) {\n const params = {\n keyProviderId: this._id,\n 'sifTrailer': base64.fromByteArray(trailer),\n };\n\n return WebRTCModule.keyProviderSetSifTrailer(params);\n }\n\n async dispose() {\n const params = {\n keyProviderId: this._id,\n };\n\n return WebRTCModule.keyProviderDispose(params);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAA6C,SAAAE,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAA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OT,YAAY,CAAC6B,oBAAoB,CAAChB,MAAM,CAAC,CAC3CG,IAAI,CAACC,IAAI,IAAIhD,MAAM,CAACmD,WAAW,CAACH,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;EACzD;EAEA,MAAMa,aAAaA,CAACC,OAAmB,EAAE;IACrC,MAAMlB,MAAM,GAAG;MACXP,aAAa,EAAE,IAAI,CAACC,GAAG;MACvB,YAAY,EAAEtC,MAAM,CAAC6C,aAAa,CAACiB,OAAO;IAC9C,CAAC;IAED,OAAO/B,YAAY,CAACgC,wBAAwB,CAACnB,MAAM,CAAC;EACxD;EAEA,MAAMoB,OAAOA,CAAA,EAAG;IACZ,MAAMpB,MAAM,GAAG;MACXP,aAAa,EAAE,IAAI,CAACC;IACxB,CAAC;IAED,OAAOP,YAAY,CAACkC,kBAAkB,CAACrB,MAAM,CAAC;EAClD;AACJ;AAACV,OAAA,CAAAvB,OAAA,GAAAwB,cAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCPIPView.js b/lib/commonjs/RTCPIPView.js new file mode 100644 index 000000000..f490d9e5c --- /dev/null +++ b/lib/commonjs/RTCPIPView.js @@ -0,0 +1,38 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +exports.startIOSPIP = startIOSPIP; +exports.stopIOSPIP = stopIOSPIP; +var _react = require("react"); +var _reactNative = _interopRequireWildcard(require("react-native")); +var _RTCView = _interopRequireDefault(require("./RTCView")); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } +function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } +function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } +/** + * A convenience wrapper around RTCView to handle the fallback view as a prop. + */ +const RTCPIPView = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => { + var _rtcViewProps$iosPIP, _rtcViewProps$iosPIP2; + const rtcViewProps = { + ...props + }; + const fallbackView = (_rtcViewProps$iosPIP = rtcViewProps.iosPIP) === null || _rtcViewProps$iosPIP === void 0 ? void 0 : _rtcViewProps$iosPIP.fallbackView; + (_rtcViewProps$iosPIP2 = rtcViewProps.iosPIP) === null || _rtcViewProps$iosPIP2 === void 0 ? true : delete _rtcViewProps$iosPIP2.fallbackView; + return /*#__PURE__*/React.createElement(_RTCView.default, _extends({ + ref: ref + }, rtcViewProps), fallbackView); +}); +function startIOSPIP(ref) { + _reactNative.UIManager.dispatchViewManagerCommand(_reactNative.default.findNodeHandle(ref.current), _reactNative.UIManager.getViewManagerConfig('RTCVideoView').Commands.startIOSPIP, []); +} +function stopIOSPIP(ref) { + _reactNative.UIManager.dispatchViewManagerCommand(_reactNative.default.findNodeHandle(ref.current), _reactNative.UIManager.getViewManagerConfig('RTCVideoView').Commands.stopIOSPIP, []); +} +var _default = RTCPIPView; +exports.default = _default; +//# sourceMappingURL=RTCPIPView.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCPIPView.js.map b/lib/commonjs/RTCPIPView.js.map new file mode 100644 index 000000000..8088a3f50 --- /dev/null +++ b/lib/commonjs/RTCPIPView.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_react","require","_reactNative","_interopRequireWildcard","_RTCView","_interopRequireDefault","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_extends","assign","target","i","arguments","length","source","apply","RTCPIPView","forwardRef","props","ref","_rtcViewProps$iosPIP","_rtcViewProps$iosPIP2","rtcViewProps","fallbackView","iosPIP","React","createElement","startIOSPIP","UIManager","dispatchViewManagerCommand","ReactNative","findNodeHandle","current","getViewManagerConfig","Commands","stopIOSPIP","_default","exports"],"sources":["RTCPIPView.tsx"],"sourcesContent":["import { Component, forwardRef } from 'react';\nimport ReactNative, { UIManager } from 'react-native';\n\nimport RTCView, { RTCIOSPIPOptions, RTCVideoViewProps } from './RTCView';\n\nexport interface RTCPIPViewProps extends RTCVideoViewProps {\n iosPIP?: RTCIOSPIPOptions & {\n fallbackView?: Component;\n };\n}\n\ntype RTCViewInstance = InstanceType;\n\n/**\n * A convenience wrapper around RTCView to handle the fallback view as a prop.\n */\nconst RTCPIPView = forwardRef((props, ref) => {\n const rtcViewProps = { ...props };\n const fallbackView = rtcViewProps.iosPIP?.fallbackView;\n\n delete rtcViewProps.iosPIP?.fallbackView;\n\n return (\n \n {fallbackView}\n \n );\n});\n\nexport function startIOSPIP(ref) {\n UIManager.dispatchViewManagerCommand(\n ReactNative.findNodeHandle(ref.current),\n UIManager.getViewManagerConfig('RTCVideoView').Commands.startIOSPIP,\n []\n );\n}\n\nexport function stopIOSPIP(ref) {\n UIManager.dispatchViewManagerCommand(\n ReactNative.findNodeHandle(ref.current),\n UIManager.getViewManagerConfig('RTCVideoView').Commands.stopIOSPIP,\n []\n );\n}\n\nexport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C,CAACC,QAAQ,CAACP,WAAW,EACnE,EACJ,CAAC;AACL;AAEO,SAASQ,UAAUA,CAAChB,GAAG,EAAE;EAC5BS,sBAAS,CAACC,0BAA0B,CAChCC,oBAAW,CAACC,cAAc,CAACZ,GAAG,CAACa,OAAO,CAAC,EACvCJ,sBAAS,CAACK,oBAAoB,CAAC,cAAc,CAAC,CAACC,QAAQ,CAACC,UAAU,EAClE,EACJ,CAAC;AACL;AAAC,IAAAC,QAAA,GAEcpB,UAAU;AAAAqB,OAAA,CAAAjD,OAAA,GAAAgD,QAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCPeerConnection.js b/lib/commonjs/RTCPeerConnection.js new file mode 100644 index 000000000..621367c84 --- /dev/null +++ b/lib/commonjs/RTCPeerConnection.js @@ -0,0 +1,694 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _index = require("event-target-shim/index"); +var _reactNative = require("react-native"); +var _EventEmitter = require("./EventEmitter"); +var _Logger = _interopRequireDefault(require("./Logger")); +var _MediaStream = _interopRequireDefault(require("./MediaStream")); +var _MediaStreamTrack = _interopRequireDefault(require("./MediaStreamTrack")); +var _MediaStreamTrackEvent = _interopRequireDefault(require("./MediaStreamTrackEvent")); +var _RTCDataChannel = _interopRequireDefault(require("./RTCDataChannel")); +var _RTCDataChannelEvent = _interopRequireDefault(require("./RTCDataChannelEvent")); +var _RTCIceCandidate = _interopRequireDefault(require("./RTCIceCandidate")); +var _RTCIceCandidateEvent = _interopRequireDefault(require("./RTCIceCandidateEvent")); +var _RTCRtpReceiveParameters = _interopRequireDefault(require("./RTCRtpReceiveParameters")); +var _RTCRtpReceiver = _interopRequireDefault(require("./RTCRtpReceiver")); +var _RTCRtpSendParameters = _interopRequireDefault(require("./RTCRtpSendParameters")); +var _RTCRtpSender = _interopRequireDefault(require("./RTCRtpSender")); +var _RTCRtpTransceiver = _interopRequireDefault(require("./RTCRtpTransceiver")); +var _RTCSessionDescription = _interopRequireDefault(require("./RTCSessionDescription")); +var _RTCTrackEvent = _interopRequireDefault(require("./RTCTrackEvent")); +var RTCUtil = _interopRequireWildcard(require("./RTCUtil")); +function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } +function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +const log = new _Logger.default('pc'); +const { + WebRTCModule +} = _reactNative.NativeModules; +let nextPeerConnectionId = 0; +class RTCPeerConnection extends _index.EventTarget { + constructor(configuration) { + super(); + _defineProperty(this, "localDescription", null); + _defineProperty(this, "remoteDescription", null); + _defineProperty(this, "signalingState", 'stable'); + _defineProperty(this, "iceGatheringState", 'new'); + _defineProperty(this, "connectionState", 'new'); + _defineProperty(this, "iceConnectionState", 'new'); + _defineProperty(this, "_pcId", void 0); + _defineProperty(this, "_transceivers", void 0); + _defineProperty(this, "_remoteStreams", void 0); + _defineProperty(this, "_pendingTrackEvents", void 0); + this._pcId = nextPeerConnectionId++; + + // Sanitize ICE servers. + if (configuration) { + var _configuration$iceSer; + const servers = (_configuration$iceSer = configuration === null || configuration === void 0 ? void 0 : configuration.iceServers) !== null && _configuration$iceSer !== void 0 ? _configuration$iceSer : []; + for (const server of servers) { + let urls = server.url || server.urls; + delete server.url; + delete server.urls; + if (!urls) { + continue; + } + if (!Array.isArray(urls)) { + urls = [urls]; + } + + // Native WebRTC does case sensitive parsing. + server.urls = urls.map(url => url.toLowerCase()); + } + + // Filter out bogus servers. + configuration.iceServers = servers.filter(s => s.urls); + } + if (!WebRTCModule.peerConnectionInit(configuration, this._pcId)) { + throw new Error('Failed to initialize PeerConnection, check the native logs!'); + } + this._transceivers = []; + this._remoteStreams = new Map(); + this._pendingTrackEvents = []; + this._registerEvents(); + log.debug(`${this._pcId} ctor`); + } + async createOffer(options) { + log.debug(`${this._pcId} createOffer`); + const { + sdpInfo, + newTransceivers, + transceiversInfo + } = await WebRTCModule.peerConnectionCreateOffer(this._pcId, RTCUtil.normalizeOfferOptions(options)); + log.debug(`${this._pcId} createOffer OK`); + newTransceivers === null || newTransceivers === void 0 ? void 0 : newTransceivers.forEach(t => { + const { + transceiverOrder, + transceiver + } = t; + const newSender = new _RTCRtpSender.default({ + ...transceiver.sender, + track: null + }); + const remoteTrack = transceiver.receiver.track ? new _MediaStreamTrack.default(transceiver.receiver.track) : null; + const newReceiver = new _RTCRtpReceiver.default({ + ...transceiver.receiver, + track: remoteTrack + }); + const newTransceiver = new _RTCRtpTransceiver.default({ + ...transceiver, + sender: newSender, + receiver: newReceiver + }); + this._insertTransceiverSorted(transceiverOrder, newTransceiver); + }); + this._updateTransceivers(transceiversInfo); + return sdpInfo; + } + async createAnswer() { + log.debug(`${this._pcId} createAnswer`); + const { + sdpInfo, + transceiversInfo + } = await WebRTCModule.peerConnectionCreateAnswer(this._pcId, {}); + this._updateTransceivers(transceiversInfo); + return sdpInfo; + } + setConfiguration(configuration) { + WebRTCModule.peerConnectionSetConfiguration(configuration, this._pcId); + } + async setLocalDescription(sessionDescription) { + var _desc; + log.debug(`${this._pcId} setLocalDescription`); + let desc; + if (sessionDescription) { + var _sessionDescription$s; + desc = { + type: sessionDescription.type, + sdp: (_sessionDescription$s = sessionDescription.sdp) !== null && _sessionDescription$s !== void 0 ? _sessionDescription$s : '' + }; + if (!RTCUtil.isSdpTypeValid(desc.type)) { + throw new Error(`Invalid session description: invalid type: ${desc.type}`); + } + } else { + desc = null; + } + const { + sdpInfo, + transceiversInfo + } = await WebRTCModule.peerConnectionSetLocalDescription(this._pcId, desc); + if (sdpInfo.type && sdpInfo.sdp) { + this.localDescription = new _RTCSessionDescription.default(sdpInfo); + } else { + this.localDescription = null; + } + this._updateTransceivers(transceiversInfo, /* removeStopped */((_desc = desc) === null || _desc === void 0 ? void 0 : _desc.type) === 'answer'); + log.debug(`${this._pcId} setLocalDescription OK`); + } + async setRemoteDescription(sessionDescription) { + var _sessionDescription$s2, _desc$type; + log.debug(`${this._pcId} setRemoteDescription`); + if (!sessionDescription) { + return Promise.reject(new Error('No session description provided')); + } + const desc = { + type: sessionDescription.type, + sdp: (_sessionDescription$s2 = sessionDescription.sdp) !== null && _sessionDescription$s2 !== void 0 ? _sessionDescription$s2 : '' + }; + if (!RTCUtil.isSdpTypeValid((_desc$type = desc.type) !== null && _desc$type !== void 0 ? _desc$type : '')) { + throw new Error(`Invalid session description: invalid type: ${desc.type}`); + } + const { + sdpInfo, + newTransceivers, + transceiversInfo + } = await WebRTCModule.peerConnectionSetRemoteDescription(this._pcId, desc); + if (sdpInfo.type && sdpInfo.sdp) { + this.remoteDescription = new _RTCSessionDescription.default(sdpInfo); + } else { + this.remoteDescription = null; + } + newTransceivers === null || newTransceivers === void 0 ? void 0 : newTransceivers.forEach(t => { + const { + transceiverOrder, + transceiver + } = t; + const newSender = new _RTCRtpSender.default({ + ...transceiver.sender, + track: null + }); + const remoteTrack = transceiver.receiver.track ? new _MediaStreamTrack.default(transceiver.receiver.track) : null; + const newReceiver = new _RTCRtpReceiver.default({ + ...transceiver.receiver, + track: remoteTrack + }); + const newTransceiver = new _RTCRtpTransceiver.default({ + ...transceiver, + sender: newSender, + receiver: newReceiver + }); + this._insertTransceiverSorted(transceiverOrder, newTransceiver); + }); + this._updateTransceivers(transceiversInfo, /* removeStopped */desc.type === 'answer'); + + // Fire track events. They must fire before sRD resolves. + const pendingTrackEvents = this._pendingTrackEvents; + this._pendingTrackEvents = []; + for (const ev of pendingTrackEvents) { + const [transceiver] = this.getTransceivers().filter(t => t.receiver.id === ev.receiver.id); + + // We need to fire this event for an existing track sometimes, like + // when the transceiver direction (on the sending side) switches from + // sendrecv to recvonly and then back. + + // @ts-ignore + const track = transceiver.receiver.track; + transceiver._mid = ev.transceiver.mid; + transceiver._currentDirection = ev.transceiver.currentDirection; + transceiver._direction = ev.transceiver.direction; + + // Get the stream object from the event. Create if necessary. + const streams = ev.streams.map(streamInfo => { + // Here we are making sure that we don't create stream objects that already exist + // So that event listeners do get the same object if it has been created before. + if (!this._remoteStreams.has(streamInfo.streamId)) { + const stream = new _MediaStream.default({ + streamId: streamInfo.streamId, + streamReactTag: streamInfo.streamReactTag, + tracks: [] + }); + this._remoteStreams.set(streamInfo.streamId, stream); + } + const stream = this._remoteStreams.get(streamInfo.streamId); + if (!(stream !== null && stream !== void 0 && stream._tracks.includes(track))) { + stream === null || stream === void 0 ? void 0 : stream._tracks.push(track); + } + return stream; + }); + const eventData = { + streams, + transceiver, + track, + receiver: transceiver.receiver + }; + this.dispatchEvent(new _RTCTrackEvent.default('track', eventData)); + streams.forEach(stream => { + stream.dispatchEvent(new _MediaStreamTrackEvent.default('addtrack', { + track + })); + }); + + // Dispatch an unmute event for the track. + track._setMutedInternal(false); + } + log.debug(`${this._pcId} setRemoteDescription OK`); + } + async addIceCandidate(candidate) { + log.debug(`${this._pcId} addIceCandidate`); + if (!candidate || !candidate.candidate) { + // XXX end-of candidates is not implemented: https://bugs.chromium.org/p/webrtc/issues/detail?id=9218 + return; + } + if ((candidate.sdpMLineIndex === null || candidate.sdpMLineIndex === undefined) && (candidate.sdpMid === null || candidate.sdpMid === undefined)) { + throw new TypeError('`sdpMLineIndex` and `sdpMid` must not be both null or undefined'); + } + const newSdp = await WebRTCModule.peerConnectionAddICECandidate(this._pcId, RTCUtil.deepClone(candidate)); + this.remoteDescription = new _RTCSessionDescription.default(newSdp); + } + + /** + * @brief Adds a new track to the {@link RTCPeerConnection}, + * and indicates that it is contained in the specified {@link MediaStream}s. + * This method has to be synchronous as the W3C API expects a track to be returned + * @param {MediaStreamTrack} track The track to be added + * @param {...MediaStream} streams One or more {@link MediaStream}s the track needs to be added to + * https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack + */ + addTrack(track) { + log.debug(`${this._pcId} addTrack`); + if (this.connectionState === 'closed') { + throw new Error('Peer Connection is closed'); + } + if (this._trackExists(track)) { + throw new Error('Track already exists in a sender'); + } + for (var _len = arguments.length, streams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + streams[_key - 1] = arguments[_key]; + } + const streamIds = streams.map(s => s.id); + const result = WebRTCModule.peerConnectionAddTrack(this._pcId, track.id, { + streamIds + }); + if (result === null) { + throw new Error('Could not add sender'); + } + const { + transceiverOrder, + transceiver, + sender + } = result; + + // According to the W3C docs, the sender could have been reused, and + // so we check if that is the case, and update accordingly. + const [existingSender] = this.getSenders().filter(s => s.id === sender.id); + if (existingSender) { + // Update sender + existingSender._track = track; + + // Update the corresponding transceiver as well + const [existingTransceiver] = this.getTransceivers().filter(t => t.sender.id === existingSender.id); + existingTransceiver._direction = transceiver.direction; + existingTransceiver._currentDirection = transceiver.currentDirection; + return existingSender; + } + + // This is a new transceiver, should create a transceiver for it and add it + const newSender = new _RTCRtpSender.default({ + ...transceiver.sender, + track + }); + const remoteTrack = transceiver.receiver.track ? new _MediaStreamTrack.default(transceiver.receiver.track) : null; + const newReceiver = new _RTCRtpReceiver.default({ + ...transceiver.receiver, + track: remoteTrack + }); + const newTransceiver = new _RTCRtpTransceiver.default({ + ...transceiver, + sender: newSender, + receiver: newReceiver + }); + this._insertTransceiverSorted(transceiverOrder, newTransceiver); + return newSender; + } + addTransceiver(source, init) { + log.debug(`${this._pcId} addTransceiver`); + let src = {}; + if (source === 'audio') { + src = { + type: 'audio' + }; + } else if (source === 'video') { + src = { + type: 'video' + }; + } else { + src = { + trackId: source.id + }; + } + + // Extract the stream ids + if (init && init.streams) { + init.streamIds = init.streams.map(stream => stream.id); + } + const result = WebRTCModule.peerConnectionAddTransceiver(this._pcId, { + ...src, + init: { + ...init + } + }); + if (result === null) { + throw new Error('Transceiver could not be added'); + } + const t = result.transceiver; + let track = null; + if (typeof source === 'string') { + if (t.sender.track) { + track = new _MediaStreamTrack.default(t.sender.track); + } + } else { + // 'source' is a MediaStreamTrack + track = source; + } + const sender = new _RTCRtpSender.default({ + ...t.sender, + track + }); + const remoteTrack = t.receiver.track ? new _MediaStreamTrack.default(t.receiver.track) : null; + const receiver = new _RTCRtpReceiver.default({ + ...t.receiver, + track: remoteTrack + }); + const transceiver = new _RTCRtpTransceiver.default({ + ...result.transceiver, + sender, + receiver + }); + this._insertTransceiverSorted(result.transceiverOrder, transceiver); + return transceiver; + } + removeTrack(sender) { + log.debug(`${this._pcId} removeTrack`); + if (this._pcId !== sender._peerConnectionId) { + throw new Error('Sender does not belong to this peer connection'); + } + if (this.connectionState === 'closed') { + throw new Error('Peer Connection is closed'); + } + const existingSender = this.getSenders().find(s => s === sender); + if (!existingSender) { + throw new Error('Sender does not exist'); + } + if (existingSender.track === null) { + return; + } + + // Blocking! + WebRTCModule.peerConnectionRemoveTrack(this._pcId, sender.id); + existingSender._track = null; + const [existingTransceiver] = this.getTransceivers().filter(t => t.sender.id === existingSender.id); + existingTransceiver._direction = existingTransceiver.direction === 'sendrecv' ? 'recvonly' : 'inactive'; + } + async getStats(selector) { + log.debug(`${this._pcId} getStats`); + if (!selector) { + const data = await WebRTCModule.peerConnectionGetStats(this._pcId); + + /** + * On both Android and iOS it is faster to construct a single + * JSON string representing the Map of StatsReports and have it + * pass through the React Native bridge rather than the Map of + * StatsReports. While the implementations do try to be faster in + * general, the stress is on being faster to pass through the React + * Native bridge which is a bottleneck that tends to be visible in + * the UI when there is congestion involving UI-related passing. + */ + return new Map(JSON.parse(data)); + } else { + const senders = this.getSenders().filter(s => s.track === selector); + const receivers = this.getReceivers().filter(r => r.track === selector); + const matches = senders.length + receivers.length; + if (matches === 0) { + throw new Error('Invalid selector: could not find matching sender / receiver'); + } else if (matches > 1) { + throw new Error('Invalid selector: multiple matching senders / receivers'); + } else { + const sr = senders[0] || receivers[0]; + return sr.getStats(); + } + } + } + getTransceivers() { + return this._transceivers.map(e => e.transceiver); + } + getSenders() { + return this._transceivers.filter(e => !e.transceiver.stopped).map(e => e.transceiver.sender); + } + getReceivers() { + return this._transceivers.filter(e => !e.transceiver.stopped).map(e => e.transceiver.receiver); + } + close() { + log.debug(`${this._pcId} close`); + if (this.connectionState === 'closed') { + return; + } + WebRTCModule.peerConnectionClose(this._pcId); + + // Mark transceivers as stopped. + this._transceivers.forEach(_ref => { + let { + transceiver + } = _ref; + transceiver._setStopped(); + }); + } + restartIce() { + WebRTCModule.peerConnectionRestartIce(this._pcId); + } + _registerEvents() { + (0, _EventEmitter.addListener)(this, 'peerConnectionOnRenegotiationNeeded', ev => { + if (ev.pcId !== this._pcId) { + return; + } + this.dispatchEvent(new _index.Event('negotiationneeded')); + }); + (0, _EventEmitter.addListener)(this, 'peerConnectionIceConnectionChanged', ev => { + if (ev.pcId !== this._pcId) { + return; + } + this.iceConnectionState = ev.iceConnectionState; + this.dispatchEvent(new _index.Event('iceconnectionstatechange')); + }); + (0, _EventEmitter.addListener)(this, 'peerConnectionStateChanged', ev => { + if (ev.pcId !== this._pcId) { + return; + } + this.connectionState = ev.connectionState; + this.dispatchEvent(new _index.Event('connectionstatechange')); + if (ev.connectionState === 'closed') { + // This PeerConnection is done, clean up. + (0, _EventEmitter.removeListener)(this); + WebRTCModule.peerConnectionDispose(this._pcId); + } + }); + (0, _EventEmitter.addListener)(this, 'peerConnectionSignalingStateChanged', ev => { + if (ev.pcId !== this._pcId) { + return; + } + this.signalingState = ev.signalingState; + this.dispatchEvent(new _index.Event('signalingstatechange')); + }); + + // Consider moving away from this event: https://github.com/WebKit/WebKit/pull/3953 + (0, _EventEmitter.addListener)(this, 'peerConnectionOnTrack', ev => { + if (ev.pcId !== this._pcId) { + return; + } + log.debug(`${this._pcId} ontrack`); + + // NOTE: We need to make sure the track event fires right before sRD completes, + // so we queue them up here and dispatch the events when sRD fires, but before completing it. + // In the future we should probably implement out own logic and drop this event altogether. + this._pendingTrackEvents.push(ev); + }); + (0, _EventEmitter.addListener)(this, 'peerConnectionOnRemoveTrack', ev => { + if (ev.pcId !== this._pcId) { + return; + } + log.debug(`${this._pcId} onremovetrack ${ev.receiverId}`); + const receiver = this.getReceivers().find(r => r.id === ev.receiverId); + const track = receiver === null || receiver === void 0 ? void 0 : receiver.track; + if (receiver && track) { + // As per the spec: + // - Remove the track from any media streams that were previously passed to the `track` event. + // https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-removetrack, + // - Mark the track as muted: + // https://w3c.github.io/webrtc-pc/#process-remote-track-removal + for (const stream of this._remoteStreams.values()) { + if (stream._tracks.includes(track)) { + const trackIdx = stream._tracks.indexOf(track); + log.debug(`${this._pcId} removetrack ${track.id}`); + stream._tracks.splice(trackIdx, 1); + stream.dispatchEvent(new _MediaStreamTrackEvent.default('removetrack', { + track + })); + + // Dispatch a mute event for the track. + track._setMutedInternal(true); + } + } + } + }); + (0, _EventEmitter.addListener)(this, 'peerConnectionGotICECandidate', ev => { + if (ev.pcId !== this._pcId) { + return; + } + const sdpInfo = ev.sdp; + + // Can happen when doing a rollback. + if (sdpInfo.type && sdpInfo.sdp) { + this.localDescription = new _RTCSessionDescription.default(sdpInfo); + } else { + this.localDescription = null; + } + const candidate = new _RTCIceCandidate.default(ev.candidate); + this.dispatchEvent(new _RTCIceCandidateEvent.default('icecandidate', { + candidate + })); + }); + (0, _EventEmitter.addListener)(this, 'peerConnectionIceGatheringChanged', ev => { + if (ev.pcId !== this._pcId) { + return; + } + this.iceGatheringState = ev.iceGatheringState; + if (this.iceGatheringState === 'complete') { + const sdpInfo = ev.sdp; + + // Can happen when doing a rollback. + if (sdpInfo.type && sdpInfo.sdp) { + this.localDescription = new _RTCSessionDescription.default(sdpInfo); + } else { + this.localDescription = null; + } + this.dispatchEvent(new _RTCIceCandidateEvent.default('icecandidate', { + candidate: null + })); + } + this.dispatchEvent(new _index.Event('icegatheringstatechange')); + }); + (0, _EventEmitter.addListener)(this, 'peerConnectionDidOpenDataChannel', ev => { + if (ev.pcId !== this._pcId) { + return; + } + const channel = new _RTCDataChannel.default(ev.dataChannel); + this.dispatchEvent(new _RTCDataChannelEvent.default('datachannel', { + channel + })); + + // Send 'open' event. Native doesn't update the state since it's already + // set at this point. + channel.dispatchEvent(new _RTCDataChannelEvent.default('open', { + channel + })); + }); + (0, _EventEmitter.addListener)(this, 'mediaStreamTrackMuteChanged', ev => { + if (ev.pcId !== this._pcId) { + return; + } + const [track] = this.getReceivers().map(r => r.track).filter(t => (t === null || t === void 0 ? void 0 : t.id) === ev.trackId); + if (track) { + track._setMutedInternal(ev.muted); + } + }); + } + + /** + * Creates a new RTCDataChannel object with the given label. The + * RTCDataChannelInit dictionary can be used to configure properties of the + * underlying channel such as data reliability. + * + * @param {string} label - the value with which the label attribute of the new + * instance is to be initialized + * @param {RTCDataChannelInit} dataChannelDict - an optional dictionary of + * values with which to initialize corresponding attributes of the new + * instance such as id + */ + createDataChannel(label, dataChannelDict) { + if (arguments.length === 0) { + throw new TypeError('1 argument required, but 0 present'); + } + if (dataChannelDict && 'id' in dataChannelDict) { + const id = dataChannelDict.id; + if (typeof id !== 'number') { + throw new TypeError('DataChannel id must be a number: ' + id); + } + } + const channelInfo = WebRTCModule.createDataChannel(this._pcId, String(label), dataChannelDict); + if (channelInfo === null) { + throw new TypeError('Failed to create new DataChannel'); + } + return new _RTCDataChannel.default(channelInfo); + } + + /** + * Check whether a media stream track exists already in a sender. + * See https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack for more information + */ + _trackExists(track) { + const [sender] = this.getSenders().filter(sender => { + var _sender$track; + return ((_sender$track = sender.track) === null || _sender$track === void 0 ? void 0 : _sender$track.id) === track.id; + }); + return sender ? true : false; + } + + /** + * Updates transceivers after offer/answer updates if necessary. + */ + _updateTransceivers(transceiverUpdates) { + let removeStopped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + for (const update of transceiverUpdates) { + const [transceiver] = this.getTransceivers().filter(t => t.sender.id === update.transceiverId); + if (!transceiver) { + continue; + } + if (update.currentDirection) { + transceiver._currentDirection = update.currentDirection; + } + transceiver._mid = update.mid; + transceiver._stopped = Boolean(update.isStopped); + transceiver._sender._rtpParameters = new _RTCRtpSendParameters.default(update.senderRtpParameters); + transceiver._receiver._rtpParameters = new _RTCRtpReceiveParameters.default(update.receiverRtpParameters); + } + if (removeStopped) { + const stopped = this.getTransceivers().filter(t => t.stopped); + const newTransceivers = this._transceivers.filter(t => !stopped.includes(t.transceiver)); + this._transceivers = newTransceivers; + } + } + + /** + * Inserts transceiver into the transceiver array in the order they are created (timestamp). + * @param order an index that refers to when it it was created relatively. + * @param transceiver the transceiver object to be inserted. + */ + _insertTransceiverSorted(order, transceiver) { + this._transceivers.push({ + order, + transceiver + }); + this._transceivers.sort((a, b) => a.order - b.order); + } +} + +/** + * Define the `onxxx` event handlers. + */ +exports.default = RTCPeerConnection; +const proto = RTCPeerConnection.prototype; +(0, _index.defineEventAttribute)(proto, 'connectionstatechange'); +(0, _index.defineEventAttribute)(proto, 'icecandidate'); +(0, _index.defineEventAttribute)(proto, 'icecandidateerror'); +(0, _index.defineEventAttribute)(proto, 'iceconnectionstatechange'); +(0, _index.defineEventAttribute)(proto, 'icegatheringstatechange'); +(0, _index.defineEventAttribute)(proto, 'negotiationneeded'); +(0, _index.defineEventAttribute)(proto, 'signalingstatechange'); +(0, _index.defineEventAttribute)(proto, 'datachannel'); +(0, _index.defineEventAttribute)(proto, 'track'); +(0, _index.defineEventAttribute)(proto, 'error'); +//# sourceMappingURL=RTCPeerConnection.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCPeerConnection.js.map b/lib/commonjs/RTCPeerConnection.js.map new file mode 100644 index 000000000..368ebaae5 --- /dev/null +++ b/lib/commonjs/RTCPeerConnection.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_index","require","_reactNative","_EventEmitter","_Logger","_interopRequireDefault","_MediaStream","_MediaStreamTrack","_MediaStreamTrackEvent","_RTCDataChannel","_RTCDataChannelEvent","_RTCIceCandidate","_RTCIceCandidateEvent","_RTCRtpReceiveParameters","_RTCRtpReceiver","_RTCRtpSendParameters","_RTCRtpSender","_RTCRtpTransceiver","_RTCSessionDescription","_RTCTrackEvent","RTCUtil","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_defineProperty","value","enumerable","configurable","writable","log","Logger","WebRTCModule","NativeModules","nextPeerConnectionId","RTCPeerConnection","EventTarget","constructor","configuration","_pcId","_configuration$iceSer","servers","iceServers","server","urls","url","Array","isArray","map","toLowerCase","filter","s","peerConnectionInit","Error","_transceivers","_remoteStreams","Map","_pendingTrackEvents","_registerEvents","debug","createOffer","options","sdpInfo","newTransceivers","transceiversInfo","peerConnectionCreateOffer","normalizeOfferOptions","forEach","t","transceiverOrder","transceiver","newSender","RTCRtpSender","sender","track","remoteTrack","receiver","MediaStreamTrack","newReceiver","RTCRtpReceiver","newTransceiver","RTCRtpTransceiver","_insertTransceiverSorted","_updateTransceivers","createAnswer","peerConnectionCreateAnswer","setConfiguration","peerConnectionSetConfiguration","setLocalDescription","sessionDescription","_desc","_sessionDescription$s","type","sdp","isSdpTypeValid","peerConnectionSetLocalDescription","localDescription","RTCSessionDescription","setRemoteDescription","_sessionDescription$s2","_desc$type","Promise","reject","peerConnectionSetRemoteDescription","remoteDescription","pendingTrackEvents","ev","getTransceivers","id","_mid","mid","_currentDirection","currentDirection","_direction","direction","streams","streamInfo","streamId","stream","MediaStream","streamReactTag","tracks","_tracks","includes","push","eventData","dispatchEvent","RTCTrackEvent","MediaStreamTrackEvent","_setMutedInternal","addIceCandidate","candidate","sdpMLineIndex","undefined","sdpMid","TypeError","newSdp","peerConnectionAddICECandidate","deepClone","addTrack","connectionState","_trackExists","_len","arguments","length","_key","streamIds","result","peerConnectionAddTrack","existingSender","getSenders","_track","existingTransceiver","addTransceiver","source","init","src","trackId","peerConnectionAddTransceiver","removeTrack","_peerConnectionId","find","peerConnectionRemoveTrack","getStats","selector","data","peerConnectionGetStats","JSON","parse","senders","receivers","getReceivers","r","matches","sr","e","stopped","close","peerConnectionClose","_ref","_setStopped","restartIce","peerConnectionRestartIce","addListener","pcId","Event","iceConnectionState","removeListener","peerConnectionDispose","signalingState","receiverId","values","trackIdx","indexOf","splice","RTCIceCandidate","RTCIceCandidateEvent","iceGatheringState","channel","RTCDataChannel","dataChannel","RTCDataChannelEvent","muted","createDataChannel","label","dataChannelDict","channelInfo","String","_sender$track","transceiverUpdates","removeStopped","update","transceiverId","_stopped","Boolean","isStopped","_sender","_rtpParameters","RTCRtpSendParameters","senderRtpParameters","_receiver","RTCRtpReceiveParameters","receiverRtpParameters","order","sort","a","b","exports","proto","defineEventAttribute"],"sources":["RTCPeerConnection.ts"],"sourcesContent":["import { EventTarget, Event, defineEventAttribute } from 'event-target-shim/index';\nimport { NativeModules } from 'react-native';\n\nimport { addListener, removeListener } from './EventEmitter';\nimport Logger from './Logger';\nimport MediaStream from './MediaStream';\nimport MediaStreamTrack from './MediaStreamTrack';\nimport MediaStreamTrackEvent from './MediaStreamTrackEvent';\nimport RTCDataChannel from './RTCDataChannel';\nimport RTCDataChannelEvent from './RTCDataChannelEvent';\nimport RTCIceCandidate from './RTCIceCandidate';\nimport RTCIceCandidateEvent from './RTCIceCandidateEvent';\nimport RTCRtpReceiveParameters from './RTCRtpReceiveParameters';\nimport RTCRtpReceiver from './RTCRtpReceiver';\nimport RTCRtpSendParameters from './RTCRtpSendParameters';\nimport RTCRtpSender from './RTCRtpSender';\nimport RTCRtpTransceiver from './RTCRtpTransceiver';\nimport RTCSessionDescription, { RTCSessionDescriptionInit } from './RTCSessionDescription';\nimport RTCTrackEvent from './RTCTrackEvent';\nimport * as RTCUtil from './RTCUtil';\nimport { RTCOfferOptions } from './RTCUtil';\n\nconst log = new Logger('pc');\nconst { WebRTCModule } = NativeModules;\n\ntype RTCSignalingState =\n | 'stable'\n | 'have-local-offer'\n | 'have-remote-offer'\n | 'have-local-pranswer'\n | 'have-remote-pranswer'\n | 'closed';\n\ntype RTCIceGatheringState = 'new' | 'gathering' | 'complete';\n\ntype RTCPeerConnectionState = 'new' | 'connecting' | 'connected' | 'disconnected' | 'failed' | 'closed';\n\ntype RTCIceConnectionState = 'new' | 'checking' | 'connected' | 'completed' | 'failed' | 'disconnected' | 'closed';\n\ntype RTCDataChannelInit = {\n ordered?: boolean,\n maxPacketLifeTime?: number,\n maxRetransmits?: number,\n protocol?: string,\n negotiated?: boolean,\n id?: number\n};\n\ntype RTCIceServer = {\n credential?: string,\n url?: string, // Deprecated.\n urls?: string | string[],\n username?: string\n};\n\ntype RTCConfiguration = {\n bundlePolicy?: 'balanced' | 'max-compat' | 'max-bundle',\n iceCandidatePoolSize?: number,\n iceServers?: RTCIceServer[],\n iceTransportPolicy?: 'all' | 'relay',\n rtcpMuxPolicy?: 'negotiate' | 'require'\n};\n\ntype RTCPeerConnectionEventMap = {\n connectionstatechange: Event<'connectionstatechange'>\n icecandidate: RTCIceCandidateEvent<'icecandidate'>\n icecandidateerror: RTCIceCandidateEvent<'icecandidateerror'>\n iceconnectionstatechange: Event<'iceconnectionstatechange'>\n icegatheringstatechange: Event<'icegatheringstatechange'>\n negotiationneeded: Event<'negotiationneeded'>\n signalingstatechange: Event<'signalingstatechange'>\n datachannel: RTCDataChannelEvent<'datachannel'>\n track: RTCTrackEvent<'track'>\n error: Event<'error'>\n}\n\nlet nextPeerConnectionId = 0;\n\nexport default class RTCPeerConnection extends EventTarget {\n localDescription: RTCSessionDescription | null = null;\n remoteDescription: RTCSessionDescription | null = null;\n signalingState: RTCSignalingState = 'stable';\n iceGatheringState: RTCIceGatheringState = 'new';\n connectionState: RTCPeerConnectionState = 'new';\n iceConnectionState: RTCIceConnectionState = 'new';\n\n _pcId: number;\n _transceivers: { order: number, transceiver: RTCRtpTransceiver }[];\n _remoteStreams: Map;\n _pendingTrackEvents: any[];\n\n constructor(configuration?: RTCConfiguration) {\n super();\n\n this._pcId = nextPeerConnectionId++;\n\n // Sanitize ICE servers.\n if (configuration) {\n const servers = configuration?.iceServers ?? [];\n\n for (const server of servers) {\n let urls = server.url || server.urls;\n\n delete server.url;\n delete server.urls;\n\n if (!urls) {\n continue;\n }\n\n if (!Array.isArray(urls)) {\n urls = [ urls ];\n }\n\n // Native WebRTC does case sensitive parsing.\n server.urls = urls.map(url => url.toLowerCase());\n }\n\n // Filter out bogus servers.\n configuration.iceServers = servers.filter(s => s.urls);\n }\n\n if (!WebRTCModule.peerConnectionInit(configuration, this._pcId)) {\n throw new Error('Failed to initialize PeerConnection, check the native logs!');\n }\n\n this._transceivers = [];\n this._remoteStreams = new Map();\n this._pendingTrackEvents = [];\n\n this._registerEvents();\n\n log.debug(`${this._pcId} ctor`);\n }\n\n async createOffer(options?:RTCOfferOptions) {\n log.debug(`${this._pcId} createOffer`);\n\n const {\n sdpInfo,\n newTransceivers,\n transceiversInfo\n } = await WebRTCModule.peerConnectionCreateOffer(this._pcId, RTCUtil.normalizeOfferOptions(options));\n\n log.debug(`${this._pcId} createOffer OK`);\n\n newTransceivers?.forEach(t => {\n const { transceiverOrder, transceiver } = t;\n const newSender = new RTCRtpSender({ ...transceiver.sender, track: null });\n const remoteTrack\n = transceiver.receiver.track ? new MediaStreamTrack(transceiver.receiver.track) : null;\n const newReceiver = new RTCRtpReceiver({ ...transceiver.receiver, track: remoteTrack });\n const newTransceiver = new RTCRtpTransceiver({\n ...transceiver,\n sender: newSender,\n receiver: newReceiver,\n });\n\n this._insertTransceiverSorted(transceiverOrder, newTransceiver);\n });\n\n this._updateTransceivers(transceiversInfo);\n\n return sdpInfo;\n }\n\n async createAnswer() {\n log.debug(`${this._pcId} createAnswer`);\n\n const {\n sdpInfo,\n transceiversInfo\n } = await WebRTCModule.peerConnectionCreateAnswer(this._pcId, {});\n\n this._updateTransceivers(transceiversInfo);\n\n return sdpInfo;\n }\n\n setConfiguration(configuration): void {\n WebRTCModule.peerConnectionSetConfiguration(configuration, this._pcId);\n }\n\n async setLocalDescription(sessionDescription?: RTCSessionDescription | RTCSessionDescriptionInit): Promise {\n log.debug(`${this._pcId} setLocalDescription`);\n\n let desc;\n\n if (sessionDescription) {\n desc = {\n type: sessionDescription.type,\n sdp: sessionDescription.sdp ?? ''\n };\n\n if (!RTCUtil.isSdpTypeValid(desc.type)) {\n throw new Error(`Invalid session description: invalid type: ${desc.type}`);\n }\n } else {\n desc = null;\n }\n\n const {\n sdpInfo,\n transceiversInfo\n } = await WebRTCModule.peerConnectionSetLocalDescription(this._pcId, desc);\n\n if (sdpInfo.type && sdpInfo.sdp) {\n this.localDescription = new RTCSessionDescription(sdpInfo);\n } else {\n this.localDescription = null;\n }\n\n this._updateTransceivers(transceiversInfo, /* removeStopped */ desc?.type === 'answer');\n\n log.debug(`${this._pcId} setLocalDescription OK`);\n }\n\n async setRemoteDescription(sessionDescription: RTCSessionDescription | RTCSessionDescriptionInit): Promise {\n log.debug(`${this._pcId} setRemoteDescription`);\n\n if (!sessionDescription) {\n return Promise.reject(new Error('No session description provided'));\n }\n\n const desc = {\n type: sessionDescription.type,\n sdp: sessionDescription.sdp ?? ''\n };\n\n if (!RTCUtil.isSdpTypeValid(desc.type ?? '')) {\n throw new Error(`Invalid session description: invalid type: ${desc.type}`);\n }\n\n const {\n sdpInfo,\n newTransceivers,\n transceiversInfo\n } = await WebRTCModule.peerConnectionSetRemoteDescription(this._pcId, desc);\n\n if (sdpInfo.type && sdpInfo.sdp) {\n this.remoteDescription = new RTCSessionDescription(sdpInfo);\n } else {\n this.remoteDescription = null;\n }\n\n newTransceivers?.forEach(t => {\n const { transceiverOrder, transceiver } = t;\n const newSender = new RTCRtpSender({ ...transceiver.sender, track: null });\n const remoteTrack\n = transceiver.receiver.track ? new MediaStreamTrack(transceiver.receiver.track) : null;\n const newReceiver = new RTCRtpReceiver({ ...transceiver.receiver, track: remoteTrack });\n const newTransceiver = new RTCRtpTransceiver({\n ...transceiver,\n sender: newSender,\n receiver: newReceiver,\n });\n\n this._insertTransceiverSorted(transceiverOrder, newTransceiver);\n });\n\n this._updateTransceivers(transceiversInfo, /* removeStopped */ desc.type === 'answer');\n\n // Fire track events. They must fire before sRD resolves.\n const pendingTrackEvents = this._pendingTrackEvents;\n\n this._pendingTrackEvents = [];\n\n for (const ev of pendingTrackEvents) {\n const [ transceiver ] = this\n .getTransceivers()\n .filter(t => t.receiver.id === ev.receiver.id);\n\n // We need to fire this event for an existing track sometimes, like\n // when the transceiver direction (on the sending side) switches from\n // sendrecv to recvonly and then back.\n\n // @ts-ignore\n const track: MediaStreamTrack = transceiver.receiver.track;\n\n transceiver._mid = ev.transceiver.mid;\n transceiver._currentDirection = ev.transceiver.currentDirection;\n transceiver._direction = ev.transceiver.direction;\n\n // Get the stream object from the event. Create if necessary.\n const streams: MediaStream[] = ev.streams.map(streamInfo => {\n // Here we are making sure that we don't create stream objects that already exist\n // So that event listeners do get the same object if it has been created before.\n if (!this._remoteStreams.has(streamInfo.streamId)) {\n const stream = new MediaStream({\n streamId: streamInfo.streamId,\n streamReactTag: streamInfo.streamReactTag,\n tracks: []\n });\n\n this._remoteStreams.set(streamInfo.streamId, stream);\n }\n\n const stream = this._remoteStreams.get(streamInfo.streamId);\n\n if (!stream?._tracks.includes(track)) {\n stream?._tracks.push(track);\n }\n\n return stream;\n });\n\n const eventData = {\n streams,\n transceiver,\n track,\n receiver: transceiver.receiver\n };\n\n\n this.dispatchEvent(new RTCTrackEvent('track', eventData));\n\n streams.forEach(stream => {\n stream.dispatchEvent(new MediaStreamTrackEvent('addtrack', { track }));\n });\n\n // Dispatch an unmute event for the track.\n track._setMutedInternal(false);\n }\n\n log.debug(`${this._pcId} setRemoteDescription OK`);\n }\n\n async addIceCandidate(candidate): Promise {\n log.debug(`${this._pcId} addIceCandidate`);\n\n if (!candidate || !candidate.candidate) {\n // XXX end-of candidates is not implemented: https://bugs.chromium.org/p/webrtc/issues/detail?id=9218\n return;\n }\n\n if ((candidate.sdpMLineIndex === null ||\n candidate.sdpMLineIndex === undefined) &&\n (candidate.sdpMid === null ||\n candidate.sdpMid === undefined)\n ) {\n throw new TypeError('`sdpMLineIndex` and `sdpMid` must not be both null or undefined');\n }\n\n const newSdp = await WebRTCModule.peerConnectionAddICECandidate(\n this._pcId,\n RTCUtil.deepClone(candidate)\n );\n\n this.remoteDescription = new RTCSessionDescription(newSdp);\n }\n\n /**\n * @brief Adds a new track to the {@link RTCPeerConnection},\n * and indicates that it is contained in the specified {@link MediaStream}s.\n * This method has to be synchronous as the W3C API expects a track to be returned\n * @param {MediaStreamTrack} track The track to be added\n * @param {...MediaStream} streams One or more {@link MediaStream}s the track needs to be added to\n * https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack\n */\n addTrack(track: MediaStreamTrack, ...streams: MediaStream[]): RTCRtpSender {\n log.debug(`${this._pcId} addTrack`);\n\n if (this.connectionState === 'closed') {\n throw new Error('Peer Connection is closed');\n }\n\n if (this._trackExists(track)) {\n throw new Error('Track already exists in a sender');\n }\n\n const streamIds = streams.map(s => s.id);\n const result = WebRTCModule.peerConnectionAddTrack(this._pcId, track.id, { streamIds });\n\n if (result === null) {\n throw new Error('Could not add sender');\n }\n\n const { transceiverOrder, transceiver, sender } = result;\n\n // According to the W3C docs, the sender could have been reused, and\n // so we check if that is the case, and update accordingly.\n const [ existingSender ] = this\n .getSenders()\n .filter(s => s.id === sender.id);\n\n if (existingSender) {\n // Update sender\n existingSender._track = track;\n\n // Update the corresponding transceiver as well\n const [ existingTransceiver ] = this\n .getTransceivers()\n .filter(t => t.sender.id === existingSender.id);\n\n existingTransceiver._direction = transceiver.direction;\n existingTransceiver._currentDirection = transceiver.currentDirection;\n\n return existingSender;\n }\n\n // This is a new transceiver, should create a transceiver for it and add it\n const newSender = new RTCRtpSender({ ...transceiver.sender, track });\n const remoteTrack = transceiver.receiver.track ? new MediaStreamTrack(transceiver.receiver.track) : null;\n const newReceiver = new RTCRtpReceiver({ ...transceiver.receiver, track: remoteTrack });\n const newTransceiver = new RTCRtpTransceiver({\n ...transceiver,\n sender: newSender,\n receiver: newReceiver,\n });\n\n this._insertTransceiverSorted(transceiverOrder, newTransceiver);\n\n return newSender;\n }\n\n addTransceiver(source: 'audio' | 'video' | MediaStreamTrack, init): RTCRtpTransceiver {\n log.debug(`${this._pcId} addTransceiver`);\n\n let src = {};\n\n if (source === 'audio') {\n src = { type: 'audio' };\n } else if (source === 'video') {\n src = { type: 'video' };\n } else {\n src = { trackId: source.id };\n }\n\n // Extract the stream ids\n if (init && init.streams) {\n init.streamIds = init.streams.map(stream => stream.id);\n }\n\n const result = WebRTCModule.peerConnectionAddTransceiver(this._pcId, { ...src, init: { ...init } });\n\n if (result === null) {\n throw new Error('Transceiver could not be added');\n }\n\n const t = result.transceiver;\n let track: MediaStreamTrack | null = null;\n\n if (typeof source === 'string') {\n if (t.sender.track) {\n track = new MediaStreamTrack(t.sender.track);\n }\n } else {\n // 'source' is a MediaStreamTrack\n track = source;\n }\n\n const sender = new RTCRtpSender({ ...t.sender, track });\n const remoteTrack = t.receiver.track ? new MediaStreamTrack(t.receiver.track) : null;\n const receiver = new RTCRtpReceiver({ ...t.receiver, track: remoteTrack });\n const transceiver = new RTCRtpTransceiver({\n ...result.transceiver,\n sender,\n receiver\n });\n\n this._insertTransceiverSorted(result.transceiverOrder, transceiver);\n\n return transceiver;\n }\n\n removeTrack(sender: RTCRtpSender) {\n log.debug(`${this._pcId} removeTrack`);\n\n if (this._pcId !== sender._peerConnectionId) {\n throw new Error('Sender does not belong to this peer connection');\n }\n\n if (this.connectionState === 'closed') {\n throw new Error('Peer Connection is closed');\n }\n\n const existingSender = this\n .getSenders()\n .find(s => s === sender);\n\n if (!existingSender) {\n throw new Error('Sender does not exist');\n }\n\n if (existingSender.track === null) {\n return;\n }\n\n // Blocking!\n WebRTCModule.peerConnectionRemoveTrack(this._pcId, sender.id);\n\n existingSender._track = null;\n\n const [ existingTransceiver ] = this\n .getTransceivers()\n .filter(t => t.sender.id === existingSender.id);\n\n existingTransceiver._direction = existingTransceiver.direction === 'sendrecv' ? 'recvonly' : 'inactive';\n }\n\n async getStats(selector?: MediaStreamTrack) {\n log.debug(`${this._pcId} getStats`);\n\n if (!selector) {\n const data = await WebRTCModule.peerConnectionGetStats(this._pcId);\n\n /**\n * On both Android and iOS it is faster to construct a single\n * JSON string representing the Map of StatsReports and have it\n * pass through the React Native bridge rather than the Map of\n * StatsReports. While the implementations do try to be faster in\n * general, the stress is on being faster to pass through the React\n * Native bridge which is a bottleneck that tends to be visible in\n * the UI when there is congestion involving UI-related passing.\n */\n return new Map(JSON.parse(data));\n } else {\n const senders = this.getSenders().filter(s => s.track === selector);\n const receivers = this.getReceivers().filter(r => r.track === selector);\n const matches = senders.length + receivers.length;\n\n if (matches === 0) {\n throw new Error('Invalid selector: could not find matching sender / receiver');\n } else if (matches > 1) {\n throw new Error('Invalid selector: multiple matching senders / receivers');\n } else {\n const sr = senders[0] || receivers[0];\n\n return sr.getStats();\n }\n }\n }\n\n getTransceivers(): RTCRtpTransceiver[] {\n return this._transceivers.map(e => e.transceiver);\n }\n\n getSenders(): RTCRtpSender[] {\n return this._transceivers.filter(e => !e.transceiver.stopped).map(e => e.transceiver.sender);\n }\n\n getReceivers(): RTCRtpReceiver[] {\n return this._transceivers.filter(e => !e.transceiver.stopped).map(e => e.transceiver.receiver);\n }\n\n close(): void {\n log.debug(`${this._pcId} close`);\n\n if (this.connectionState === 'closed') {\n return;\n }\n\n WebRTCModule.peerConnectionClose(this._pcId);\n\n // Mark transceivers as stopped.\n this._transceivers.forEach(({ transceiver })=> {\n transceiver._setStopped();\n });\n }\n\n restartIce(): void {\n WebRTCModule.peerConnectionRestartIce(this._pcId);\n }\n\n _registerEvents(): void {\n addListener(this, 'peerConnectionOnRenegotiationNeeded', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n this.dispatchEvent(new Event('negotiationneeded'));\n });\n\n addListener(this, 'peerConnectionIceConnectionChanged', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n this.iceConnectionState = ev.iceConnectionState;\n\n this.dispatchEvent(new Event('iceconnectionstatechange'));\n });\n\n addListener(this, 'peerConnectionStateChanged', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n this.connectionState = ev.connectionState;\n\n this.dispatchEvent(new Event('connectionstatechange'));\n\n if (ev.connectionState === 'closed') {\n // This PeerConnection is done, clean up.\n removeListener(this);\n\n WebRTCModule.peerConnectionDispose(this._pcId);\n }\n });\n\n addListener(this, 'peerConnectionSignalingStateChanged', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n this.signalingState = ev.signalingState;\n\n this.dispatchEvent(new Event('signalingstatechange'));\n });\n\n // Consider moving away from this event: https://github.com/WebKit/WebKit/pull/3953\n addListener(this, 'peerConnectionOnTrack', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n log.debug(`${this._pcId} ontrack`);\n\n // NOTE: We need to make sure the track event fires right before sRD completes,\n // so we queue them up here and dispatch the events when sRD fires, but before completing it.\n // In the future we should probably implement out own logic and drop this event altogether.\n this._pendingTrackEvents.push(ev);\n });\n\n addListener(this, 'peerConnectionOnRemoveTrack', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n log.debug(`${this._pcId} onremovetrack ${ev.receiverId}`);\n\n const receiver = this.getReceivers().find(r => r.id === ev.receiverId);\n const track = receiver?.track;\n\n if (receiver && track) {\n // As per the spec:\n // - Remove the track from any media streams that were previously passed to the `track` event.\n // https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-removetrack,\n // - Mark the track as muted:\n // https://w3c.github.io/webrtc-pc/#process-remote-track-removal\n for (const stream of this._remoteStreams.values()) {\n if (stream._tracks.includes(track)) {\n const trackIdx = stream._tracks.indexOf(track);\n\n log.debug(`${this._pcId} removetrack ${track.id}`);\n\n stream._tracks.splice(trackIdx, 1);\n\n stream.dispatchEvent(new MediaStreamTrackEvent('removetrack', { track }));\n\n // Dispatch a mute event for the track.\n track._setMutedInternal(true);\n }\n }\n }\n });\n\n addListener(this, 'peerConnectionGotICECandidate', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n const sdpInfo = ev.sdp;\n\n // Can happen when doing a rollback.\n if (sdpInfo.type && sdpInfo.sdp) {\n this.localDescription = new RTCSessionDescription(sdpInfo);\n } else {\n this.localDescription = null;\n }\n\n const candidate = new RTCIceCandidate(ev.candidate);\n\n this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', { candidate }));\n });\n\n addListener(this, 'peerConnectionIceGatheringChanged', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n this.iceGatheringState = ev.iceGatheringState;\n\n if (this.iceGatheringState === 'complete') {\n const sdpInfo = ev.sdp;\n\n // Can happen when doing a rollback.\n if (sdpInfo.type && sdpInfo.sdp) {\n this.localDescription = new RTCSessionDescription(sdpInfo);\n } else {\n this.localDescription = null;\n }\n\n this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', { candidate: null }));\n }\n\n this.dispatchEvent(new Event('icegatheringstatechange'));\n });\n\n addListener(this, 'peerConnectionDidOpenDataChannel', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n const channel = new RTCDataChannel(ev.dataChannel);\n\n this.dispatchEvent(new RTCDataChannelEvent('datachannel', { channel }));\n\n // Send 'open' event. Native doesn't update the state since it's already\n // set at this point.\n channel.dispatchEvent(new RTCDataChannelEvent('open', { channel }));\n });\n\n addListener(this, 'mediaStreamTrackMuteChanged', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n const [\n track\n ] = this.getReceivers().map(r => r.track).filter(t => t?.id === ev.trackId);\n\n if (track) {\n track._setMutedInternal(ev.muted);\n }\n });\n }\n\n /**\n * Creates a new RTCDataChannel object with the given label. The\n * RTCDataChannelInit dictionary can be used to configure properties of the\n * underlying channel such as data reliability.\n *\n * @param {string} label - the value with which the label attribute of the new\n * instance is to be initialized\n * @param {RTCDataChannelInit} dataChannelDict - an optional dictionary of\n * values with which to initialize corresponding attributes of the new\n * instance such as id\n */\n createDataChannel(label: string, dataChannelDict?: RTCDataChannelInit): RTCDataChannel {\n if (arguments.length === 0) {\n throw new TypeError('1 argument required, but 0 present');\n }\n\n if (dataChannelDict && 'id' in dataChannelDict) {\n const id = dataChannelDict.id;\n\n if (typeof id !== 'number') {\n throw new TypeError('DataChannel id must be a number: ' + id);\n }\n }\n\n const channelInfo = WebRTCModule.createDataChannel(this._pcId, String(label), dataChannelDict);\n\n if (channelInfo === null) {\n throw new TypeError('Failed to create new DataChannel');\n }\n\n return new RTCDataChannel(channelInfo);\n }\n\n /**\n * Check whether a media stream track exists already in a sender.\n * See https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack for more information\n */\n _trackExists(track: MediaStreamTrack): boolean {\n const [ sender ] = this\n .getSenders()\n .filter(\n sender => sender.track?.id === track.id\n );\n\n return sender? true : false;\n }\n\n /**\n * Updates transceivers after offer/answer updates if necessary.\n */\n _updateTransceivers(transceiverUpdates, removeStopped = false) {\n for (const update of transceiverUpdates) {\n const [ transceiver ] = this\n .getTransceivers()\n .filter(t => t.sender.id === update.transceiverId);\n\n if (!transceiver) {\n continue;\n }\n\n if (update.currentDirection) {\n transceiver._currentDirection = update.currentDirection;\n }\n\n transceiver._mid = update.mid;\n transceiver._stopped = Boolean(update.isStopped);\n transceiver._sender._rtpParameters = new RTCRtpSendParameters(update.senderRtpParameters);\n transceiver._receiver._rtpParameters = new RTCRtpReceiveParameters(update.receiverRtpParameters);\n }\n\n if (removeStopped) {\n const stopped = this.getTransceivers().filter(t => t.stopped);\n const newTransceivers = this._transceivers.filter(t => !stopped.includes(t.transceiver));\n\n this._transceivers = newTransceivers;\n }\n }\n\n /**\n * Inserts transceiver into the transceiver array in the order they are created (timestamp).\n * @param order an index that refers to when it it was created relatively.\n * @param transceiver the transceiver object to be inserted.\n */\n _insertTransceiverSorted(order: number, transceiver: RTCRtpTransceiver) {\n this._transceivers.push({ order, transceiver });\n this._transceivers.sort((a, b) => a.order - b.order);\n }\n}\n\n/**\n * Define the `onxxx` event handlers.\n */\nconst proto = RTCPeerConnection.prototype;\n\ndefineEventAttribute(proto, 'connectionstatechange');\ndefineEventAttribute(proto, 'icecandidate');\ndefineEventAttribute(proto, 'icecandidateerror');\ndefineEventAttribute(proto, 'iceconnectionstatechange');\ndefineEventAttribute(proto, 'icegatheringstatechange');\ndefineEventAttribute(proto, 'negotiationneeded');\ndefineEventAttribute(proto, 'signalingstatechange');\ndefineEventAttribute(proto, 'datachannel');\ndefineEventAttribute(proto, 'track');\ndefineEventAttribute(proto, 'error');\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAD,sBAAA,CAAAJ,OAAA;AACA,IAAAM,iBAAA,GAAAF,sBAAA,CAAAJ,OAAA;AACA,IAAAO,sBAAA,GAAAH,sBAAA,CAAAJ,OAAA;AACA,IAAAQ,eAAA,GAAAJ,sBAAA,CAAAJ,OAAA;AACA,IAAAS,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,IAAAC,2BAAoB,EAACD,KAAK,EAAE,OAAO,CAAC;AACpC,IAAAC,2BAAoB,EAACD,KAAK,EAAE,OAAO,CAAC"} \ No newline at end of file diff --git a/lib/commonjs/RTCRtcpParameters.js b/lib/commonjs/RTCRtcpParameters.js new file mode 100644 index 000000000..3bf3f4f71 --- /dev/null +++ b/lib/commonjs/RTCRtcpParameters.js @@ -0,0 +1,24 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +class RTCRtcpParameters { + constructor(init) { + _defineProperty(this, "cname", void 0); + _defineProperty(this, "reducedSize", void 0); + this.cname = init.cname; + this.reducedSize = init.reducedSize; + Object.freeze(this); + } + toJSON() { + return { + cname: this.cname, + reducedSize: this.reducedSize + }; + } +} +exports.default = RTCRtcpParameters; +//# sourceMappingURL=RTCRtcpParameters.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCRtcpParameters.js.map b/lib/commonjs/RTCRtcpParameters.js.map new file mode 100644 index 000000000..ed117704f --- /dev/null +++ b/lib/commonjs/RTCRtcpParameters.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtcpParameters","constructor","init","_defineProperty","cname","reducedSize","Object","freeze","toJSON","exports","default"],"sources":["RTCRtcpParameters.ts"],"sourcesContent":["export interface RTCRtcpParametersInit {\n cname: string;\n reducedSize: boolean;\n}\n\nexport default class RTCRtcpParameters {\n readonly cname: string;\n readonly reducedSize: boolean;\n\n constructor(init: RTCRtcpParametersInit) {\n this.cname = init.cname;\n this.reducedSize = init.reducedSize;\n\n Object.freeze(this);\n }\n\n toJSON(): RTCRtcpParametersInit {\n return {\n cname: this.cname,\n reducedSize: this.reducedSize\n };\n }\n}\n"],"mappings":";;;;;;;AAKe,MAAMA,iBAAiB,CAAC;EAInCC,WAAWA,CAACC,IAA2B,EAAE;IAAAC,eAAA;IAAAA,eAAA;IACrC,IAAI,CAACC,KAAK,GAAGF,IAAI,CAACE,KAAK;IACvB,IAAI,CAACC,WAAW,GAAGH,IAAI,CAACG,WAAW;IAEnCC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC;EACvB;EAEAC,MAAMA,CAAA,EAA0B;IAC5B,OAAO;MACHJ,KAAK,EAAE,IAAI,CAACA,KAAK;MACjBC,WAAW,EAAE,IAAI,CAACA;IACtB,CAAC;EACL;AACJ;AAACI,OAAA,CAAAC,OAAA,GAAAV,iBAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCRtpCapabilities.js b/lib/commonjs/RTCRtpCapabilities.js new file mode 100644 index 000000000..3679cb1f5 --- /dev/null +++ b/lib/commonjs/RTCRtpCapabilities.js @@ -0,0 +1,22 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +/** + * @brief represents codec capabilities for senders and receivers. + */ +class RTCRtpCapabilities { + constructor(codecs) { + _defineProperty(this, "_codecs", []); + this._codecs = codecs; + Object.freeze(this); + } + get codecs() { + return this._codecs; + } +} +exports.default = RTCRtpCapabilities; +//# sourceMappingURL=RTCRtpCapabilities.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCRtpCapabilities.js.map b/lib/commonjs/RTCRtpCapabilities.js.map new file mode 100644 index 000000000..bb3d548b2 --- /dev/null +++ b/lib/commonjs/RTCRtpCapabilities.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtpCapabilities","constructor","codecs","_defineProperty","_codecs","Object","freeze","exports","default"],"sources":["RTCRtpCapabilities.ts"],"sourcesContent":["import RTCRtpCodecCapability from './RTCRtpCodecCapability';\n\n/**\n * @brief represents codec capabilities for senders and receivers.\n */\nexport default class RTCRtpCapabilities {\n _codecs: RTCRtpCodecCapability[] = [];\n constructor(codecs: RTCRtpCodecCapability[]) {\n this._codecs = codecs;\n Object.freeze(this);\n }\n\n get codecs() {\n return this._codecs;\n }\n}\n"],"mappings":";;;;;;;AAEA;AACA;AACA;AACe,MAAMA,kBAAkB,CAAC;EAEpCC,WAAWA,CAACC,MAA+B,EAAE;IAAAC,eAAA,kBADV,EAAE;IAEjC,IAAI,CAACC,OAAO,GAAGF,MAAM;IACrBG,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC;EACvB;EAEA,IAAIJ,MAAMA,CAAA,EAAG;IACT,OAAO,IAAI,CAACE,OAAO;EACvB;AACJ;AAACG,OAAA,CAAAC,OAAA,GAAAR,kBAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCRtpCodecCapability.js b/lib/commonjs/RTCRtpCodecCapability.js new file mode 100644 index 000000000..4d289adfc --- /dev/null +++ b/lib/commonjs/RTCRtpCodecCapability.js @@ -0,0 +1,19 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +class RTCRtpCodecCapability { + constructor(init) { + _defineProperty(this, "_mimeType", void 0); + this._mimeType = init.mimeType; + Object.freeze(this); + } + get mimeType() { + return this._mimeType; + } +} +exports.default = RTCRtpCodecCapability; +//# sourceMappingURL=RTCRtpCodecCapability.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCRtpCodecCapability.js.map b/lib/commonjs/RTCRtpCodecCapability.js.map new file mode 100644 index 000000000..ff8f778de --- /dev/null +++ b/lib/commonjs/RTCRtpCodecCapability.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtpCodecCapability","constructor","init","_defineProperty","_mimeType","mimeType","Object","freeze","exports","default"],"sources":["RTCRtpCodecCapability.ts"],"sourcesContent":["\nexport default class RTCRtpCodecCapability {\n _mimeType: string;\n\n constructor(init: { mimeType: string }) {\n this._mimeType = init.mimeType;\n Object.freeze(this);\n }\n\n get mimeType() {\n return this._mimeType;\n }\n}"],"mappings":";;;;;;;AACe,MAAMA,qBAAqB,CAAC;EAGvCC,WAAWA,CAACC,IAA0B,EAAE;IAAAC,eAAA;IACpC,IAAI,CAACC,SAAS,GAAGF,IAAI,CAACG,QAAQ;IAC9BC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC;EACvB;EAEA,IAAIF,QAAQA,CAAA,EAAG;IACX,OAAO,IAAI,CAACD,SAAS;EACzB;AACJ;AAACI,OAAA,CAAAC,OAAA,GAAAT,qBAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCRtpCodecParameters.js b/lib/commonjs/RTCRtpCodecParameters.js new file mode 100644 index 000000000..7cc5c201d --- /dev/null +++ b/lib/commonjs/RTCRtpCodecParameters.js @@ -0,0 +1,38 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +class RTCRtpCodecParameters { + constructor(init) { + _defineProperty(this, "payloadType", void 0); + _defineProperty(this, "clockRate", void 0); + _defineProperty(this, "mimeType", void 0); + _defineProperty(this, "channels", void 0); + _defineProperty(this, "sdpFmtpLine", void 0); + this.payloadType = init.payloadType; + this.clockRate = init.clockRate; + this.mimeType = init.mimeType; + this.channels = init.channels ? init.channels : null; + this.sdpFmtpLine = init.sdpFmtpLine ? init.sdpFmtpLine : null; + Object.freeze(this); + } + toJSON() { + const obj = { + payloadType: this.payloadType, + clockRate: this.clockRate, + mimeType: this.mimeType + }; + if (this.channels !== null) { + obj['channels'] = this.channels; + } + if (this.sdpFmtpLine !== null) { + obj['sdpFmtpLine'] = this.sdpFmtpLine; + } + return obj; + } +} +exports.default = RTCRtpCodecParameters; +//# sourceMappingURL=RTCRtpCodecParameters.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCRtpCodecParameters.js.map b/lib/commonjs/RTCRtpCodecParameters.js.map new file mode 100644 index 000000000..42220422f --- /dev/null +++ b/lib/commonjs/RTCRtpCodecParameters.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtpCodecParameters","constructor","init","_defineProperty","payloadType","clockRate","mimeType","channels","sdpFmtpLine","Object","freeze","toJSON","obj","exports","default"],"sources":["RTCRtpCodecParameters.ts"],"sourcesContent":["export interface RTCRtpCodecParametersInit {\n payloadType: number;\n clockRate: number;\n mimeType: string;\n channels?: number;\n sdpFmtpLine?: string;\n}\n\nexport default class RTCRtpCodecParameters {\n readonly payloadType: number;\n readonly clockRate: number;\n readonly mimeType: string;\n readonly channels: number | null;\n readonly sdpFmtpLine: string | null;\n\n constructor(init: RTCRtpCodecParametersInit) {\n this.payloadType = init.payloadType;\n this.clockRate = init.clockRate;\n this.mimeType = init.mimeType;\n\n this.channels = init.channels ? init.channels : null;\n this.sdpFmtpLine = init.sdpFmtpLine ? init.sdpFmtpLine : null;\n\n Object.freeze(this);\n }\n\n toJSON(): RTCRtpCodecParametersInit {\n const obj = {\n payloadType: this.payloadType,\n clockRate: this.clockRate,\n mimeType: this.mimeType\n };\n\n if (this.channels !== null) {\n obj['channels'] = this.channels;\n }\n\n if (this.sdpFmtpLine !== null) {\n obj['sdpFmtpLine'] = this.sdpFmtpLine;\n }\n\n return obj;\n }\n}\n"],"mappings":";;;;;;;AAQe,MAAMA,qBAAqB,CAAC;EAOvCC,WAAWA,CAACC,IAA+B,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACzC,IAAI,CAACC,WAAW,GAAGF,IAAI,CAACE,WAAW;IACnC,IAAI,CAACC,SAAS,GAAGH,IAAI,CAACG,SAAS;IAC/B,IAAI,CAACC,QAAQ,GAAGJ,IAAI,CAACI,QAAQ;IAE7B,IAAI,CAACC,QAAQ,GAAGL,IAAI,CAACK,QAAQ,GAAGL,IAAI,CAACK,QAAQ,GAAG,IAAI;IACpD,IAAI,CAACC,WAAW,GAAGN,IAAI,CAACM,WAAW,GAAGN,IAAI,CAACM,WAAW,GAAG,IAAI;IAE7DC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC;EACvB;EAEAC,MAAMA,CAAA,EAA8B;IAChC,MAAMC,GAAG,GAAG;MACRR,WAAW,EAAE,IAAI,CAACA,WAAW;MAC7BC,SAAS,EAAE,IAAI,CAACA,SAAS;MACzBC,QAAQ,EAAE,IAAI,CAACA;IACnB,CAAC;IAED,IAAI,IAAI,CAACC,QAAQ,KAAK,IAAI,EAAE;MACxBK,GAAG,CAAC,UAAU,CAAC,GAAG,IAAI,CAACL,QAAQ;IACnC;IAEA,IAAI,IAAI,CAACC,WAAW,KAAK,IAAI,EAAE;MAC3BI,GAAG,CAAC,aAAa,CAAC,GAAG,IAAI,CAACJ,WAAW;IACzC;IAEA,OAAOI,GAAG;EACd;AACJ;AAACC,OAAA,CAAAC,OAAA,GAAAd,qBAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCRtpEncodingParameters.js b/lib/commonjs/RTCRtpEncodingParameters.js new file mode 100644 index 000000000..9b0283039 --- /dev/null +++ b/lib/commonjs/RTCRtpEncodingParameters.js @@ -0,0 +1,78 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +class RTCRtpEncodingParameters { + constructor(init) { + var _init$rid, _init$maxBitrate, _init$maxFramerate, _init$scaleResolution; + _defineProperty(this, "active", void 0); + _defineProperty(this, "_rid", void 0); + _defineProperty(this, "_maxFramerate", void 0); + _defineProperty(this, "_maxBitrate", void 0); + _defineProperty(this, "_scaleResolutionDownBy", void 0); + this.active = init.active; + this._rid = (_init$rid = init.rid) !== null && _init$rid !== void 0 ? _init$rid : null; + this._maxBitrate = (_init$maxBitrate = init.maxBitrate) !== null && _init$maxBitrate !== void 0 ? _init$maxBitrate : null; + this._maxFramerate = (_init$maxFramerate = init.maxFramerate) !== null && _init$maxFramerate !== void 0 ? _init$maxFramerate : null; + this._scaleResolutionDownBy = (_init$scaleResolution = init.scaleResolutionDownBy) !== null && _init$scaleResolution !== void 0 ? _init$scaleResolution : null; + } + get rid() { + return this._rid; + } + get maxFramerate() { + return this._maxFramerate; + } + set maxFramerate(framerate) { + // eslint-disable-next-line eqeqeq + if (framerate != null && framerate > 0) { + this._maxFramerate = framerate; + } else { + this._maxFramerate = null; + } + } + get maxBitrate() { + return this._maxBitrate; + } + set maxBitrate(bitrate) { + // eslint-disable-next-line eqeqeq + if (bitrate != null && bitrate >= 0) { + this._maxBitrate = bitrate; + } else { + this._maxBitrate = null; + } + } + get scaleResolutionDownBy() { + return this._scaleResolutionDownBy; + } + set scaleResolutionDownBy(resolutionScale) { + // eslint-disable-next-line eqeqeq + if (resolutionScale != null && resolutionScale >= 1) { + this._scaleResolutionDownBy = resolutionScale; + } else { + this._scaleResolutionDownBy = null; + } + } + toJSON() { + const obj = { + active: Boolean(this.active) + }; + if (this._rid !== null) { + obj['rid'] = this._rid; + } + if (this._maxBitrate !== null) { + obj['maxBitrate'] = this._maxBitrate; + } + if (this._maxFramerate !== null) { + obj['maxFramerate'] = this._maxFramerate; + } + if (this._scaleResolutionDownBy !== null) { + obj['scaleResolutionDownBy'] = this._scaleResolutionDownBy; + } + return obj; + } +} +exports.default = RTCRtpEncodingParameters; +//# sourceMappingURL=RTCRtpEncodingParameters.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCRtpEncodingParameters.js.map b/lib/commonjs/RTCRtpEncodingParameters.js.map new file mode 100644 index 000000000..1573e25c7 --- /dev/null +++ b/lib/commonjs/RTCRtpEncodingParameters.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtpEncodingParameters","constructor","init","_init$rid","_init$maxBitrate","_init$maxFramerate","_init$scaleResolution","_defineProperty","active","_rid","rid","_maxBitrate","maxBitrate","_maxFramerate","maxFramerate","_scaleResolutionDownBy","scaleResolutionDownBy","framerate","bitrate","resolutionScale","toJSON","obj","Boolean","exports","default"],"sources":["RTCRtpEncodingParameters.ts"],"sourcesContent":["export interface RTCRtpEncodingParametersInit {\n active: boolean,\n rid?: string;\n maxFramerate?: number;\n maxBitrate?: number;\n scaleResolutionDownBy?: number;\n}\n\nexport default class RTCRtpEncodingParameters {\n active: boolean;\n _rid: string | null;\n _maxFramerate: number | null;\n _maxBitrate: number | null;\n _scaleResolutionDownBy: number | null;\n\n constructor(init: RTCRtpEncodingParametersInit) {\n this.active = init.active;\n this._rid = init.rid ?? null;\n this._maxBitrate = init.maxBitrate ?? null;\n this._maxFramerate = init.maxFramerate ?? null;\n this._scaleResolutionDownBy = init.scaleResolutionDownBy ?? null;\n }\n\n get rid() {\n return this._rid;\n }\n\n get maxFramerate() {\n return this._maxFramerate;\n }\n\n set maxFramerate(framerate) {\n // eslint-disable-next-line eqeqeq\n if (framerate != null && framerate > 0) {\n this._maxFramerate = framerate;\n } else {\n this._maxFramerate = null;\n }\n }\n\n get maxBitrate() {\n return this._maxBitrate;\n }\n\n set maxBitrate(bitrate) {\n // eslint-disable-next-line eqeqeq\n if (bitrate != null && bitrate >= 0) {\n this._maxBitrate = bitrate;\n } else {\n this._maxBitrate = null;\n }\n }\n\n get scaleResolutionDownBy() {\n return this._scaleResolutionDownBy;\n }\n\n set scaleResolutionDownBy(resolutionScale) {\n // eslint-disable-next-line eqeqeq\n if (resolutionScale != null && resolutionScale >= 1) {\n this._scaleResolutionDownBy = resolutionScale;\n } else {\n this._scaleResolutionDownBy = null;\n }\n }\n\n toJSON(): RTCRtpEncodingParametersInit {\n const obj = {\n active: Boolean(this.active),\n };\n\n if (this._rid !== null) {\n obj['rid'] = this._rid;\n }\n\n if (this._maxBitrate !== null) {\n obj['maxBitrate'] = this._maxBitrate;\n }\n\n if (this._maxFramerate !== null) {\n obj['maxFramerate'] = this._maxFramerate;\n }\n\n if (this._scaleResolution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IA,OAAO,IAAI,IAAI,IAAIA,OAAO,IAAI,CAAC,EAAE;MACjC,IAAI,CAACP,WAAW,GAAGO,OAAO;IAC9B,CAAC,MAAM;MACH,IAAI,CAACP,WAAW,GAAG,IAAI;IAC3B;EACJ;EAEA,IAAIK,qBAAqBA,CAAA,EAAG;IACxB,OAAO,IAAI,CAACD,sBAAsB;EACtC;EAEA,IAAIC,qBAAqBA,CAACG,eAAe,EAAE;IACvC;IACA,IAAIA,eAAe,IAAI,IAAI,IAAIA,eAAe,IAAI,CAAC,EAAE;MACjD,IAAI,CAACJ,sBAAsB,GAAGI,eAAe;IACjD,CAAC,MAAM;MACH,IAAI,CAACJ,sBAAsB,GAAG,IAAI;IACtC;EACJ;EAEAK,MAAMA,CAAA,EAAiC;IACnC,MAAMC,GAAG,GAAG;MACRb,MAAM,EAAEc,OAAO,CAAC,IAAI,CAACd,MAAM;IAC/B,CAAC;IAED,IAAI,IAAI,CAACC,IAAI,KAAK,IAAI,EAAE;MACpBY,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAACZ,IAAI;IAC1B;IAEA,IAAI,IAAI,CAACE,WAAW,KAAK,IAAI,EAAE;MAC3BU,GAAG,CAAC,YAAY,CAAC,GAAG,IAAI,CAACV,WAAW;IACxC;IAEA,IAAI,IAAI,CAACE,aAAa,KAAK,IAAI,EAAE;MAC7BQ,GAAG,CAAC,cAAc,CAAC,GAAG,IAAI,CAACR,aAAa;IAC5C;IAEA,IAAI,IAAI,CAACE,sBAAsB,KAAK,IAAI,EAAE;MACtCM,GAAG,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAACN,sBAAsB;IAC9D;IAEA,OAAOM,GAAG;EACd;AACJ;AAACE,OAAA,CAAAC,OAAA,GAAAxB,wBAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCRtpHeaderExtension.js b/lib/commonjs/RTCRtpHeaderExtension.js new file mode 100644 index 000000000..ffed1f898 --- /dev/null +++ b/lib/commonjs/RTCRtpHeaderExtension.js @@ -0,0 +1,27 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +class RTCRtpHeaderExtension { + constructor(init) { + _defineProperty(this, "id", void 0); + _defineProperty(this, "uri", void 0); + _defineProperty(this, "encrypted", void 0); + this.id = init.id; + this.uri = init.uri; + this.encrypted = init.encrypted; + Object.freeze(this); + } + toJSON() { + return { + id: this.id, + uri: this.uri, + encrypted: this.encrypted + }; + } +} +exports.default = RTCRtpHeaderExtension; +//# sourceMappingURL=RTCRtpHeaderExtension.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCRtpHeaderExtension.js.map b/lib/commonjs/RTCRtpHeaderExtension.js.map new file mode 100644 index 000000000..18dccee14 --- /dev/null +++ b/lib/commonjs/RTCRtpHeaderExtension.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtpHeaderExtension","constructor","init","_defineProperty","id","uri","encrypted","Object","freeze","toJSON","exports","default"],"sources":["RTCRtpHeaderExtension.ts"],"sourcesContent":["export interface RTCRtpHeaderExtensionInit {\n id: number;\n uri: string;\n encrypted: boolean;\n}\n\nexport default class RTCRtpHeaderExtension {\n readonly id: number;\n readonly uri: string;\n readonly encrypted: boolean;\n\n constructor(init: RTCRtpHeaderExtensionInit) {\n this.id = init.id;\n this.uri = init.uri;\n this.encrypted = init.encrypted;\n\n Object.freeze(this);\n }\n\n toJSON(): RTCRtpHeaderExtensionInit {\n return {\n id: this.id,\n uri: this.uri,\n encrypted: this.encrypted\n };\n }\n}\n"],"mappings":";;;;;;;AAMe,MAAMA,qBAAqB,CAAC;EAKvCC,WAAWA,CAACC,IAA+B,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACzC,IAAI,CAACC,EAAE,GAAGF,IAAI,CAACE,EAAE;IACjB,IAAI,CAACC,GAAG,GAAGH,IAAI,CAACG,GAAG;IACnB,IAAI,CAACC,SAAS,GAAGJ,IAAI,CAACI,SAAS;IAE/BC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC;EACvB;EAEAC,MAAMA,CAAA,EAA8B;IAChC,OAAO;MACHL,EAAE,EAAE,IAAI,CAACA,EAAE;MACXC,GAAG,EAAE,IAAI,CAACA,GAAG;MACbC,SAAS,EAAE,IAAI,CAACA;IACpB,CAAC;EACL;AACJ;AAACI,OAAA,CAAAC,OAAA,GAAAX,qBAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCRtpParameters.js b/lib/commonjs/RTCRtpParameters.js new file mode 100644 index 000000000..0cde971d4 --- /dev/null +++ b/lib/commonjs/RTCRtpParameters.js @@ -0,0 +1,35 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _RTCRtcpParameters = _interopRequireDefault(require("./RTCRtcpParameters")); +var _RTCRtpCodecParameters = _interopRequireDefault(require("./RTCRtpCodecParameters")); +var _RTCRtpHeaderExtension = _interopRequireDefault(require("./RTCRtpHeaderExtension")); +var _RTCUtil = require("./RTCUtil"); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +class RTCRtpParameters { + constructor(init) { + _defineProperty(this, "codecs", []); + _defineProperty(this, "headerExtensions", []); + _defineProperty(this, "rtcp", void 0); + for (const codec of init.codecs) { + this.codecs.push(new _RTCRtpCodecParameters.default(codec)); + } + for (const ext of init.headerExtensions) { + this.headerExtensions.push(new _RTCRtpHeaderExtension.default(ext)); + } + this.rtcp = new _RTCRtcpParameters.default(init.rtcp); + } + toJSON() { + return { + codecs: this.codecs.map(c => (0, _RTCUtil.deepClone)(c)), + headerExtensions: this.headerExtensions.map(he => (0, _RTCUtil.deepClone)(he)), + rtcp: (0, _RTCUtil.deepClone)(this.rtcp) + }; + } +} +exports.default = RTCRtpParameters; +//# sourceMappingURL=RTCRtpParameters.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCRtpParameters.js.map b/lib/commonjs/RTCRtpParameters.js.map new file mode 100644 index 000000000..548916758 --- /dev/null +++ b/lib/commonjs/RTCRtpParameters.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_RTCRtcpParameters","_interopRequireDefault","require","_RTCRtpCodecParameters","_RTCRtpHeaderExtension","_RTCUtil","obj","__esModule","default","_defineProperty","key","value","Object","defineProperty","enumerable","configurable","writable","RTCRtpParameters","constructor","init","codec","codecs","push","RTCRtpCodecParameters","ext","headerExtensions","RTCRtpHeaderExtension","rtcp","RTCRtcpParameters","toJSON","map","c","deepClone","he","exports"],"sources":["RTCRtpParameters.ts"],"sourcesContent":["import RTCRtcpParameters, { RTCRtcpParametersInit } from './RTCRtcpParameters';\nimport RTCRtpCodecParameters, { RTCRtpCodecParametersInit } from './RTCRtpCodecParameters';\nimport RTCRtpHeaderExtension, { RTCRtpHeaderExtensionInit } from './RTCRtpHeaderExtension';\nimport { deepClone } from './RTCUtil';\n\n\nexport interface RTCRtpParametersInit {\n codecs: RTCRtpCodecParametersInit[],\n headerExtensions: RTCRtpHeaderExtensionInit[],\n rtcp: RTCRtcpParametersInit\n}\n\nexport default class RTCRtpParameters {\n codecs: (RTCRtpCodecParameters | RTCRtpCodecParametersInit)[] = [];\n readonly headerExtensions: RTCRtpHeaderExtension[] = [];\n readonly rtcp: RTCRtcpParameters;\n\n constructor(init: RTCRtpParametersInit) {\n for (const codec of init.codecs) {\n this.codecs.push(new RTCRtpCodecParameters(codec));\n }\n\n for (const ext of init.headerExtensions) {\n this.headerExtensions.push(new RTCRtpHeaderExtension(ext));\n }\n\n this.rtcp = new RTCRtcpParameters(init.rtcp);\n }\n\n toJSON() {\n return {\n codecs: this.codecs.map(c => deepClone(c)),\n headerExtensions: this.headerExtensions.map(he => deepClone(he)),\n rtcp: deepClone(this.rtcp)\n };\n }\n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CAACA,gBAAgB,CAACK,GAAG,CAACG,EAAE,IAAI,IAAAD,kBAAS,EAACC,EAAE,CAAC,CAAC;MAChEN,IAAI,EAAE,IAAAK,kBAAS,EAAC,IAAI,CAACL,IAAI;IAC7B,CAAC;EACL;AACJ;AAACO,OAAA,CAAA1B,OAAA,GAAAS,gBAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCRtpReceiveParameters.js b/lib/commonjs/RTCRtpReceiveParameters.js new file mode 100644 index 000000000..769419a21 --- /dev/null +++ b/lib/commonjs/RTCRtpReceiveParameters.js @@ -0,0 +1,15 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _RTCRtpParameters = _interopRequireDefault(require("./RTCRtpParameters")); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +class RTCRtpReceiveParameters extends _RTCRtpParameters.default { + constructor(init) { + super(init); + } +} +exports.default = RTCRtpReceiveParameters; +//# sourceMappingURL=RTCRtpReceiveParameters.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCRtpReceiveParameters.js.map b/lib/commonjs/RTCRtpReceiveParameters.js.map new file mode 100644 index 000000000..6142a6ba5 --- /dev/null +++ b/lib/commonjs/RTCRtpReceiveParameters.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_RTCRtpParameters","_interopRequireDefault","require","obj","__esModule","default","RTCRtpReceiveParameters","RTCRtpParameters","constructor","init","exports"],"sources":["RTCRtpReceiveParameters.ts"],"sourcesContent":["import RTCRtpParameters, { RTCRtpParametersInit } from './RTCRtpParameters';\n\nexport default class RTCRtpReceiveParameters extends RTCRtpParameters {\n constructor(init: RTCRtpParametersInit) {\n super(init);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA4E,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE7D,MAAMG,uBAAuB,SAASC,yBAAgB,CAAC;EAClEC,WAAWA,CAACC,IAA0B,EAAE;IACpC,KAAK,CAACA,IAAI,CAAC;EACf;AACJ;AAACC,OAAA,CAAAL,OAAA,GAAAC,uBAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCRtpReceiver.js b/lib/commonjs/RTCRtpReceiver.js new file mode 100644 index 000000000..1bf60f9c5 --- /dev/null +++ b/lib/commonjs/RTCRtpReceiver.js @@ -0,0 +1,53 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _reactNative = require("react-native"); +var _RTCRtpReceiveParameters = _interopRequireDefault(require("./RTCRtpReceiveParameters")); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +const { + WebRTCModule +} = _reactNative.NativeModules; +class RTCRtpReceiver { + constructor(info) { + _defineProperty(this, "_id", void 0); + _defineProperty(this, "_peerConnectionId", void 0); + _defineProperty(this, "_track", null); + _defineProperty(this, "_rtpParameters", void 0); + this._id = info.id; + this._peerConnectionId = info.peerConnectionId; + this._rtpParameters = new _RTCRtpReceiveParameters.default(info.rtpParameters); + if (info.track) { + this._track = info.track; + } + } + static getCapabilities(kind) { + return WebRTCModule.receiverGetCapabilities(kind); + } + getStats() { + return WebRTCModule.receiverGetStats(this._peerConnectionId, this._id).then(data => + /* On both Android and iOS it is faster to construct a single + JSON string representing the Map of StatsReports and have it + pass through the React Native bridge rather than the Map of + StatsReports. While the implementations do try to be faster in + general, the stress is on being faster to pass through the React + Native bridge which is a bottleneck that tends to be visible in + the UI when there is congestion involving UI-related passing. + */ + new Map(JSON.parse(data))); + } + getParameters() { + return this._rtpParameters; + } + get id() { + return this._id; + } + get track() { + return this._track; + } +} +exports.default = RTCRtpReceiver; +//# sourceMappingURL=RTCRtpReceiver.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCRtpReceiver.js.map b/lib/commonjs/RTCRtpReceiver.js.map new file mode 100644 index 000000000..08647e445 --- /dev/null +++ b/lib/commonjs/RTCRtpReceiver.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_reactNative","require","_RTCRtpReceiveParameters","_interopRequireDefault","obj","__esModule","default","_defineProperty","key","value","Object","defineProperty","enumerable","configurable","writable","WebRTCModule","NativeModules","RTCRtpReceiver","constructor","info","_id","id","_peerConnectionId","peerConnectionId","_rtpParameters","RTCRtpReceiveParameters","rtpParameters","track","_track","getCapabilities","kind","receiverGetCapabilities","getStats","receiverGetStats","then","data","Map","JSON","parse","getParameters","exports"],"sources":["RTCRtpReceiver.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\nimport MediaStreamTrack from './MediaStreamTrack';\nimport RTCRtpCapabilities from './RTCRtpCapabilities';\nimport { RTCRtpParametersInit } from './RTCRtpParameters';\nimport RTCRtpReceiveParameters from './RTCRtpReceiveParameters';\n\nconst { WebRTCModule } = NativeModules;\n\nexport default class RTCRtpReceiver {\n _id: string;\n _peerConnectionId: number;\n _track: MediaStreamTrack | null = null;\n _rtpParameters: RTCRtpReceiveParameters;\n\n constructor(info: {\n peerConnectionId: number,\n id: string,\n track?: MediaStreamTrack,\n rtpParameters: RTCRtpParametersInit\n }) {\n this._id = info.id;\n this._peerConnectionId = info.peerConnectionId;\n this._rtpParameters = new RTCRtpReceiveParameters(info.rtpParameters);\n\n if (info.track) {\n this._track = info.track;\n }\n }\n\n static getCapabilities(kind: 'audio' | 'video'): RTCRtpCapabilities {\n return WebRTCModule.receiverGetCapabilities(kind);\n }\n\n getStats() {\n return WebRTCModule.receiverGetStats(this._peerConnectionId, this._id).then(data =>\n /* On both Android and iOS it is faster to construct a single\n JSON string representing the Map of StatsReports and have it\n pass through the React Native bridge rather than the Map of\n StatsReports. While the implementations do try to be faster in\n general, the stress is on being faster to pass through the React\n Native bridge which is a bottleneck that tends to be visible in\n the UI when there is congestion involving UI-related passing.\n */\n new Map(JSON.parse(data))\n );\n }\n\n getParameters(): RTCRtpReceiveParameters {\n return this._rtpParameters;\n }\n\n get id() {\n return this._id;\n }\n\n get track() {\n return this._track;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAKA,IAAAC,wBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAgE,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,QAAAD,GAAA,IAAAJ,GAAA,IAAAM,MAAA,CAAAC,cAAA,CAAAP,GAAA,EAAAI,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAG,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAV,GAAA,CAAAI,GAAA,IAAAC,KAAA,WAAAL,GAAA;AAEhE,MAAM;EAAEW;AAAa,CAAC,GAAGC,0BAAa;AAEvB,MAAMC,cAAc,CAAC;EAMhCC,WAAWA,CAACC,IAKX,EAAE;IAAAZ,eAAA;IAAAA,eAAA;IAAAA,eAAA,iBAR+B,IAAI;IAAAA,eAAA;IASlC,IAAI,CAACa,GAAG,GAAGD,IAAI,CAACE,EAAE;IAClB,IAAI,CAACC,iBAAiB,GAAGH,IAAI,CAACI,gBAAgB;IAC9C,IAAI,CAACC,cAAc,GAAG,IAAIC,gCAAuB,CAACN,IAAI,CAACO,aAAa,CAAC;IAErE,IAAIP,IAAI,CAACQ,KAAK,EAAE;MACZ,IAAI,CAACC,MAAM,GAAGT,IAAI,CAACQ,KAAK;IAC5B;EACJ;EAEA,OAAOE,eAAeA,CAACC,IAAuB,EAAsB;IAChE,OAAOf,YAAY,CAACgB,uBAAuB,CAACD,IAAI,CAAC;EACrD;EAEAE,QAAQA,CAAA,EAAG;IACP,OAAOjB,YAAY,CAACkB,gBAAgB,CAAC,IAAI,CAACX,iBAAiB,EAAE,IAAI,CAACF,GAAG,CAAC,CAACc,IAAI,CAACC,IAAI;IAC5E;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;IACY,IAAIC,GAAG,CAACC,IAAI,CAACC,KAAK,CAACH,IAAI,CAAC,CAC5B,CAAC;EACL;EAEAI,aAAaA,CAAA,EAA4B;IACrC,OAAO,IAAI,CAACf,cAAc;EAC9B;EAEA,IAAIH,EAAEA,CAAA,EAAG;IACL,OAAO,IAAI,CAACD,GAAG;EACnB;EAEA,IAAIO,KAAKA,CAAA,EAAG;IACR,OAAO,IAAI,CAACC,MAAM;EACtB;AACJ;AAACY,OAAA,CAAAlC,OAAA,GAAAW,cAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCRtpSendParameters.js b/lib/commonjs/RTCRtpSendParameters.js new file mode 100644 index 000000000..db27292c4 --- /dev/null +++ b/lib/commonjs/RTCRtpSendParameters.js @@ -0,0 +1,49 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _RTCRtpEncodingParameters = _interopRequireDefault(require("./RTCRtpEncodingParameters")); +var _RTCRtpParameters = _interopRequireDefault(require("./RTCRtpParameters")); +var _RTCUtil = require("./RTCUtil"); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +/** + * Class to convert degradation preference format. Native has a format such as + * MAINTAIN_FRAMERATE whereas the web APIs expect maintain-framerate + */ +class DegradationPreference { + static fromNative(nativeFormat) { + const stringFormat = nativeFormat.toLowerCase().replace('_', '-'); + return stringFormat; + } + static toNative(format) { + return format.toUpperCase().replace('-', '_'); + } +} +class RTCRtpSendParameters extends _RTCRtpParameters.default { + constructor(init) { + super(init); + _defineProperty(this, "transactionId", void 0); + _defineProperty(this, "encodings", void 0); + _defineProperty(this, "degradationPreference", void 0); + this.transactionId = init.transactionId; + this.encodings = []; + this.degradationPreference = init.degradationPreference ? DegradationPreference.fromNative(init.degradationPreference) : null; + for (const enc of init.encodings) { + this.encodings.push(new _RTCRtpEncodingParameters.default(enc)); + } + } + toJSON() { + const obj = super.toJSON(); + obj['transactionId'] = this.transactionId; + obj['encodings'] = this.encodings.map(e => (0, _RTCUtil.deepClone)(e)); + if (this.degradationPreference !== null) { + obj['degradationPreference'] = DegradationPreference.toNative(this.degradationPreference); + } + return obj; + } +} +exports.default = RTCRtpSendParameters; +//# sourceMappingURL=RTCRtpSendParameters.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCRtpSendParameters.js.map b/lib/commonjs/RTCRtpSendParameters.js.map new file mode 100644 index 000000000..e2ffcc361 --- /dev/null +++ b/lib/commonjs/RTCRtpSendParameters.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_RTCRtpEncodingParameters","_interopRequireDefault","require","_RTCRtpParameters","_RTCUtil","obj","__esModule","default","_defineProperty","key","value","Object","defineProperty","enumerable","configurable","writable","DegradationPreference","fromNative","nativeFormat","stringFormat","toLowerCase","replace","toNative","format","toUpperCase","RTCRtpSendParameters","RTCRtpParameters","constructor","init","transactionId","encodings","degradationPreference","enc","push","RTCRtpEncodingParameters","toJSON","map","e","deepClone","exports"],"sources":["RTCRtpSendParameters.ts"],"sourcesContent":["import RTCRtpEncodingParameters, { RTCRtpEncodingParametersInit } from './RTCRtpEncodingParameters';\nimport RTCRtpParameters, { RTCRtpParametersInit } from './RTCRtpParameters';\nimport { deepClone } from './RTCUtil';\n\ntype DegradationPreferenceType = 'maintain-framerate'\n | 'maintain-resolution'\n | 'balanced'\n | 'disabled'\n\n\n/**\n * Class to convert degradation preference format. Native has a format such as\n * MAINTAIN_FRAMERATE whereas the web APIs expect maintain-framerate\n */\nclass DegradationPreference {\n static fromNative(nativeFormat: string): DegradationPreferenceType {\n const stringFormat = nativeFormat.toLowerCase().replace('_', '-');\n\n return stringFormat as DegradationPreferenceType;\n }\n\n static toNative(format: DegradationPreferenceType): string {\n return format.toUpperCase().replace('-', '_');\n }\n}\n\nexport interface RTCRtpSendParametersInit extends RTCRtpParametersInit {\n transactionId: string;\n encodings: RTCRtpEncodingParametersInit[];\n degradationPreference?: string;\n}\n\nexport default class RTCRtpSendParameters extends RTCRtpParameters {\n readonly transactionId: string;\n encodings: (RTCRtpEncodingParameters | RTCRtpEncodingParametersInit)[];\n degradationPreference: DegradationPreferenceType | null;\n\n constructor(init: RTCRtpSendParametersInit) {\n super(init);\n\n this.transactionId = init.transactionId;\n this.encodings = [];\n this.degradationPreference = init.degradationPreference ?\n DegradationPreference.fromNative(init.degradationPreference) : null;\n\n for (const enc of init.encodings) {\n this.encodings.push(new RTCRtpEncodingParameters(enc));\n }\n }\n\n toJSON() {\n const obj = super.toJSON();\n\n obj['transactionId'] = this.transactionId;\n obj['encodings'] = this.encodings.map(e => deepClone(e));\n\n if (this.degradationPreference !== null) {\n obj['degradationPreference'] = DegradationPreference.toNative(this.degradationPreference);\n }\n\n return obj;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,yBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAAsC,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,QAAAD,GAAA,IAAAJ,GAAA,IAAAM,MAAA,CAAAC,cAAA,CAAAP,GAAA,EAAAI,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAG,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAV,GAAA,CAAAI,GAAA,IAAAC,KAAA,WAAAL,GAAA;AAQtC;AACA;AACA;AACA;AACA,MAAMW,qBAAqB,CAAC;EACxB,OAAOC,UAAUA,CAACC,YAAoB,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ACd;AACJ;AAACkC,OAAA,CAAAhC,OAAA,GAAAkB,oBAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCRtpSender.js b/lib/commonjs/RTCRtpSender.js new file mode 100644 index 000000000..d95b1fc2f --- /dev/null +++ b/lib/commonjs/RTCRtpSender.js @@ -0,0 +1,67 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _reactNative = require("react-native"); +var _RTCRtpSendParameters = _interopRequireDefault(require("./RTCRtpSendParameters")); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +const { + WebRTCModule +} = _reactNative.NativeModules; +class RTCRtpSender { + constructor(info) { + _defineProperty(this, "_id", void 0); + _defineProperty(this, "_track", null); + _defineProperty(this, "_peerConnectionId", void 0); + _defineProperty(this, "_rtpParameters", void 0); + this._peerConnectionId = info.peerConnectionId; + this._id = info.id; + this._rtpParameters = new _RTCRtpSendParameters.default(info.rtpParameters); + if (info.track) { + this._track = info.track; + } + } + async replaceTrack(track) { + try { + await WebRTCModule.senderReplaceTrack(this._peerConnectionId, this._id, track ? track.id : null); + } catch (e) { + return; + } + this._track = track; + } + static getCapabilities(kind) { + return WebRTCModule.senderGetCapabilities(kind); + } + getParameters() { + return this._rtpParameters; + } + async setParameters(parameters) { + // This allows us to get rid of private "underscore properties" + const _params = JSON.parse(JSON.stringify(parameters)); + const newParameters = await WebRTCModule.senderSetParameters(this._peerConnectionId, this._id, _params); + this._rtpParameters = new _RTCRtpSendParameters.default(newParameters); + } + getStats() { + return WebRTCModule.senderGetStats(this._peerConnectionId, this._id).then(data => + /* On both Android and iOS it is faster to construct a single + JSON string representing the Map of StatsReports and have it + pass through the React Native bridge rather than the Map of + StatsReports. While the implementations do try to be faster in + general, the stress is on being faster to pass through the React + Native bridge which is a bottleneck that tends to be visible in + the UI when there is congestion involving UI-related passing. + */ + new Map(JSON.parse(data))); + } + get track() { + return this._track; + } + get id() { + return this._id; + } +} +exports.default = RTCRtpSender; +//# sourceMappingURL=RTCRtpSender.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCRtpSender.js.map b/lib/commonjs/RTCRtpSender.js.map new file mode 100644 index 000000000..8f74e1b34 --- /dev/null +++ b/lib/commonjs/RTCRtpSender.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_reactNative","require","_RTCRtpSendParameters","_interopRequireDefault","obj","__esModule","default","_defineProperty","key","value","Object","defineProperty","enumerable","configurable","writable","WebRTCModule","NativeModules","RTCRtpSender","constructor","info","_peerConnectionId","peerConnectionId","_id","id","_rtpParameters","RTCRtpSendParameters","rtpParameters","track","_track","replaceTrack","senderReplaceTrack","e","getCapabilities","kind","senderGetCapabilities","getParameters","setParameters","parameters","_params","JSON","parse","stringify","newParameters","senderSetParameters","getStats","senderGetStats","then","data","Map","exports"],"sources":["RTCRtpSender.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\nimport MediaStreamTrack from './MediaStreamTrack';\nimport RTCRtpCapabilities from './RTCRtpCapabilities';\nimport RTCRtpSendParameters, { RTCRtpSendParametersInit } from './RTCRtpSendParameters';\n\nconst { WebRTCModule } = NativeModules;\n\n\nexport default class RTCRtpSender {\n _id: string;\n _track: MediaStreamTrack | null = null;\n _peerConnectionId: number;\n _rtpParameters: RTCRtpSendParameters;\n\n constructor(info: {\n peerConnectionId: number,\n id: string,\n track?: MediaStreamTrack,\n rtpParameters: RTCRtpSendParametersInit\n }) {\n this._peerConnectionId = info.peerConnectionId;\n this._id = info.id;\n this._rtpParameters = new RTCRtpSendParameters(info.rtpParameters);\n\n if (info.track) {\n this._track = info.track;\n }\n }\n\n async replaceTrack(track: MediaStreamTrack | null): Promise {\n try {\n await WebRTCModule.senderReplaceTrack(this._peerConnectionId, this._id, track ? track.id : null);\n } catch (e) {\n return;\n }\n\n this._track = track;\n }\n\n static getCapabilities(kind: 'audio' | 'video'): RTCRtpCapabilities {\n return WebRTCModule.senderGetCapabilities(kind);\n }\n\n getParameters(): RTCRtpSendParameters {\n return this._rtpParameters;\n }\n\n async setParameters(parameters: RTCRtpSendParameters): Promise {\n // This allows us to get rid of private \"underscore properties\"\n const _params = JSON.parse(JSON.stringify(parameters));\n const newParameters = await WebRTCModule.senderSetParameters(this._peerConnectionId, this._id, _params);\n\n this._rtpParameters = new RTCRtpSendParameters(newParameters);\n }\n\n getStats() {\n return WebRTCModule.senderGetStats(this._peerConnectionId, this._id).then(data =>\n /* On both Android and iOS it is faster to construct a single\n JSON string representing the Map of StatsReports and have it\n pass through the React Native bridge rather than the Map of\n StatsReports. While the implementations do try to be faster in\n general, the stress is on being faster to pass through the React\n Native bridge which is a bottleneck that tends to be visible in\n the UI when there is congestion involving UI-related passing.\n */\n new Map(JSON.parse(data))\n );\n }\n\n get track() {\n return this._track;\n }\n\n get id() {\n return this._id;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAIA,IAAAC,qBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAwF,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,QAAAD,GAAA,IAAAJ,GAAA,IAAAM,MAAA,CAAAC,cAAA,CAAAP,GAAA,EAAAI,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAG,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAV,GAAA,CAAAI,GAAA,IAAAC,KAAA,WAAAL,GAAA;AAExF,MAAM;EAAEW;AAAa,CAAC,GAAGC,0BAAa;AAGvB,MAAMC,YAAY,CAAC;EAM9BC,WAAWA,CAACC,IAKX,EAAE;IAAAZ,eAAA;IAAAA,eAAA,iBAT+B,IAAI;IAAAA,eAAA;IAAAA,eAAA;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;AACA;AACA;AACA;AACA;AACA;AACA;IACY,IAAIC,GAAG,CAACT,IAAI,CAACC,KAAK,CAACO,IAAI,CAAC,CAC5B,CAAC;EACL;EAEA,IAAIpB,KAAKA,CAAA,EAAG;IACR,OAAO,IAAI,CAACC,MAAM;EACtB;EAEA,IAAIL,EAAEA,CAAA,EAAG;IACL,OAAO,IAAI,CAACD,GAAG;EACnB;AACJ;AAAC2B,OAAA,CAAA3C,OAAA,GAAAW,YAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCRtpTransceiver.js b/lib/commonjs/RTCRtpTransceiver.js new file mode 100644 index 000000000..781a6f4d9 --- /dev/null +++ b/lib/commonjs/RTCRtpTransceiver.js @@ -0,0 +1,81 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _reactNative = require("react-native"); +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +const { + WebRTCModule +} = _reactNative.NativeModules; +class RTCRtpTransceiver { + constructor(args) { + var _args$mid, _args$currentDirectio; + _defineProperty(this, "_peerConnectionId", void 0); + _defineProperty(this, "_sender", void 0); + _defineProperty(this, "_receiver", void 0); + _defineProperty(this, "_mid", null); + _defineProperty(this, "_direction", void 0); + _defineProperty(this, "_currentDirection", void 0); + _defineProperty(this, "_stopped", void 0); + this._peerConnectionId = args.peerConnectionId; + this._mid = (_args$mid = args.mid) !== null && _args$mid !== void 0 ? _args$mid : null; + this._direction = args.direction; + this._currentDirection = (_args$currentDirectio = args.currentDirection) !== null && _args$currentDirectio !== void 0 ? _args$currentDirectio : null; + this._stopped = Boolean(args.isStopped); + this._sender = args.sender; + this._receiver = args.receiver; + } + get mid() { + return this._mid; + } + get stopped() { + return this._stopped; + } + get direction() { + return this._direction; + } + set direction(val) { + if (!['sendonly', 'recvonly', 'sendrecv', 'inactive'].includes(val)) { + throw new TypeError('Invalid direction provided'); + } + if (this._stopped) { + throw new Error('Transceiver Stopped'); + } + if (this._direction === val) { + return; + } + const oldDirection = this._direction; + WebRTCModule.transceiverSetDirection(this._peerConnectionId, this.sender.id, val).catch(() => { + this._direction = oldDirection; + }); + this._direction = val; + } + get currentDirection() { + return this._currentDirection; + } + get sender() { + return this._sender; + } + get receiver() { + return this._receiver; + } + stop() { + if (this._stopped) { + return; + } + WebRTCModule.transceiverStop(this._peerConnectionId, this.sender.id).then(() => this._setStopped()); + } + setCodecPreferences(codecs) { + WebRTCModule.transceiverSetCodecPreferences(this._peerConnectionId, this.sender.id, codecs); + } + _setStopped() { + this._stopped = true; + this._direction = 'stopped'; + this._currentDirection = 'stopped'; + this._mid = null; + } +} +exports.default = RTCRtpTransceiver; +//# sourceMappingURL=RTCRtpTransceiver.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCRtpTransceiver.js.map b/lib/commonjs/RTCRtpTransceiver.js.map new file mode 100644 index 000000000..b53346be6 --- /dev/null +++ b/lib/commonjs/RTCRtpTransceiver.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_reactNative","require","_defineProperty","obj","key","value","Object","defineProperty","enumerable","configurable","writable","WebRTCModule","NativeModules","RTCRtpTransceiver","constructor","args","_args$mid","_args$currentDirectio","_peerConnectionId","peerConnectionId","_mid","mid","_direction","direction","_currentDirection","currentDirection","_stopped","Boolean","isStopped","_sender","sender","_receiver","receiver","stopped","val","includes","TypeError","Error","oldDirection","transceiverSetDirection","id","catch","stop","transceiverStop","then","_setStopped","setCodecPreferences","codecs","transceiverSetCodecPreferences","exports","default"],"sources":["RTCRtpTransceiver.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\nimport RTCRtpCodecCapability from './RTCRtpCodecCapability';\nimport RTCRtpReceiver from './RTCRtpReceiver';\nimport RTCRtpSender from './RTCRtpSender';\n\nconst { WebRTCModule } = NativeModules;\n\nexport default class RTCRtpTransceiver {\n _peerConnectionId: number;\n _sender: RTCRtpSender;\n _receiver: RTCRtpReceiver;\n\n _mid: string | null = null;\n _direction: string;\n _currentDirection: string;\n _stopped: boolean;\n\n constructor(args: {\n peerConnectionId: number,\n isStopped: boolean,\n direction: string,\n currentDirection: string,\n mid?: string,\n sender: RTCRtpSender,\n receiver: RTCRtpReceiver,\n }) {\n this._peerConnectionId = args.peerConnectionId;\n this._mid = args.mid ?? null;\n this._direction = args.direction;\n this._currentDirection = args.currentDirection ?? null;\n this._stopped = Boolean(args.isStopped);\n this._sender = args.sender;\n this._receiver = args.receiver;\n }\n\n get mid() {\n return this._mid;\n }\n\n get stopped() {\n return this._stopped;\n }\n\n get direction() {\n return this._direction;\n }\n\n set direction(val) {\n if (![ 'sendonly', 'recvonly', 'sendrecv', 'inactive' ].includes(val)) {\n throw new TypeError('Invalid direction provided');\n }\n\n if (this._stopped) {\n throw new Error('Transceiver Stopped');\n }\n\n if (this._direction === val) {\n return;\n }\n\n const oldDirection = this._direction;\n\n WebRTCModule.transceiverSetDirection(this._peerConnectionId, this.sender.id, val)\n .catch(() => {\n this._direction = oldDirection;\n });\n\n this._direction = val;\n }\n\n get currentDirection() {\n return this._currentDirection;\n }\n\n get sender() {\n return this._sender;\n }\n\n get receiver() {\n return this._receiver;\n }\n\n stop() {\n if (this._stopped) {\n return;\n }\n\n WebRTCModule.transceiverStop(this._peerConnectionId, this.sender.id)\n .then(() => this._setStopped());\n }\n\n setCodecPreferences(codecs: RTCRtpCodecCapability[]) {\n WebRTCModule.transceiverSetCodecPreferences(\n this._peerConnectionId,\n this.sender.id,\n codecs\n );\n }\n\n _setStopped() {\n this._stopped = true;\n this._direction = 'stopped';\n this._currentDirection = 'stopped';\n this._mid = null;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAA6C,SAAAC,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,QAAAD,GAAA,IAAAD,GAAA,IAAAG,MAAA,CAAAC,cAAA,CAAAJ,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,E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;AACJ;AAAC6B,OAAA,CAAAC,OAAA,GAAArC,iBAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCSessionDescription.js b/lib/commonjs/RTCSessionDescription.js new file mode 100644 index 000000000..85341065a --- /dev/null +++ b/lib/commonjs/RTCSessionDescription.js @@ -0,0 +1,33 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +class RTCSessionDescription { + constructor() { + let info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { + type: null, + sdp: '' + }; + _defineProperty(this, "_sdp", void 0); + _defineProperty(this, "_type", void 0); + this._sdp = info.sdp; + this._type = info.type; + } + get sdp() { + return this._sdp; + } + get type() { + return this._type; + } + toJSON() { + return { + sdp: this._sdp, + type: this._type + }; + } +} +exports.default = RTCSessionDescription; +//# sourceMappingURL=RTCSessionDescription.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCSessionDescription.js.map b/lib/commonjs/RTCSessionDescription.js.map new file mode 100644 index 000000000..25b6310a7 --- /dev/null +++ b/lib/commonjs/RTCSessionDescription.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCSessionDescription","constructor","info","arguments","length","undefined","type","sdp","_defineProperty","_sdp","_type","toJSON","exports","default"],"sources":["RTCSessionDescription.ts"],"sourcesContent":["\nexport interface RTCSessionDescriptionInit {\n sdp: string;\n type: string | null;\n}\n\nexport default class RTCSessionDescription {\n _sdp: string;\n _type: string | null;\n\n constructor(info: RTCSessionDescriptionInit = { type: null, sdp: '' }) {\n this._sdp = info.sdp;\n this._type = info.type;\n }\n\n get sdp(): string {\n return this._sdp;\n }\n\n get type(): string | null {\n return this._type;\n }\n\n toJSON(): RTCSessionDescriptionInit {\n return {\n sdp: this._sdp,\n type: this._type\n };\n }\n}\n"],"mappings":";;;;;;;AAMe,MAAMA,qBAAqB,CAAC;EAIvCC,WAAWA,CAAA,EAA4D;IAAA,IAA3DC,IAA+B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;MAAEG,IAAI,EAAE,IAAI;MAAEC,GAAG,EAAE;IAAG,CAAC;IAAAC,eAAA;IAAAA,eAAA;IACjE,IAAI,CAACC,IAAI,GAAGP,IAAI,CAACK,GAAG;IACpB,IAAI,CAACG,KAAK,GAAGR,IAAI,CAACI,IAAI;EAC1B;EAEA,IAAIC,GAAGA,CAAA,EAAW;IACd,OAAO,IAAI,CAACE,IAAI;EACpB;EAEA,IAAIH,IAAIA,CAAA,EAAkB;IACtB,OAAO,IAAI,CAACI,KAAK;EACrB;EAEAC,MAAMA,CAAA,EAA8B;IAChC,OAAO;MACHJ,GAAG,EAAE,IAAI,CAACE,IAAI;MACdH,IAAI,EAAE,IAAI,CAACI;IACf,CAAC;EACL;AACJ;AAACE,OAAA,CAAAC,OAAA,GAAAb,qBAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCTrackEvent.js b/lib/commonjs/RTCTrackEvent.js new file mode 100644 index 000000000..7c4b49e3e --- /dev/null +++ b/lib/commonjs/RTCTrackEvent.js @@ -0,0 +1,38 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _index = require("event-target-shim/index"); +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +/** + * @eventClass + * This event is fired whenever the Track is changed in PeerConnection. + * @param {TRACK_EVENTS} type - The type of event. + * @param {IRTCTrackEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/track_event MDN} for details. + */ +class RTCTrackEvent extends _index.Event { + /** @eventProperty */ + + /** @eventProperty */ + + /** @eventProperty */ + + /** @eventProperty */ + + constructor(type, eventInitDict) { + super(type, eventInitDict); + _defineProperty(this, "streams", []); + _defineProperty(this, "transceiver", void 0); + _defineProperty(this, "receiver", void 0); + _defineProperty(this, "track", void 0); + this.streams = eventInitDict.streams; + this.transceiver = eventInitDict.transceiver; + this.receiver = eventInitDict.transceiver.receiver; + this.track = eventInitDict.transceiver.receiver ? eventInitDict.transceiver.receiver.track : null; + } +} +exports.default = RTCTrackEvent; +//# sourceMappingURL=RTCTrackEvent.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCTrackEvent.js.map b/lib/commonjs/RTCTrackEvent.js.map new file mode 100644 index 000000000..8e004522b --- /dev/null +++ b/lib/commonjs/RTCTrackEvent.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_index","require","_defineProperty","obj","key","value","Object","defineProperty","enumerable","configurable","writable","RTCTrackEvent","Event","constructor","type","eventInitDict","streams","transceiver","receiver","track","exports","default"],"sources":["RTCTrackEvent.ts"],"sourcesContent":["import { Event } from 'event-target-shim/index';\n\nimport MediaStream from './MediaStream';\nimport type MediaStreamTrack from './MediaStreamTrack';\nimport RTCRtpReceiver from './RTCRtpReceiver';\nimport RTCRtpTransceiver from './RTCRtpTransceiver';\n\ntype TRACK_EVENTS = 'track'\n\ninterface IRTCTrackEventInitDict extends Event.EventInit {\n streams: MediaStream[]\n transceiver: RTCRtpTransceiver\n}\n\n/**\n * @eventClass\n * This event is fired whenever the Track is changed in PeerConnection.\n * @param {TRACK_EVENTS} type - The type of event.\n * @param {IRTCTrackEventInitDict} eventInitDict - The event init properties.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/track_event MDN} for details.\n */\nexport default class RTCTrackEvent extends Event {\n /** @eventProperty */\n readonly streams: MediaStream[] = [];\n\n /** @eventProperty */\n readonly transceiver: RTCRtpTransceiver;\n\n /** @eventProperty */\n readonly receiver: RTCRtpReceiver | null;\n\n /** @eventProperty */\n readonly track: MediaStreamTrack | null;\n\n constructor(type: TEventType, eventInitDict: IRTCTrackEventInitDict) {\n super(type, eventInitDict);\n this.streams = eventInitDict.streams;\n this.transceiver = eventInitDict.transceiver;\n this.receiver = eventInitDict.transceiver.receiver;\n this.track = eventInitDict.transceiver.receiver ? eventInitDict.transceiver.receiver.track : null;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAgD,SAAAC,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,QAAAD,GAAA,IAAAD,GAAA,IAAAG,MAAA,CAAAC,cAAA,CAAAJ,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAG,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAP,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAchD;AACA;AACA;AACA;AACA;AACA;AACA;AACe,MAAMQ,aAAa,SAA0CC,YAAK,CAAa;EAC1F;;EAGA;;EAGA;;EAGA;;EAGAC,WAAWA,CAACC,IAAgB,EAAEC,aAAqC,EAAE;IACjE,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAACb,eAAA,kBAZG,EAAE;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAahC,IAAI,CAACc,OAAO,GAAGD,aAAa,CAACC,OAAO;IACpC,IAAI,CAACC,WAAW,GAAGF,aAAa,CAACE,WAAW;IAC5C,IAAI,CAACC,QAAQ,GAAGH,aAAa,CAACE,WAAW,CAACC,QAAQ;IAClD,IAAI,CAACC,KAAK,GAAGJ,aAAa,CAACE,WAAW,CAACC,QAAQ,GAAGH,aAAa,CAACE,WAAW,CAACC,QAAQ,CAACC,KAAK,GAAG,IAAI;EACrG;AACJ;AAACC,OAAA,CAAAC,OAAA,GAAAV,aAAA"} \ No newline at end of file diff --git a/lib/commonjs/RTCUtil.js b/lib/commonjs/RTCUtil.js new file mode 100644 index 000000000..2660a121f --- /dev/null +++ b/lib/commonjs/RTCUtil.js @@ -0,0 +1,186 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.deepClone = deepClone; +exports.isSdpTypeValid = isSdpTypeValid; +exports.normalizeConstraints = normalizeConstraints; +exports.normalizeOfferOptions = normalizeOfferOptions; +exports.uniqueID = uniqueID; +const DEFAULT_AUDIO_CONSTRAINTS = {}; +const DEFAULT_VIDEO_CONSTRAINTS = { + facingMode: 'user', + frameRate: 30, + height: 720, + width: 1280 +}; +const FACING_MODES = ['user', 'environment']; +const ASPECT_RATIO = 16 / 9; +const STANDARD_OFFER_OPTIONS = { + icerestart: 'IceRestart', + offertoreceiveaudio: 'OfferToReceiveAudio', + offertoreceivevideo: 'OfferToReceiveVideo', + voiceactivitydetection: 'VoiceActivityDetection' +}; +const SDP_TYPES = ['offer', 'pranswer', 'answer', 'rollback']; +function getDefaultMediaConstraints(mediaType) { + switch (mediaType) { + case 'audio': + return DEFAULT_AUDIO_CONSTRAINTS; + case 'video': + return DEFAULT_VIDEO_CONSTRAINTS; + default: + throw new TypeError(`Invalid media type: ${mediaType}`); + } +} +function extractString(constraints, prop) { + const value = constraints[prop]; + const type = typeof value; + if (type === 'object') { + for (const v of ['exact', 'ideal']) { + if (value[v]) { + return value[v]; + } + } + } else if (type === 'string') { + return value; + } +} +function extractNumber(constraints, prop) { + const value = constraints[prop]; + const type = typeof value; + if (type === 'number') { + return Number.parseInt(value); + } else if (type === 'object') { + for (const v of ['exact', 'ideal', 'max', 'min']) { + if (value[v]) { + return Number.parseInt(value[v]); + } + } + } +} +function normalizeMediaConstraints(constraints, mediaType) { + switch (mediaType) { + case 'audio': + return constraints; + case 'video': + { + const c = { + deviceId: extractString(constraints, 'deviceId'), + facingMode: extractString(constraints, 'facingMode'), + frameRate: extractNumber(constraints, 'frameRate'), + height: extractNumber(constraints, 'height'), + width: extractNumber(constraints, 'width') + }; + if (!c.deviceId) { + delete c.deviceId; + } + if (!FACING_MODES.includes(c.facingMode)) { + c.facingMode = DEFAULT_VIDEO_CONSTRAINTS.facingMode; + } + if (!c.frameRate) { + c.frameRate = DEFAULT_VIDEO_CONSTRAINTS.frameRate; + } + if (!c.height && !c.width) { + c.height = DEFAULT_VIDEO_CONSTRAINTS.height; + c.width = DEFAULT_VIDEO_CONSTRAINTS.width; + } else if (!c.height && c.width) { + c.height = Math.round(c.width / ASPECT_RATIO); + } else if (!c.width && c.height) { + c.width = Math.round(c.height * ASPECT_RATIO); + } + return c; + } + default: + throw new TypeError(`Invalid media type: ${mediaType}`); + } +} + +/** + * Utility for creating short random strings from float point values. + * We take 4 characters from the end after converting to a string. + * Conversion to string gives us some letters as we don't want just numbers. + * Should be suitable to pass for enough randomness. + * + * @return {String} 4 random characters + */ +function chr4() { + return Math.random().toString(16).slice(-4); +} + +/** + * Put together a random string in UUIDv4 format {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} + * + * @return {String} uuidv4 + */ +function uniqueID() { + return `${chr4()}${chr4()}-${chr4()}-${chr4()}-${chr4()}-${chr4()}${chr4()}${chr4()}`; +} + +/** + * Utility for deep cloning an object. Object.assign() only does a shallow copy. + * + * @param {Object} obj - object to be cloned + * @return {Object} cloned obj + */ +function deepClone(obj) { + return JSON.parse(JSON.stringify(obj)); +} + +/** + * Checks whether an SDP type is valid or not. + * + * @param type SDP type to check. + * @returns Whether the SDP type is valid or not. + */ +function isSdpTypeValid(type) { + return SDP_TYPES.includes(type); +} + +/** + * Normalize options passed to createOffer(). + * + * @param options - user supplied options + * @return Normalized options + */ +function normalizeOfferOptions(options) { + const newOptions = {}; + if (typeof options !== 'object') { + return newOptions; + } + + // Convert standard options into WebRTC internal constant names. + // See: https://github.com/jitsi/webrtc/blob/0cd6ce4de669bed94ba47b88cb71b9be0341bb81/sdk/media_constraints.cc#L113 + for (const [key, value] of Object.entries(options)) { + const newKey = STANDARD_OFFER_OPTIONS[key.toLowerCase()]; + if (newKey) { + newOptions[newKey] = String(Boolean(value)); + } + } + return newOptions; +} + +/** + * Normalize the given constraints in something we can work with. + */ +function normalizeConstraints(constraints) { + const c = deepClone(constraints); + for (const mediaType of ['audio', 'video']) { + const mediaTypeConstraints = c[mediaType]; + const typeofMediaTypeConstraints = typeof mediaTypeConstraints; + if (typeofMediaTypeConstraints !== 'undefined') { + if (typeofMediaTypeConstraints === 'boolean') { + if (mediaTypeConstraints) { + c[mediaType] = getDefaultMediaConstraints(mediaType); + } + } else if (typeofMediaTypeConstraints === 'object') { + c[mediaType] = normalizeMediaConstraints(mediaTypeConstraints, mediaType); + } else { + throw new TypeError(`constraints.${mediaType} is neither a boolean nor a dictionary`); + } + } + } + return c; +} +//# sourceMappingURL=RTCUtil.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCUtil.js.map b/lib/commonjs/RTCUtil.js.map new file mode 100644 index 000000000..3d1a953de --- /dev/null +++ b/lib/commonjs/RTCUtil.js.map @@ -0,0 +1 @@ +{"version":3,"names":["DEFAULT_AUDIO_CONSTRAINTS","DEFAULT_VIDEO_CONSTRAINTS","facingMode","frameRate","height","width","FACING_MODES","ASPECT_RATIO","STANDARD_OFFER_OPTIONS","icerestart","offertoreceiveaudio","offertoreceivevideo","voiceactivitydetection","SDP_TYPES","getDefaultMediaConstraints","mediaType","TypeError","extractString","constraints","prop","value","type","v","extractNumber","Number","parseInt","normalizeMediaConstraints","c","deviceId","includes","Math","round","chr4","random","toString","slice","uniqueID","deepClone","obj","JSON","parse","stringify","isSdpTypeValid","normalizeOfferOptions","options","newOptions","key","Object","entries","newKey","toLowerCase","String","Boolean","normalizeConstraints","mediaTypeConstraints","typeofMediaTypeConstraints"],"sources":["RTCUtil.ts"],"sourcesContent":["\nconst DEFAULT_AUDIO_CONSTRAINTS = {};\n\nconst DEFAULT_VIDEO_CONSTRAINTS = {\n facingMode: 'user',\n frameRate: 30,\n height: 720,\n width: 1280\n};\n\nconst FACING_MODES = [ 'user', 'environment' ];\n\nconst ASPECT_RATIO = 16 / 9;\n\nexport type RTCOfferOptions = {\n iceRestart?:boolean;\n offerToReceiveAudio?: boolean;\n offerToReceiveVideo?: boolean;\n voiceActivityDetection?:boolean\n};\n\nconst STANDARD_OFFER_OPTIONS = {\n icerestart: 'IceRestart',\n offertoreceiveaudio: 'OfferToReceiveAudio',\n offertoreceivevideo: 'OfferToReceiveVideo',\n voiceactivitydetection: 'VoiceActivityDetection'\n};\n\nconst SDP_TYPES = [\n 'offer',\n 'pranswer',\n 'answer',\n 'rollback'\n];\n\nfunction getDefaultMediaConstraints(mediaType) {\n switch (mediaType) {\n case 'audio':\n return DEFAULT_AUDIO_CONSTRAINTS;\n case 'video':\n return DEFAULT_VIDEO_CONSTRAINTS;\n default:\n throw new TypeError(`Invalid media type: ${mediaType}`);\n }\n}\n\nfunction extractString(constraints, prop) {\n const value = constraints[prop];\n const type = typeof value;\n\n if (type === 'object') {\n for (const v of [ 'exact', 'ideal' ]) {\n if (value[v]) {\n return value[v];\n }\n }\n } else if (type === 'string') {\n return value;\n }\n}\n\nfunction extractNumber(constraints, prop) {\n const value = constraints[prop];\n const type = typeof value;\n\n if (type === 'number') {\n return Number.parseInt(value);\n } else if (type === 'object') {\n for (const v of [ 'exact', 'ideal', 'max', 'min' ]) {\n if (value[v]) {\n return Number.parseInt(value[v]);\n }\n }\n }\n}\n\nfunction normalizeMediaConstraints(constraints, mediaType) {\n switch (mediaType) {\n case 'audio':\n return constraints;\n\n case 'video': {\n const c = {\n deviceId: extractString(constraints, 'deviceId'),\n facingMode: extractString(constraints, 'facingMode'),\n frameRate: extractNumber(constraints, 'frameRate'),\n height: extractNumber(constraints, 'height'),\n width: extractNumber(constraints, 'width')\n };\n\n if (!c.deviceId) {\n delete c.deviceId;\n }\n\n if (!FACING_MODES.includes(c.facingMode)) {\n c.facingMode = DEFAULT_VIDEO_CONSTRAINTS.facingMode;\n }\n\n if (!c.frameRate) {\n c.frameRate = DEFAULT_VIDEO_CONSTRAINTS.frameRate;\n }\n\n if (!c.height && !c.width) {\n c.height = DEFAULT_VIDEO_CONSTRAINTS.height;\n c.width = DEFAULT_VIDEO_CONSTRAINTS.width;\n } else if (!c.height && c.width) {\n c.height = Math.round(c.width / ASPECT_RATIO);\n } else if (!c.width && c.height) {\n c.width = Math.round(c.height * ASPECT_RATIO);\n }\n\n return c;\n }\n\n default:\n throw new TypeError(`Invalid media type: ${mediaType}`);\n }\n}\n\n/**\n * Utility for creating short random strings from float point values.\n * We take 4 characters from the end after converting to a string.\n * Conversion to string gives us some letters as we don't want just numbers.\n * Should be suitable to pass for enough randomness.\n *\n * @return {String} 4 random characters\n */\nfunction chr4() {\n return Math.random().toString(16).slice(-4);\n}\n\n/**\n * Put together a random string in UUIDv4 format {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\n *\n * @return {String} uuidv4\n */\nexport function uniqueID(): string {\n return `${chr4()}${chr4()}-${chr4()}-${chr4()}-${chr4()}-${chr4()}${chr4()}${chr4()}`;\n}\n\n/**\n * Utility for deep cloning an object. Object.assign() only does a shallow copy.\n *\n * @param {Object} obj - object to be cloned\n * @return {Object} cloned obj\n */\nexport function deepClone(obj: T): T {\n return JSON.parse(JSON.stringify(obj));\n}\n\n/**\n * Checks whether an SDP type is valid or not.\n *\n * @param type SDP type to check.\n * @returns Whether the SDP type is valid or not.\n */\nexport function isSdpTypeValid(type: string): boolean {\n return SDP_TYPES.includes(type);\n}\n\n/**\n * Normalize options passed to createOffer().\n *\n * @param options - user supplied options\n * @return Normalized options\n */\nexport function normalizeOfferOptions(options?: RTCOfferOptions) {\n const newOptions: Record = {};\n\n if (typeof options !== 'object') {\n return newOptions;\n }\n\n // Convert standard options into WebRTC internal constant names.\n // See: https://github.com/jitsi/webrtc/blob/0cd6ce4de669bed94ba47b88cb71b9be0341bb81/sdk/media_constraints.cc#L113\n for (const [ key, value ] of Object.entries(options)) {\n const newKey = STANDARD_OFFER_OPTIONS[key.toLowerCase()];\n\n if (newKey) {\n newOptions[newKey] = String(Boolean(value));\n }\n }\n\n return newOptions;\n}\n\n/**\n * Normalize the given constraints in something we can work with.\n */\nexport function normalizeConstraints(constraints) {\n const c = deepClone(constraints);\n\n for (const mediaType of [ 'audio', 'video' ]) {\n const mediaTypeConstraints = c[mediaType];\n const typeofMediaTypeConstraints = typeof mediaTypeConstraints;\n\n if (typeofMediaTypeConstraints !== 'undefined') {\n if (typeofMediaTypeConstraints === 'boolean') {\n if (mediaTypeConstraints) {\n c[mediaType] = getDefaultMediaConstraints(mediaType);\n }\n } else if (typeofMediaTypeConstraints === 'object') {\n c[mediaType] = normalizeMediaConstraints(mediaTypeConstraints, mediaType);\n } else {\n throw new TypeError(`constraints.${mediaType} is neither a boolean nor a dictionary`);\n }\n }\n }\n\n return c;\n}\n"],"mappings":";;;;;;;;;;AACA,MAAMA,yBAAyB,GAAG,CAAC,CAAC;AAEpC,MAAMC,yBAAyB,GAAG;EAC9BC,UAAU,EAAE,MAAM;EAClBC,SAAS,EAAE,EAAE;EACbC,MAAM,EAAE,GAAG;EACXC,KAAK,EAAE;AACX,CAAC;AAED,MAAMC,YAAY,GAAG,CAAE,MAAM,EAAE,aAAa,CAAE;AAE9C,MAAMC,YAAY,GAAG,EAAE,GAAG,CAAC;AAS3B,MAAMC,sBAAsB,GAAG;EAC3BC,UAAU,EAAE,YAAY;EACxBC,mBAAmB,EAAE,qBAAqB;EAC1CC,mBAAmB,EAAE,qBAAqB;EAC1CC,sBAAsB,EAAE;AAC5B,CAAC;AAED,MAAMC,SAAS,GAAG,CACd,OAAO,EACP,UAAU,EACV,QAAQ,EACR,UAAU,CACb;AAED,SAASC,0BAA0BA,CAACC,SAAS,EAAE;EAC3C,QAAQA,SAAS;IACb,KAAK,OAAO;MACR,OAAOf,yBAAyB;IACpC,KAAK,OAAO;MACR,OAAOC,yBAAyB;IACpC;MACI,MAAM,IAAIe,SAAS,CAAE,uBAAsBD,SAAU,EAAC,CAAC;EAC/D;AACJ;AAEA,SAASE,aAAaA,CAACC,WAAW,EAAEC,IAAI,EAAE;EACtC,MAAMC,KAAK,GAAGF,WAAW,CAACC,IAAI,CAAC;EAC/B,MAAME,IAAI,GAAG,OAAOD,KAAK;EAEzB,IAAIC,IAAI,KAAK,QAA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B,CAAC,CAACZ,SAAS,CAAC;IACzC,MAAMwC,0BAA0B,GAAG,OAAOD,oBAAoB;IAE9D,IAAIC,0BAA0B,KAAK,WAAW,EAAE;MAC5C,IAAIA,0BAA0B,KAAK,SAAS,EAAE;QAC1C,IAAID,oBAAoB,EAAE;UACtB3B,CAAC,CAACZ,SAAS,CAAC,GAAGD,0BAA0B,CAACC,SAAS,CAAC;QACxD;MACJ,CAAC,MAAM,IAAIwC,0BAA0B,KAAK,QAAQ,EAAE;QAChD5B,CAAC,CAACZ,SAAS,CAAC,GAAGW,yBAAyB,CAAC4B,oBAAoB,EAAEvC,SAAS,CAAC;MAC7E,CAAC,MAAM;QACH,MAAM,IAAIC,SAAS,CAAE,eAAcD,SAAU,wCAAuC,CAAC;MACzF;IACJ;EACJ;EAEA,OAAOY,CAAC;AACZ"} \ No newline at end of file diff --git a/lib/commonjs/RTCView.js b/lib/commonjs/RTCView.js new file mode 100644 index 000000000..d6cd8796b --- /dev/null +++ b/lib/commonjs/RTCView.js @@ -0,0 +1,16 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _reactNative = require("react-native"); +/** + * Native prop validation was removed from RN in: + * https://github.com/facebook/react-native/commit/8dc3ba0444c94d9bbb66295b5af885bff9b9cd34 + * + * So we list them here for documentation purposes. + */ +var _default = (0, _reactNative.requireNativeComponent)("RTCVideoView"); +exports.default = _default; +//# sourceMappingURL=RTCView.js.map \ No newline at end of file diff --git a/lib/commonjs/RTCView.js.map b/lib/commonjs/RTCView.js.map new file mode 100644 index 000000000..6dd9a2d01 --- /dev/null +++ b/lib/commonjs/RTCView.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_reactNative","require","_default","requireNativeComponent","exports","default"],"sources":["RTCView.ts"],"sourcesContent":["import { requireNativeComponent, ViewProps } from \"react-native\";\n\n/**\n * Native prop validation was removed from RN in:\n * https://github.com/facebook/react-native/commit/8dc3ba0444c94d9bbb66295b5af885bff9b9cd34\n *\n * So we list them here for documentation purposes.\n */\nexport interface RTCVideoViewProps extends ViewProps {\n customScale?: number;\n customTranslateX?: number; // as fraction of width (-1 to 1)\n customTranslateY?: number; // as fraction of height (-1 to 1)\n useCustomTransform?: boolean;\n /**\n * Android only. When true, uses TextureViewRenderer instead of\n * SurfaceViewRenderer. TextureView renders in the normal View hierarchy\n * and supports borderRadius, overflow:hidden, and other clipping.\n * Slightly higher GPU overhead but negligible for small views.\n *\n * Defaults to false (SurfaceView).\n */\n useTextureView?: boolean;\n /**\n * Indicates whether the video specified by {@link #streamURL} should be\n * mirrored during rendering. Commonly, applications choose to mirror the\n * user-facing camera.\n *\n * mirror: boolean\n */\n mirror?: boolean;\n\n /**\n * In the fashion of\n * https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth\n * and https://www.w3.org/TR/html5/rendering.html#video-object-fit,\n * resembles the CSS style object-fit.\n *\n * objectFit: 'contain' | 'cover'\n *\n * Defaults to 'cover'.\n */\n objectFit?: \"contain\" | \"cover\";\n\n /**\n * URL / id of the stream that should be rendered.\n *\n * streamURL: string\n */\n streamURL?: string;\n /**\n * Similarly to the CSS property z-index, specifies the z-order of this\n * RTCView in the stacking space of all RTCViews. When RTCViews overlap,\n * zOrder determines which one covers the other. An RTCView with a larger\n * zOrder generally covers an RTCView with a lower one.\n *\n * Non-overlapping RTCViews may safely share a z-order (because one does not\n * have to cover the other).\n *\n * The support for zOrder is platform-dependent and/or\n * implementation-specific. Thus, specifying a value for zOrder is to be\n * thought of as giving a hint rather than as imposing a requirement. For\n * example, video renderers such as RTCView are commonly implemented using\n * OpenGL and OpenGL views may have different numbers of layers in their\n * stacking space. Android has three: a layer bellow the window (aka\n * default), a layer bellow the window again but above the previous layer\n * (aka media overlay), and above the window. Consequently, it is advisable\n * to limit the number of utilized layers in the stacking space to the\n * minimum sufficient for the desired display. For example, a video call\n * application usually needs a maximum of two zOrder values: 0 for the\n * remote video(s) which appear in the background, and 1 for the local\n * video(s) which appear above the remote video(s).\n *\n * zOrder: number\n */\n zOrder?: number;\n\n /**\n * Picture in picture options for this view. Disabled if not supplied.\n *\n * Note: this should only be generally only used with remote video tracks,\n * as the local camera may stop while in the background.\n *\n * iOS only. Requires iOS 15.0 or above, and the PIP background mode capability.\n */\n iosPIP?: RTCIOSPIPOptions;\n\n /**\n * Callback function that is called when the dimensions of the video change.\n *\n * @param {Object} event - The event object containing the new dimensions.\n * @param {Object} event.nativeEvent - The native event data.\n * @param {number} event.nativeEvent.width - The width of the video.\n * @param {number} event.nativeEvent.height - The height of the video.\n */\n onDimensionsChange?: (event: {\n nativeEvent: { width: number; height: number };\n }) => void;\n}\n\nexport interface RTCIOSPIPOptions {\n /**\n * Whether PIP can be launched from this view.\n *\n * Defaults to true.\n */\n enabled?: boolean;\n\n /**\n * The preferred size of the PIP window.\n */\n preferredSize?: {\n width: number;\n height: number;\n };\n\n /**\n * Indicates whether Picture in Picture starts automatically\n * when the controller embeds its content inline and the app\n * transitions to the background.\n *\n * Defaults to true.\n *\n * See: AVPictureInPictureController.canStartPictureInPictureAutomaticallyFromInline\n */\n startAutomatically?: boolean;\n\n /**\n * Indicates whether Picture in Picture should stop automatically\n * when the app returns to the foreground.\n *\n * Defaults to true.\n */\n stopAutomatically?: boolean;\n}\nexport default requireNativeComponent(\"RTCVideoView\");\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AALA,IAAAC,QAAA,GAoIe,IAAAC,mCAAsB,EAAoB,cAAc,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAH,QAAA"} \ No newline at end of file diff --git a/lib/commonjs/ScreenCapturePickerView.js b/lib/commonjs/ScreenCapturePickerView.js new file mode 100644 index 000000000..11912f382 --- /dev/null +++ b/lib/commonjs/ScreenCapturePickerView.js @@ -0,0 +1,10 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _reactNative = require("react-native"); +var _default = (0, _reactNative.requireNativeComponent)('ScreenCapturePickerView'); +exports.default = _default; +//# sourceMappingURL=ScreenCapturePickerView.js.map \ No newline at end of file diff --git a/lib/commonjs/ScreenCapturePickerView.js.map b/lib/commonjs/ScreenCapturePickerView.js.map new file mode 100644 index 000000000..71bd2bcf5 --- /dev/null +++ b/lib/commonjs/ScreenCapturePickerView.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_reactNative","require","_default","requireNativeComponent","exports","default"],"sources":["ScreenCapturePickerView.ts"],"sourcesContent":["\nimport { requireNativeComponent } from 'react-native';\n\nexport default requireNativeComponent('ScreenCapturePickerView');\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAsD,IAAAC,QAAA,GAEvC,IAAAC,mCAAsB,EAAC,yBAAyB,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAH,QAAA"} \ No newline at end of file diff --git a/lib/commonjs/getDisplayMedia.js b/lib/commonjs/getDisplayMedia.js new file mode 100644 index 000000000..322a55862 --- /dev/null +++ b/lib/commonjs/getDisplayMedia.js @@ -0,0 +1,33 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = getDisplayMedia; +var _reactNative = require("react-native"); +var _MediaStream = _interopRequireDefault(require("./MediaStream")); +var _MediaStreamError = _interopRequireDefault(require("./MediaStreamError")); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +const { + WebRTCModule +} = _reactNative.NativeModules; +function getDisplayMedia() { + return new Promise((resolve, reject) => { + WebRTCModule.getDisplayMedia().then(data => { + const { + streamId, + track + } = data; + const info = { + streamId: streamId, + streamReactTag: streamId, + tracks: [track] + }; + const stream = new _MediaStream.default(info); + resolve(stream); + }, error => { + reject(new _MediaStreamError.default(error)); + }); + }); +} +//# sourceMappingURL=getDisplayMedia.js.map \ No newline at end of file diff --git a/lib/commonjs/getDisplayMedia.js.map b/lib/commonjs/getDisplayMedia.js.map new file mode 100644 index 000000000..6d530d9da --- /dev/null +++ b/lib/commonjs/getDisplayMedia.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_reactNative","require","_MediaStream","_interopRequireDefault","_MediaStreamError","obj","__esModule","default","WebRTCModule","NativeModules","getDisplayMedia","Promise","resolve","reject","then","data","streamId","track","info","streamReactTag","tracks","stream","MediaStream","error","MediaStreamError"],"sources":["getDisplayMedia.ts"],"sourcesContent":["\nimport { NativeModules } from 'react-native';\n\nimport MediaStream from './MediaStream';\nimport MediaStreamError from './MediaStreamError';\n\nconst { WebRTCModule } = NativeModules;\n\nexport default function getDisplayMedia(): Promise {\n return new Promise((resolve, reject) => {\n WebRTCModule.getDisplayMedia().then(\n data => {\n const { streamId, track } = data;\n\n const info = {\n streamId: streamId,\n streamReactTag: streamId,\n tracks: [ track ]\n };\n\n const stream = new MediaStream(info);\n\n resolve(stream);\n },\n error => {\n reject(new MediaStreamError(error));\n }\n );\n });\n}\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAD,sBAAA,CAAAF,OAAA;AAAkD,SAAAE,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAElD,MAAM;EAAEG;AAAa,CAAC,GAAGC,0BAAa;AAEvB,SAASC,eAAeA,CAAA,EAAyB;EAC5D,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACpCL,YAAY,CAACE,eAAe,CAAC,CAAC,CAACI,IAAI,CAC/BC,IAAI,IAAI;MACJ,MAAM;QAAEC,QAAQ;QAAEC;MAAM,CAAC,GAAGF,IAAI;MAEhC,MAAMG,IAAI,GAAG;QACTF,QAAQ,EAAEA,QAAQ;QAClBG,cAAc,EAAEH,QAAQ;QACxBI,MAAM,EAAE,CAAEH,KAAK;MACnB,CAAC;MAED,MAAMI,MAAM,GAAG,IAAIC,oBAAW,CAACJ,IAAI,CAAC;MAEpCN,OAAO,CAACS,MAAM,CAAC;IACnB,CAAC,EACDE,KAAK,IAAI;MACLV,MAAM,CAAC,IAAIW,yBAAgB,CAACD,KAAK,CAAC,CAAC;IACvC,CACJ,CAAC;EACL,CAAC,CAAC;AACN"} \ No newline at end of file diff --git a/lib/commonjs/getUserMedia.js b/lib/commonjs/getUserMedia.js new file mode 100644 index 000000000..5af2a0520 --- /dev/null +++ b/lib/commonjs/getUserMedia.js @@ -0,0 +1,101 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = getUserMedia; +var _reactNative = require("react-native"); +var _MediaStream = _interopRequireDefault(require("./MediaStream")); +var _MediaStreamError = _interopRequireDefault(require("./MediaStreamError")); +var _Permissions = _interopRequireDefault(require("./Permissions")); +var RTCUtil = _interopRequireWildcard(require("./RTCUtil")); +function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } +function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +const { + WebRTCModule +} = _reactNative.NativeModules; +function getUserMedia() { + let constraints = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + // According to + // https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia, + // the constraints argument is a dictionary of type MediaStreamConstraints. + if (typeof constraints !== 'object') { + return Promise.reject(new TypeError('constraints is not a dictionary')); + } + if ((typeof constraints.audio === 'undefined' || !constraints.audio) && (typeof constraints.video === 'undefined' || !constraints.video)) { + return Promise.reject(new TypeError('audio and/or video is required')); + } + + // Normalize constraints. + constraints = RTCUtil.normalizeConstraints(constraints); + + // Request required permissions + const reqPermissions = []; + if (constraints.audio) { + reqPermissions.push(_Permissions.default.request({ + name: 'microphone' + })); + } else { + reqPermissions.push(Promise.resolve(false)); + } + if (constraints.video) { + reqPermissions.push(_Permissions.default.request({ + name: 'camera' + })); + } else { + reqPermissions.push(Promise.resolve(false)); + } + return new Promise((resolve, reject) => { + Promise.all(reqPermissions).then(results => { + const [audioPerm, videoPerm] = results; + + // Check permission results and remove unneeded permissions. + + if (!audioPerm && !videoPerm) { + // https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia + // step 4 + const error = { + message: 'Permission denied.', + name: 'SecurityError' + }; + reject(new _MediaStreamError.default(error)); + return; + } + audioPerm || delete constraints.audio; + videoPerm || delete constraints.video; + const success = (id, tracks) => { + // Store initial constraints. + for (const trackInfo of tracks) { + const c = constraints[trackInfo.kind]; + if (typeof c === 'object') { + trackInfo.constraints = RTCUtil.deepClone(c); + } + } + const info = { + streamId: id, + streamReactTag: id, + tracks + }; + resolve(new _MediaStream.default(info)); + }; + const failure = (type, message) => { + let error; + switch (type) { + case 'TypeError': + error = new TypeError(message); + break; + } + if (!error) { + error = new _MediaStreamError.default({ + message, + name: type + }); + } + reject(error); + }; + WebRTCModule.getUserMedia(constraints, success, failure); + }); + }); +} +//# sourceMappingURL=getUserMedia.js.map \ No newline at end of file diff --git a/lib/commonjs/getUserMedia.js.map b/lib/commonjs/getUserMedia.js.map new file mode 100644 index 000000000..5a8d51fe8 --- /dev/null +++ b/lib/commonjs/getUserMedia.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_reactNative","require","_MediaStream","_interopRequireDefault","_MediaStreamError","_Permissions","RTCUtil","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","WebRTCModule","NativeModules","getUserMedia","constraints","arguments","length","undefined","Promise","reject","TypeError","audio","video","normalizeConstraints","reqPermissions","push","permissions","request","name","resolve","all","then","results","audioPerm","videoPerm","error","message","MediaStreamError","success","id","tracks","trackInfo","c","kind","deepClone","info","streamId","streamReactTag","MediaStream","failure","type"],"sources":["getUserMedia.ts"],"sourcesContent":["\nimport { NativeModules } from 'react-native';\n\n\nimport { MediaTrackConstraints } from './Constraints';\nimport MediaStream from './MediaStream';\nimport MediaStreamError from './MediaStreamError';\nimport permissions from './Permissions';\nimport * as RTCUtil from './RTCUtil';\n\nconst { WebRTCModule } = NativeModules;\n\nexport interface Constraints {\n audio?: boolean | MediaTrackConstraints;\n video?: boolean | MediaTrackConstraints;\n}\n\nexport default function getUserMedia(constraints: Constraints = {}): Promise {\n // According to\n // https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia,\n // the constraints argument is a dictionary of type MediaStreamConstraints.\n if (typeof constraints !== 'object') {\n return Promise.reject(new TypeError('constraints is not a dictionary'));\n }\n\n if (\n (typeof constraints.audio === 'undefined' || !constraints.audio) &&\n (typeof constraints.video === 'undefined' || !constraints.video)\n ) {\n return Promise.reject(new TypeError('audio and/or video is required'));\n }\n\n // Normalize constraints.\n constraints = RTCUtil.normalizeConstraints(constraints);\n\n // Request required permissions\n const reqPermissions: Promise[] = [];\n\n if (constraints.audio) {\n reqPermissions.push(permissions.request({ name: 'microphone' }));\n } else {\n reqPermissions.push(Promise.resolve(false));\n }\n\n if (constraints.video) {\n reqPermissions.push(permissions.request({ name: 'camera' }));\n } else {\n reqPermissions.push(Promise.resolve(false));\n }\n\n return new Promise((resolve, reject) => {\n Promise.all(reqPermissions).then(results => {\n const [ audioPerm, videoPerm ] = results;\n\n // Check permission results and remove unneeded permissions.\n\n if (!audioPerm && !videoPerm) {\n // https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia\n // step 4\n const error = {\n message: 'Permission denied.',\n name: 'SecurityError'\n };\n\n reject(new MediaStreamError(error));\n\n return;\n }\n\n audioPerm || delete constraints.audio;\n videoPerm || delete constraints.video;\n\n const success = (id, tracks) => {\n // Store initial constraints.\n for (const trackInfo of tracks) {\n const c = constraints[trackInfo.kind];\n\n if (typeof c === 'object') {\n trackInfo.constraints = RTCUtil.deepClone(c);\n }\n }\n\n const info = {\n streamId: id,\n streamReactTag: id,\n tracks\n };\n\n resolve(new MediaStream(info));\n };\n\n const failure = (type, message) => {\n let error;\n\n switch (type) {\n case 'TypeError':\n error = new TypeError(message);\n break;\n }\n\n if (!error) {\n error = new MediaStreamError({ message, name: type });\n }\n\n reject(error);\n };\n\n WebRTCModule.getUserMedia(constraints, success, failure);\n });\n });\n}\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAIA,IAAAC,YAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,YAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,OAAA,GAAAC,uBAAA,CAAAN,OAAA;AAAqC,SAAAO,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAF,wBAAAM,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,C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kB,yBAAgB,CAACF,KAAK,CAAC,CAAC;QAEnC;MACJ;MAEAF,SAAS,IAAI,OAAOnB,WAAW,CAACO,KAAK;MACrCa,SAAS,IAAI,OAAOpB,WAAW,CAACQ,KAAK;MAErC,MAAMgB,OAAO,GAAGA,CAACC,EAAE,EAAEC,MAAM,KAAK;QAC5B;QACA,KAAK,MAAMC,SAAS,IAAID,MAAM,EAAE;UAC5B,MAAME,CAAC,GAAG5B,WAAW,CAAC2B,SAAS,CAACE,IAAI,CAAC;UAErC,IAAI,OAAOD,CAAC,KAAK,QAAQ,EAAE;YACvBD,SAAS,CAAC3B,WAAW,GAAG3B,OAAO,CAACyD,SAAS,CAACF,CAAC,CAAC;UAChD;QACJ;QAEA,MAAMG,IAAI,GAAG;UACTC,QAAQ,EAAEP,EAAE;UACZQ,cAAc,EAAER,EAAE;UAClBC;QACJ,CAAC;QAEDX,OAAO,CAAC,IAAImB,oBAAW,CAACH,IAAI,CAAC,CAAC;MAClC,CAAC;MAED,MAAMI,OAAO,GAAGA,CAACC,IAAI,EAAEd,OAAO,KAAK;QAC/B,IAAID,KAAK;QAET,QAAQe,IAAI;UACR,KAAK,WAAW;YACZf,KAAK,GAAG,IAAIf,SAAS,CAACgB,OAAO,CAAC;YAC9B;QACR;QAEA,IAAI,CAACD,KAAK,EAAE;UACRA,KAAK,GAAG,IAAIE,yBAAgB,CAAC;YAAED,OAAO;YAAER,IAAI,EAAEsB;UAAK,CAAC,CAAC;QACzD;QAEA/B,MAAM,CAACgB,KAAK,CAAC;MACjB,CAAC;MAEDxB,YAAY,CAACE,YAAY,CAACC,WAAW,EAAEwB,OAAO,EAAEW,OAAO,CAAC;IAC5D,CAAC,CAAC;EACN,CAAC,CAAC;AACN"} \ No newline at end of file diff --git a/lib/commonjs/index.js b/lib/commonjs/index.js new file mode 100644 index 000000000..ebb4994be --- /dev/null +++ b/lib/commonjs/index.js @@ -0,0 +1,204 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "MediaStream", { + enumerable: true, + get: function () { + return _MediaStream.default; + } +}); +Object.defineProperty(exports, "MediaStreamTrack", { + enumerable: true, + get: function () { + return _MediaStreamTrack.default; + } +}); +Object.defineProperty(exports, "RTCAudioSession", { + enumerable: true, + get: function () { + return _RTCAudioSession.default; + } +}); +Object.defineProperty(exports, "RTCErrorEvent", { + enumerable: true, + get: function () { + return _RTCErrorEvent.default; + } +}); +Object.defineProperty(exports, "RTCFrameCryptor", { + enumerable: true, + get: function () { + return _RTCFrameCryptor.default; + } +}); +Object.defineProperty(exports, "RTCFrameCryptorAlgorithm", { + enumerable: true, + get: function () { + return _RTCFrameCryptorFactory.RTCFrameCryptorAlgorithm; + } +}); +Object.defineProperty(exports, "RTCFrameCryptorFactory", { + enumerable: true, + get: function () { + return _RTCFrameCryptorFactory.default; + } +}); +Object.defineProperty(exports, "RTCFrameCryptorState", { + enumerable: true, + get: function () { + return _RTCFrameCryptor.RTCFrameCryptorState; + } +}); +Object.defineProperty(exports, "RTCIceCandidate", { + enumerable: true, + get: function () { + return _RTCIceCandidate.default; + } +}); +Object.defineProperty(exports, "RTCKeyProvider", { + enumerable: true, + get: function () { + return _RTCKeyProvider.default; + } +}); +Object.defineProperty(exports, "RTCKeyProviderOptions", { + enumerable: true, + get: function () { + return _RTCFrameCryptorFactory.RTCKeyProviderOptions; + } +}); +Object.defineProperty(exports, "RTCPIPView", { + enumerable: true, + get: function () { + return _RTCPIPView.default; + } +}); +Object.defineProperty(exports, "RTCPeerConnection", { + enumerable: true, + get: function () { + return _RTCPeerConnection.default; + } +}); +Object.defineProperty(exports, "RTCRtpReceiver", { + enumerable: true, + get: function () { + return _RTCRtpReceiver.default; + } +}); +Object.defineProperty(exports, "RTCRtpSender", { + enumerable: true, + get: function () { + return _RTCRtpSender.default; + } +}); +Object.defineProperty(exports, "RTCRtpTransceiver", { + enumerable: true, + get: function () { + return _RTCRtpTransceiver.default; + } +}); +Object.defineProperty(exports, "RTCSessionDescription", { + enumerable: true, + get: function () { + return _RTCSessionDescription.default; + } +}); +Object.defineProperty(exports, "RTCView", { + enumerable: true, + get: function () { + return _RTCView.default; + } +}); +Object.defineProperty(exports, "ScreenCapturePickerView", { + enumerable: true, + get: function () { + return _ScreenCapturePickerView.default; + } +}); +Object.defineProperty(exports, "mediaDevices", { + enumerable: true, + get: function () { + return _MediaDevices.default; + } +}); +Object.defineProperty(exports, "permissions", { + enumerable: true, + get: function () { + return _Permissions.default; + } +}); +exports.registerGlobals = registerGlobals; +Object.defineProperty(exports, "startIOSPIP", { + enumerable: true, + get: function () { + return _RTCPIPView.startIOSPIP; + } +}); +Object.defineProperty(exports, "stopIOSPIP", { + enumerable: true, + get: function () { + return _RTCPIPView.stopIOSPIP; + } +}); +var _reactNative = require("react-native"); +var _EventEmitter = require("./EventEmitter"); +var _Logger = _interopRequireDefault(require("./Logger")); +var _MediaDevices = _interopRequireDefault(require("./MediaDevices")); +var _MediaStream = _interopRequireDefault(require("./MediaStream")); +var _MediaStreamTrack = _interopRequireDefault(require("./MediaStreamTrack")); +var _MediaStreamTrackEvent = _interopRequireDefault(require("./MediaStreamTrackEvent")); +var _Permissions = _interopRequireDefault(require("./Permissions")); +var _RTCAudioSession = _interopRequireDefault(require("./RTCAudioSession")); +var _RTCErrorEvent = _interopRequireDefault(require("./RTCErrorEvent")); +var _RTCFrameCryptor = _interopRequireWildcard(require("./RTCFrameCryptor")); +var _RTCFrameCryptorFactory = _interopRequireWildcard(require("./RTCFrameCryptorFactory")); +var _RTCIceCandidate = _interopRequireDefault(require("./RTCIceCandidate")); +var _RTCKeyProvider = _interopRequireDefault(require("./RTCKeyProvider")); +var _RTCPIPView = _interopRequireWildcard(require("./RTCPIPView")); +var _RTCPeerConnection = _interopRequireDefault(require("./RTCPeerConnection")); +var _RTCRtpReceiver = _interopRequireDefault(require("./RTCRtpReceiver")); +var _RTCRtpSender = _interopRequireDefault(require("./RTCRtpSender")); +var _RTCRtpTransceiver = _interopRequireDefault(require("./RTCRtpTransceiver")); +var _RTCSessionDescription = _interopRequireDefault(require("./RTCSessionDescription")); +var _RTCView = _interopRequireDefault(require("./RTCView")); +var _ScreenCapturePickerView = _interopRequireDefault(require("./ScreenCapturePickerView")); +function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } +function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +const { + WebRTCModule +} = _reactNative.NativeModules; +if (WebRTCModule === null) { + throw new Error(`WebRTC native module not found.\n${_reactNative.Platform.OS === 'ios' ? 'Try executing the "pod install" command inside your projects ios folder.' : 'Try executing the "npm install" command inside your projects folder.'}`); +} +_Logger.default.enable(`${_Logger.default.ROOT_PREFIX}:*`); + +// Add listeners for the native events early, since they are added asynchronously. +(0, _EventEmitter.setupNativeEvents)(); +function registerGlobals() { + // Should not happen. React Native has a global navigator object. + if (typeof global.navigator !== 'object') { + throw new Error('navigator is not an object'); + } + if (!global.navigator.mediaDevices) { + global.navigator.mediaDevices = {}; + } + global.navigator.mediaDevices.getUserMedia = _MediaDevices.default.getUserMedia.bind(_MediaDevices.default); + global.navigator.mediaDevices.getDisplayMedia = _MediaDevices.default.getDisplayMedia.bind(_MediaDevices.default); + global.navigator.mediaDevices.enumerateDevices = _MediaDevices.default.enumerateDevices.bind(_MediaDevices.default); + global.RTCIceCandidate = _RTCIceCandidate.default; + global.RTCPeerConnection = _RTCPeerConnection.default; + global.RTCRtpReceiver = _RTCRtpReceiver.default; + global.RTCRtpSender = _RTCRtpReceiver.default; + global.RTCSessionDescription = _RTCSessionDescription.default; + global.MediaStream = _MediaStream.default; + global.MediaStreamTrack = _MediaStreamTrack.default; + global.MediaStreamTrackEvent = _MediaStreamTrackEvent.default; + global.RTCRtpTransceiver = _RTCRtpTransceiver.default; + global.RTCRtpReceiver = _RTCRtpReceiver.default; + global.RTCRtpSender = _RTCRtpSender.default; + global.RTCErrorEvent = _RTCErrorEvent.default; +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/commonjs/index.js.map b/lib/commonjs/index.js.map new file mode 100644 index 000000000..f94ce5348 --- /dev/null +++ b/lib/commonjs/index.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_reactNative","require","_EventEmitter","_Logger","_interopRequireDefault","_MediaDevices","_MediaStream","_MediaStreamTrack","_MediaStreamTrackEvent","_Permissions","_RTCAudioSession","_RTCErrorEvent","_RTCFrameCryptor","_interopRequireWildcard","_RTCFrameCryptorFactory","_RTCIceCandidate","_RTCKeyProvider","_RTCPIPView","_RTCPeerConnection","_RTCRtpReceiver","_RTCRtpSender","_RTCRtpTransceiver","_RTCSessionDescription","_RTCView","_ScreenCapturePickerView","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","WebRTCModule","NativeModules","Error","Platform","OS","Logger","enable","ROOT_PREFIX","setupNativeEvents","registerGlobals","global","navigator","mediaDevices","getUserMedia","bind","getDisplayMedia","enumerateDevices","RTCIceCandidate","RTCPeerConnection","RTCRtpReceiver","RTCRtpSender","RTCSessionDescription","MediaStream","MediaStreamTrack","MediaStreamTrackEvent","RTCRtpTransceiver","RTCErrorEvent"],"sources":["index.ts"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\nconst { WebRTCModule } = NativeModules;\n\nif (WebRTCModule === null) {\n throw new Error(`WebRTC native module not found.\\n${Platform.OS === 'ios' ?\n 'Try executing the \"pod install\" command inside your projects ios folder.' :\n 'Try executing the \"npm install\" command inside your projects folder.'\n }`);\n}\n\nimport { setupNativeEvents } from './EventEmitter';\nimport Logger from './Logger';\nimport mediaDevices from './MediaDevices';\nimport MediaStream from './MediaStream';\nimport MediaStreamTrack, { type MediaTrackSettings } from './MediaStreamTrack';\nimport MediaStreamTrackEvent from './MediaStreamTrackEvent';\nimport permissions from './Permissions';\nimport RTCAudioSession from './RTCAudioSession';\nimport RTCErrorEvent from './RTCErrorEvent';\nimport RTCFrameCryptor, { RTCFrameCryptorState } from './RTCFrameCryptor';\nimport RTCFrameCryptorFactory, { RTCFrameCryptorAlgorithm, RTCKeyProviderOptions } from './RTCFrameCryptorFactory';\nimport RTCIceCandidate from './RTCIceCandidate';\nimport RTCKeyProvider from './RTCKeyProvider';\nimport RTCPIPView, { startIOSPIP, stopIOSPIP } from './RTCPIPView';\nimport RTCPeerConnection from './RTCPeerConnection';\nimport RTCRtpReceiver from './RTCRtpReceiver';\nimport RTCRtpSender from './RTCRtpSender';\nimport RTCRtpTransceiver from './RTCRtpTransceiver';\nimport RTCSessionDescription from './RTCSessionDescription';\nimport RTCView, { type RTCVideoViewProps, type RTCIOSPIPOptions } from './RTCView';\nimport ScreenCapturePickerView from './ScreenCapturePickerView';\n\nLogger.enable(`${Logger.ROOT_PREFIX}:*`);\n\n// Add listeners for the native events early, since they are added asynchronously.\nsetupNativeEvents();\n\nexport {\n RTCIceCandidate,\n RTCPeerConnection,\n RTCSessionDescription,\n RTCView,\n RTCPIPView,\n ScreenCapturePickerView,\n RTCRtpTransceiver,\n RTCRtpReceiver,\n RTCRtpSender,\n RTCErrorEvent,\n RTCAudioSession,\n RTCFrameCryptor,\n RTCFrameCryptorAlgorithm,\n RTCFrameCryptorState,\n RTCFrameCryptorFactory,\n RTCKeyProvider,\n RTCKeyProviderOptions,\n MediaStream,\n MediaStreamTrack,\n type MediaTrackSettings,\n type RTCVideoViewProps,\n type RTCIOSPIPOptions,\n mediaDevices,\n permissions,\n registerGlobals,\n startIOSPIP,\n stopIOSPIP,\n};\n\ndeclare const global: any;\n\nfunction registerGlobals(): void {\n // Should not happen. React Native has a global navigator object.\n if (typeof global.navigator !== 'object') {\n throw new Error('navigator is not an object');\n }\n\n if (!global.navigator.mediaDevices) {\n global.navigator.mediaDevices = {};\n }\n\n global.navigator.mediaDevices.getUserMedia = mediaDevices.getUserMedia.bind(mediaDevices);\n global.navigator.mediaDevices.getDisplayMedia = mediaDevices.getDisplayMedia.bind(mediaDevices);\n global.navigator.mediaDevices.enumerateDevices = mediaDevices.enumerateDevices.bind(mediaDevices);\n\n global.RTCIceCandidate = RTCIceCandidate;\n global.RTCPeerConnection = RTCPeerConnection;\n global.RTCRtpReceiver = RTCRtpReceiver;\n global.RTCRtpSender = RTCRtpReceiver;\n global.RTCSessionDescription = RTCSessionDescription;\n global.MediaStream = MediaStream;\n global.MediaStreamTrack = MediaStreamTrack;\n global.MediaStreamTrackEvent = MediaStreamTrackEvent;\n global.RTCRtpTransceiver = RTCRtpTransceiver;\n global.RTCRtpReceiver = RTCRtpReceiver;\n global.RTCRtpSender = RTCRtpSender;\n global.RTCErrorEvent = RTCErrorEvent;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAUA,IAAAC,aA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BAAiB,EAAC,CAAC;AAkCnB,SAASC,eAAeA,CAAA,EAAS;EAC7B;EACA,IAAI,OAAOC,MAAM,CAACC,SAAS,KAAK,QAAQ,EAAE;IACtC,MAAM,IAAIT,KAAK,CAAC,4BAA4B,CAAC;EACjD;EAEA,IAAI,CAACQ,MAAM,CAACC,SAAS,CAACC,YAAY,EAAE;IAChCF,MAAM,CAACC,SAAS,CAACC,YAAY,GAAG,CAAC,CAAC;EACtC;EAEAF,MAAM,CAACC,SAAS,CAACC,YAAY,CAACC,YAAY,GAAGD,qBAAY,CAACC,YAAY,CAACC,IAAI,CAACF,qBAAY,CAAC;EACzFF,MAAM,CAACC,SAAS,CAACC,YAAY,CAACG,eAAe,GAAGH,qBAAY,CAACG,eAAe,CAACD,IAAI,CAACF,qBAAY,CAAC;EAC/FF,MAAM,CAACC,SAAS,CAACC,YAAY,CAACI,gBAAgB,GAAGJ,qBAAY,CAACI,gBAAgB,CAACF,IAAI,CAACF,qBAAY,CAAC;EAEjGF,MAAM,CAACO,eAAe,GAAGA,wBAAe;EACxCP,MAAM,CAACQ,iBAAiB,GAAGA,0BAAiB;EAC5CR,MAAM,CAACS,cAAc,GAAGA,uBAAc;EACtCT,MAAM,CAACU,YAAY,GAAGD,uBAAc;EACpCT,MAAM,CAACW,qBAAqB,GAAGA,8BAAqB;EACpDX,MAAM,CAACY,WAAW,GAAGA,oBAAW;EAChCZ,MAAM,CAACa,gBAAgB,GAAGA,yBAAgB;EAC1Cb,MAAM,CAACc,qBAAqB,GAAGA,8BAAqB;EACpDd,MAAM,CAACe,iBAAiB,GAAGA,0BAAiB;EAC5Cf,MAAM,CAACS,cAAc,GAAGA,uBAAc;EACtCT,MAAM,CAACU,YAAY,GAAGA,qBAAY;EAClCV,MAAM,CAACgB,aAAa,GAAGA,sBAAa;AACxC"} \ No newline at end of file diff --git a/lib/module/Constraints.js b/lib/module/Constraints.js new file mode 100644 index 000000000..e032fb601 --- /dev/null +++ b/lib/module/Constraints.js @@ -0,0 +1,2 @@ + +//# sourceMappingURL=Constraints.js.map \ No newline at end of file diff --git a/lib/module/Constraints.js.map b/lib/module/Constraints.js.map new file mode 100644 index 000000000..6bcd02e43 --- /dev/null +++ b/lib/module/Constraints.js.map @@ -0,0 +1 @@ +{"version":3,"names":[],"sources":["Constraints.ts"],"sourcesContent":["\nexport type MediaTrackConstraints = {\n width?: ConstrainNumber;\n height?: ConstrainNumber;\n frameRate?: ConstrainNumber;\n facingMode?: ConstrainString;\n deviceId?: ConstrainString;\n groupId?: ConstrainString;\n}\n\ntype ConstrainNumber = number | {\n exact?: number,\n ideal?: number,\n max?: number,\n min?: number,\n}\n\ntype ConstrainString = string | {\n exact?: string,\n ideal?: string,\n}"],"mappings":""} \ No newline at end of file diff --git a/lib/module/EventEmitter.js b/lib/module/EventEmitter.js new file mode 100644 index 000000000..ddd862e11 --- /dev/null +++ b/lib/module/EventEmitter.js @@ -0,0 +1,41 @@ +import { NativeModules, NativeEventEmitter } from 'react-native'; +// @ts-ignore +import EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter'; +const { + WebRTCModule +} = NativeModules; + +// This emitter is going to be used to listen to all the native events (once) and then +// re-emit them on a JS-only emitter. +const nativeEmitter = new NativeEventEmitter(WebRTCModule); +const NATIVE_EVENTS = ['peerConnectionSignalingStateChanged', 'peerConnectionStateChanged', 'peerConnectionOnRenegotiationNeeded', 'peerConnectionIceConnectionChanged', 'peerConnectionIceGatheringChanged', 'peerConnectionGotICECandidate', 'peerConnectionDidOpenDataChannel', 'peerConnectionOnRemoveTrack', 'peerConnectionOnTrack', 'dataChannelStateChanged', 'dataChannelReceiveMessage', 'dataChannelDidChangeBufferedAmount', 'mediaStreamTrackMuteChanged', 'mediaStreamTrackEnded', 'frameCryptionStateChanged']; +const eventEmitter = new EventEmitter(); +export function setupNativeEvents() { + for (const eventName of NATIVE_EVENTS) { + nativeEmitter.addListener(eventName, function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + eventEmitter.emit(eventName, ...args); + }); + } +} +const _subscriptions = new Map(); +export function addListener(listener, eventName, eventHandler) { + var _subscriptions$get; + if (!NATIVE_EVENTS.includes(eventName)) { + throw new Error(`Invalid event: ${eventName}`); + } + if (!_subscriptions.has(listener)) { + _subscriptions.set(listener, []); + } + (_subscriptions$get = _subscriptions.get(listener)) === null || _subscriptions$get === void 0 ? void 0 : _subscriptions$get.push(eventEmitter.addListener(eventName, eventHandler)); +} +export function removeListener(listener) { + var _subscriptions$get2; + (_subscriptions$get2 = _subscriptions.get(listener)) === null || _subscriptions$get2 === void 0 ? void 0 : _subscriptions$get2.forEach(sub => { + sub.remove(); + }); + _subscriptions.delete(listener); +} +//# sourceMappingURL=EventEmitter.js.map \ No newline at end of file diff --git a/lib/module/EventEmitter.js.map b/lib/module/EventEmitter.js.map new file mode 100644 index 000000000..19b2ce9bb --- /dev/null +++ b/lib/module/EventEmitter.js.map @@ -0,0 +1 @@ +{"version":3,"names":["NativeModules","NativeEventEmitter","EventEmitter","WebRTCModule","nativeEmitter","NATIVE_EVENTS","eventEmitter","setupNativeEvents","eventName","addListener","_len","arguments","length","args","Array","_key","emit","_subscriptions","Map","listener","eventHandler","_subscriptions$get","includes","Error","has","set","get","push","removeListener","_subscriptions$get2","forEach","sub","remove","delete"],"sources":["EventEmitter.ts"],"sourcesContent":["import { NativeModules, NativeEventEmitter, EmitterSubscription } from 'react-native';\n// @ts-ignore\nimport EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter';\n\nconst { WebRTCModule } = NativeModules;\n\n// This emitter is going to be used to listen to all the native events (once) and then\n// re-emit them on a JS-only emitter.\nconst nativeEmitter = new NativeEventEmitter(WebRTCModule);\n\nconst NATIVE_EVENTS = [\n 'peerConnectionSignalingStateChanged',\n 'peerConnectionStateChanged',\n 'peerConnectionOnRenegotiationNeeded',\n 'peerConnectionIceConnectionChanged',\n 'peerConnectionIceGatheringChanged',\n 'peerConnectionGotICECandidate',\n 'peerConnectionDidOpenDataChannel',\n 'peerConnectionOnRemoveTrack',\n 'peerConnectionOnTrack',\n 'dataChannelStateChanged',\n 'dataChannelReceiveMessage',\n 'dataChannelDidChangeBufferedAmount',\n 'mediaStreamTrackMuteChanged',\n 'mediaStreamTrackEnded',\n 'frameCryptionStateChanged',\n];\n\nconst eventEmitter = new EventEmitter();\n\nexport function setupNativeEvents() {\n for (const eventName of NATIVE_EVENTS) {\n nativeEmitter.addListener(eventName, (...args) => {\n eventEmitter.emit(eventName, ...args);\n });\n }\n}\n\ntype EventHandler = (event: unknown) => void;\ntype Listener = unknown;\n\nconst _subscriptions: Map = new Map();\n\nexport function addListener(listener: Listener, eventName: string, eventHandler: EventHandler): void {\n if (!NATIVE_EVENTS.includes(eventName)) {\n throw new Error(`Invalid event: ${eventName}`);\n }\n\n if (!_subscriptions.has(listener)) {\n _subscriptions.set(listener, []);\n }\n\n _subscriptions.get(listener)?.push(eventEmitter.addListener(eventName, eventHandler));\n}\n\nexport function removeListener(listener: Listener): void {\n _subscriptions.get(listener)?.forEach(sub => {\n sub.remove();\n });\n\n _subscriptions.delete(listener);\n}\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,kBAAkB,QAA6B,cAAc;AACrF;AACA,OAAOC,YAAY,MAAM,oDAAoD;AAE7E,MAAM;EAAEC;AAAa,CAAC,GAAGH,aAAa;;AAEtC;AACA;AACA,MAAMI,aAAa,GAAG,IAAIH,kBAAkB,CAACE,YAAY,CAAC;AAE1D,MAAME,aAAa,GAAG,CAClB,qCAAqC,EACrC,4BAA4B,EAC5B,qCAAqC,EACrC,oCAAoC,EACpC,mCAAmC,EACnC,+BAA+B,EAC/B,kCAAkC,EAClC,6BAA6B,EAC7B,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,oCAAoC,EACpC,6BAA6B,EAC7B,uBAAuB,EACvB,2BAA2B,CAC9B;AAED,MAAMC,YAAY,GAAG,IAAIJ,YAAY,CAAC,CAAC;AAEvC,OAAO,S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B,CAAC,CAAC;EAEFf,cAAc,CAACgB,MAAM,CAACd,QAAQ,CAAC;AACnC"} \ No newline at end of file diff --git a/lib/module/Logger.js b/lib/module/Logger.js new file mode 100644 index 000000000..30271c2ae --- /dev/null +++ b/lib/module/Logger.js @@ -0,0 +1,39 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import debug from 'debug'; +export default class Logger { + static enable(ns) { + debug.enable(ns); + } + constructor(prefix) { + _defineProperty(this, "_debug", void 0); + _defineProperty(this, "_info", void 0); + _defineProperty(this, "_warn", void 0); + _defineProperty(this, "_error", void 0); + const _prefix = `${Logger.ROOT_PREFIX}:${prefix}`; + this._debug = debug(`${_prefix}:DEBUG`); + this._info = debug(`${_prefix}:INFO`); + this._warn = debug(`${_prefix}:WARN`); + this._error = debug(`${_prefix}:ERROR`); + const log = console.log.bind(console); + this._debug.log = log; + this._info.log = log; + this._warn.log = log; + this._error.log = log; + } + debug(msg) { + this._debug(msg); + } + info(msg) { + this._info(msg); + } + warn(msg) { + this._warn(msg); + } + error(msg, err) { + var _err$stack; + const trace = (_err$stack = err === null || err === void 0 ? void 0 : err.stack) !== null && _err$stack !== void 0 ? _err$stack : 'N/A'; + this._error(`${msg} Trace: ${trace}`); + } +} +_defineProperty(Logger, "ROOT_PREFIX", 'rn-webrtc'); +//# sourceMappingURL=Logger.js.map \ No newline at end of file diff --git a/lib/module/Logger.js.map b/lib/module/Logger.js.map new file mode 100644 index 000000000..19cf4c3f7 --- /dev/null +++ b/lib/module/Logger.js.map @@ -0,0 +1 @@ +{"version":3,"names":["debug","Logger","enable","ns","constructor","prefix","_defineProperty","_prefix","ROOT_PREFIX","_debug","_info","_warn","_error","log","console","bind","msg","info","warn","error","err","_err$stack","trace","stack"],"sources":["Logger.ts"],"sourcesContent":["import debug from 'debug';\n\n\nexport default class Logger {\n static ROOT_PREFIX = 'rn-webrtc';\n\n private _debug: debug.Debugger;\n private _info: debug.Debugger;\n private _warn: debug.Debugger;\n private _error: debug.Debugger;\n\n static enable(ns: string): void {\n debug.enable(ns);\n }\n\n constructor(prefix: string) {\n const _prefix = `${Logger.ROOT_PREFIX}:${prefix}`;\n\n this._debug = debug(`${_prefix}:DEBUG`);\n this._info = debug(`${_prefix}:INFO`);\n this._warn = debug(`${_prefix}:WARN`);\n this._error = debug(`${_prefix}:ERROR`);\n\n const log = console.log.bind(console);\n\n this._debug.log = log;\n this._info.log = log;\n this._warn.log = log;\n this._error.log = log;\n }\n\n debug(msg: string): void {\n this._debug(msg);\n }\n\n info(msg: string): void {\n this._info(msg);\n }\n\n warn(msg: string): void {\n this._warn(msg);\n }\n\n error(msg: string, err?: Error): void {\n const trace = err?.stack ?? 'N/A';\n\n this._error(`${msg} Trace: ${trace}`);\n }\n}\n"],"mappings":";AAAA,OAAOA,KAAK,MAAM,OAAO;AAGzB,eAAe,MAAMC,MAAM,CAAC;EAQxB,OAAOC,MAAMA,CAACC,EAAU,EAAQ;IAC5BH,KAAK,CAACE,MAAM,CAACC,EAAE,CAAC;EACpB;EAEAC,WAAWA,CAACC,MAAc,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACxB,MAAMC,OAAO,GAAI,GAAEN,MAAM,CAACO,WAAY,IAAGH,MAAO,EAAC;IAEjD,IAAI,CAACI,MAAM,GAAGT,KAAK,CAAE,GAAEO,OAAQ,QAAO,CAAC;IACvC,IAAI,CAACG,KAAK,GAAGV,KAAK,CAAE,GAAEO,OAAQ,OAAM,CAAC;IACrC,IAAI,CAACI,KAAK,GAAGX,KAAK,CAAE,GAAEO,OAAQ,OAAM,CAAC;IACrC,IAAI,CAACK,MAAM,GAAGZ,KAAK,CAAE,GAAEO,OAAQ,QAAO,CAAC;IAEvC,MAAMM,GAAG,GAAGC,OAAO,CAACD,GAAG,CAACE,IAAI,CAACD,OAAO,CAAC;IAErC,IAAI,CAACL,MAAM,CAACI,GAAG,GAAGA,GAAG;IACrB,IAAI,CAACH,KAAK,CAACG,GAAG,GAAGA,GAAG;IACpB,IAAI,CAACF,KAAK,CAACE,GAAG,GAAGA,GAAG;IACpB,IAAI,CAACD,MAAM,CAACC,GAAG,GAAGA,GAAG;EACzB;EAEAb,KAAKA,CAACgB,GAAW,EAAQ;IACrB,IAAI,CAACP,MAAM,CAACO,GAAG,CAAC;EACpB;EAEAC,IAAIA,CAACD,GAAW,EAAQ;IACpB,IAAI,CAACN,KAAK,CAACM,GAAG,CAAC;EACnB;EAEAE,IAAIA,CAACF,GAAW,EAAQ;IACpB,IAAI,CAACL,KAAK,CAACK,GAAG,CAAC;EACnB;EAEAG,KAAKA,CAACH,GAAW,EAAEI,GAAW,EAAQ;IAAA,IAAAC,UAAA;IAClC,MAAMC,KAAK,IAAAD,UAAA,GAAGD,GAAG,aAAHA,GAAG,uBAAHA,GAAG,CAAEG,KAAK,cAAAF,UAAA,cAAAA,UAAA,GAAI,KAAK;IAEjC,IAAI,CAACT,MAAM,CAAE,GAAEI,GAAI,WAAUM,KAAM,EAAC,CAAC;EACzC;AACJ;AAAChB,eAAA,CA7CoBL,MAAM,iBACF,WAAW"} \ No newline at end of file diff --git a/lib/module/MediaDevices.js b/lib/module/MediaDevices.js new file mode 100644 index 000000000..0f2202b46 --- /dev/null +++ b/lib/module/MediaDevices.js @@ -0,0 +1,46 @@ +import { EventTarget, defineEventAttribute } from 'event-target-shim/index'; +import { NativeModules } from 'react-native'; +import getDisplayMedia from './getDisplayMedia'; +import getUserMedia from './getUserMedia'; +const { + WebRTCModule +} = NativeModules; +class MediaDevices extends EventTarget { + /** + * W3C "Media Capture and Streams" compatible {@code enumerateDevices} + * implementation. + */ + enumerateDevices() { + return new Promise(resolve => WebRTCModule.enumerateDevices(resolve)); + } + + /** + * W3C "Screen Capture" compatible {@code getDisplayMedia} implementation. + * See: https://w3c.github.io/mediacapture-screen-share/ + * + * @returns {Promise} + */ + getDisplayMedia() { + return getDisplayMedia(); + } + + /** + * W3C "Media Capture and Streams" compatible {@code getUserMedia} + * implementation. + * See: https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-enumeratedevices + * + * @param {*} constraints + * @returns {Promise} + */ + getUserMedia(constraints) { + return getUserMedia(constraints); + } +} + +/** + * Define the `onxxx` event handlers. + */ +const proto = MediaDevices.prototype; +defineEventAttribute(proto, 'devicechange'); +export default new MediaDevices(); +//# sourceMappingURL=MediaDevices.js.map \ No newline at end of file diff --git a/lib/module/MediaDevices.js.map b/lib/module/MediaDevices.js.map new file mode 100644 index 000000000..0cb4af15a --- /dev/null +++ b/lib/module/MediaDevices.js.map @@ -0,0 +1 @@ +{"version":3,"names":["EventTarget","defineEventAttribute","NativeModules","getDisplayMedia","getUserMedia","WebRTCModule","MediaDevices","enumerateDevices","Promise","resolve","constraints","proto","prototype"],"sources":["MediaDevices.ts"],"sourcesContent":["import { EventTarget, Event, defineEventAttribute } from 'event-target-shim/index';\nimport { NativeModules } from 'react-native';\n\nimport getDisplayMedia from './getDisplayMedia';\nimport getUserMedia, { Constraints } from './getUserMedia';\n\nconst { WebRTCModule } = NativeModules;\n\ntype MediaDevicesEventMap = {\n devicechange: Event<'devicechange'>\n}\n\nclass MediaDevices extends EventTarget {\n /**\n * W3C \"Media Capture and Streams\" compatible {@code enumerateDevices}\n * implementation.\n */\n enumerateDevices() {\n return new Promise(resolve => WebRTCModule.enumerateDevices(resolve));\n }\n\n /**\n * W3C \"Screen Capture\" compatible {@code getDisplayMedia} implementation.\n * See: https://w3c.github.io/mediacapture-screen-share/\n *\n * @returns {Promise}\n */\n getDisplayMedia() {\n return getDisplayMedia();\n }\n\n /**\n * W3C \"Media Capture and Streams\" compatible {@code getUserMedia}\n * implementation.\n * See: https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-enumeratedevices\n *\n * @param {*} constraints\n * @returns {Promise}\n */\n getUserMedia(constraints: Constraints) {\n return getUserMedia(constraints);\n }\n}\n\n/**\n * Define the `onxxx` event handlers.\n */\nconst proto = MediaDevices.prototype;\n\ndefineEventAttribute(proto, 'devicechange');\n\n\nexport default new MediaDevices();\n"],"mappings":"AAAA,SAASA,WAAW,EAASC,oBAAoB,QAAQ,yBAAyB;AAClF,SAASC,aAAa,QAAQ,cAAc;AAE5C,OAAOC,eAAe,MAAM,mBAAmB;AAC/C,OAAOC,YAAY,MAAuB,gBAAgB;AAE1D,MAAM;EAAEC;AAAa,CAAC,GAAGH,aAAa;AAMtC,MAAMI,YAAY,SAASN,WAAW,CAAuB;EACzD;AACJ;AACA;AACA;EACIO,gBAAgBA,CAAA,EAAG;IACf,OAAO,IAAIC,OAAO,CAACC,OAAO,IAAIJ,YAAY,CAACE,gBAAgB,CAACE,OAAO,CAAC,CAAC;EACzE;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACIN,eAAeA,CAAA,EAAG;IACd,OAAOA,eAAe,CAAC,CAAC;EAC5B;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;EACIC,YAAYA,CAACM,WAAwB,EAAE;IACnC,OAAON,YAAY,CAACM,WAAW,CAAC;EACpC;AACJ;;AAEA;AACA;AACA;AACA,MAAMC,KAAK,GAAGL,YAAY,CAACM,SAAS;AAEpCX,oBAAoB,CAACU,KAAK,EAAE,cAAc,CAAC;AAG3C,eAAe,IAAIL,YAAY,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/module/MediaStream.js b/lib/module/MediaStream.js new file mode 100644 index 000000000..ef850dd84 --- /dev/null +++ b/lib/module/MediaStream.js @@ -0,0 +1,129 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import { EventTarget, defineEventAttribute } from 'event-target-shim/index'; +import { NativeModules } from 'react-native'; +import MediaStreamTrack from './MediaStreamTrack'; +import { uniqueID } from './RTCUtil'; +const { + WebRTCModule +} = NativeModules; +export default class MediaStream extends EventTarget { + /** + * The identifier of this MediaStream unique within the associated + * WebRTCModule instance. As the id of a remote MediaStream instance is unique + * only within the associated RTCPeerConnection, it is not sufficiently unique + * to identify this MediaStream across multiple RTCPeerConnections and to + * unambiguously differentiate it from a local MediaStream instance not added + * to an RTCPeerConnection. + */ + + /** + * A MediaStream can be constructed in several ways, depending on the parameters + * that are passed here. + * + * - undefined: just a new stream, with no tracks. + * - MediaStream instance: a new stream, with a copy of the tracks of the passed stream. + * - Array of MediaStreamTrack: a new stream with a copy of the tracks in the array. + * - object: a new stream instance, represented by the passed info object, this is always + * done internally, when the stream is first created in native and the JS wrapper is + * built afterwards. + */ + constructor(arg) { + super(); + + // Assign a UUID to start with. It will get overridden for remote streams. + _defineProperty(this, "_tracks", []); + _defineProperty(this, "_id", void 0); + _defineProperty(this, "_reactTag", void 0); + this._id = uniqueID(); + + // Local MediaStreams are created by WebRTCModule to have their id and + // reactTag equal because WebRTCModule follows the respective standard's + // recommendation for id generation i.e. uses UUID which is unique enough + // for the purposes of reactTag. + this._reactTag = this._id; + if (typeof arg === 'undefined') { + WebRTCModule.mediaStreamCreate(this.id); + } else if (arg instanceof MediaStream) { + WebRTCModule.mediaStreamCreate(this.id); + for (const track of arg.getTracks()) { + this.addTrack(track); + } + } else if (Array.isArray(arg)) { + WebRTCModule.mediaStreamCreate(this.id); + for (const track of arg) { + this.addTrack(track); + } + } else if (typeof arg === 'object' && arg.streamId && arg.streamReactTag && arg.tracks) { + this._id = arg.streamId; + this._reactTag = arg.streamReactTag; + for (const trackInfo of arg.tracks) { + // We are not using addTrack here because the track is already part of the + // stream, so there is no need to add it on the native side. + this._tracks.push(new MediaStreamTrack(trackInfo)); + } + } else { + throw new TypeError(`invalid type: ${typeof arg}`); + } + } + get id() { + return this._id; + } + get active() { + // TODO: can we reliably report this value? + + return true; + } + addTrack(track) { + const index = this._tracks.indexOf(track); + if (index !== -1) { + return; + } + this._tracks.push(track); + WebRTCModule.mediaStreamAddTrack(this._reactTag, track.remote ? track._peerConnectionId : -1, track.id); + } + removeTrack(track) { + const index = this._tracks.indexOf(track); + if (index === -1) { + return; + } + this._tracks.splice(index, 1); + WebRTCModule.mediaStreamRemoveTrack(this._reactTag, track.remote ? track._peerConnectionId : -1, track.id); + } + getTracks() { + return this._tracks.slice(); + } + getTrackById(trackId) { + return this._tracks.find(track => track.id === trackId); + } + getAudioTracks() { + return this._tracks.filter(track => track.kind === 'audio'); + } + getVideoTracks() { + return this._tracks.filter(track => track.kind === 'video'); + } + clone() { + throw new Error('Not implemented.'); + } + toURL() { + return this._reactTag; + } + release() { + let releaseTracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + const tracks = [...this._tracks]; + for (const track of tracks) { + this.removeTrack(track); + if (releaseTracks) { + track.release(); + } + } + WebRTCModule.mediaStreamRelease(this._reactTag); + } +} + +/** + * Define the `onxxx` event handlers. + */ +const proto = MediaStream.prototype; +defineEventAttribute(proto, 'addtrack'); +defineEventAttribute(proto, 'removetrack'); +//# sourceMappingURL=MediaStream.js.map \ No newline at end of file diff --git a/lib/module/MediaStream.js.map b/lib/module/MediaStream.js.map new file mode 100644 index 000000000..c9296caf1 --- /dev/null +++ b/lib/module/MediaStream.js.map @@ -0,0 +1 @@ +{"version":3,"names":["EventTarget","defineEventAttribute","NativeModules","MediaStreamTrack","uniqueID","WebRTCModule","MediaStream","constructor","arg","_defineProperty","_id","_reactTag","mediaStreamCreate","id","track","getTracks","addTrack","Array","isArray","streamId","streamReactTag","tracks","trackInfo","_tracks","push","TypeError","active","index","indexOf","mediaStreamAddTrack","remote","_peerConnectionId","removeTrack","splice","mediaStreamRemoveTrack","slice","getTrackById","trackId","find","getAudioTracks","filter","kind","getVideoTracks","clone","Error","toURL","release","releaseTracks","arguments","length","undefined","mediaStreamRelease","proto","prototype"],"sources":["MediaStream.ts"],"sourcesContent":["import { EventTarget, defineEventAttribute } from 'event-target-shim/index';\nimport { NativeModules } from 'react-native';\n\nimport MediaStreamTrack, { MediaStreamTrackInfo } from './MediaStreamTrack';\nimport MediaStreamTrackEvent from './MediaStreamTrackEvent';\nimport { uniqueID } from './RTCUtil';\n\nconst { WebRTCModule } = NativeModules;\n\ntype MediaStreamEventMap = {\n addtrack: MediaStreamTrackEvent<'addtrack'>\n removetrack: MediaStreamTrackEvent<'removetrack'>\n}\n\nexport default class MediaStream extends EventTarget {\n _tracks: MediaStreamTrack[] = [];\n _id: string;\n\n /**\n * The identifier of this MediaStream unique within the associated\n * WebRTCModule instance. As the id of a remote MediaStream instance is unique\n * only within the associated RTCPeerConnection, it is not sufficiently unique\n * to identify this MediaStream across multiple RTCPeerConnections and to\n * unambiguously differentiate it from a local MediaStream instance not added\n * to an RTCPeerConnection.\n */\n _reactTag: string;\n\n /**\n * A MediaStream can be constructed in several ways, depending on the parameters\n * that are passed here.\n *\n * - undefined: just a new stream, with no tracks.\n * - MediaStream instance: a new stream, with a copy of the tracks of the passed stream.\n * - Array of MediaStreamTrack: a new stream with a copy of the tracks in the array.\n * - object: a new stream instance, represented by the passed info object, this is always\n * done internally, when the stream is first created in native and the JS wrapper is\n * built afterwards.\n */\n constructor(arg?:\n MediaStream |\n MediaStreamTrack[] |\n { streamId: string, streamReactTag: string, tracks: MediaStreamTrackInfo[] }\n ) {\n super();\n\n // Assign a UUID to start with. It will get overridden for remote streams.\n this._id = uniqueID();\n\n // Local MediaStreams are created by WebRTCModule to have their id and\n // reactTag equal because WebRTCModule follows the respective standard's\n // recommendation for id generation i.e. uses UUID which is unique enough\n // for the purposes of reactTag.\n this._reactTag = this._id;\n\n if (typeof arg === 'undefined') {\n WebRTCModule.mediaStreamCreate(this.id);\n } else if (arg instanceof MediaStream) {\n WebRTCModule.mediaStreamCreate(this.id);\n\n for (const track of arg.getTracks()) {\n this.addTrack(track);\n }\n } else if (Array.isArray(arg)) {\n WebRTCModule.mediaStreamCreate(this.id);\n\n for (const track of arg) {\n this.addTrack(track);\n }\n } else if (typeof arg === 'object' && arg.streamId && arg.streamReactTag && arg.tracks) {\n this._id = arg.streamId;\n this._reactTag = arg.streamReactTag;\n\n for (const trackInfo of arg.tracks) {\n // We are not using addTrack here because the track is already part of the\n // stream, so there is no need to add it on the native side.\n this._tracks.push(new MediaStreamTrack(trackInfo));\n }\n } else {\n throw new TypeError(`invalid type: ${typeof arg}`);\n }\n }\n\n get id(): string {\n return this._id;\n }\n\n get active(): boolean {\n // TODO: can we reliably report this value?\n\n return true;\n }\n\n addTrack(track: MediaStreamTrack): void {\n const index = this._tracks.indexOf(track);\n\n if (index !== -1) {\n return;\n }\n\n this._tracks.push(track);\n WebRTCModule.mediaStreamAddTrack(this._reactTag, track.remote ? track._peerConnectionId : -1, track.id);\n }\n\n removeTrack(track: MediaStreamTrack): void {\n const index = this._tracks.indexOf(track);\n\n if (index === -1) {\n return;\n }\n\n this._tracks.splice(index, 1);\n WebRTCModule.mediaStreamRemoveTrack(this._reactTag, track.remote ? track._peerConnectionId : -1, track.id);\n }\n\n getTracks(): MediaStreamTrack[] {\n return this._tracks.slice();\n }\n\n getTrackById(trackId): MediaStreamTrack | undefined {\n return this._tracks.find(track => track.id === trackId);\n }\n\n getAudioTracks(): MediaStreamTrack[] {\n return this._tracks.filter(track => track.kind === 'audio');\n }\n\n getVideoTracks(): MediaStreamTrack[] {\n return this._tracks.filter(track => track.kind === 'video');\n }\n\n clone(): never {\n throw new Error('Not implemented.');\n }\n\n toURL(): string {\n return this._reactTag;\n }\n\n release(releaseTracks = true): void {\n const tracks = [ ...this._tracks ];\n\n for (const track of tracks) {\n this.removeTrack(track);\n\n if (releaseTracks) {\n track.release();\n }\n }\n\n WebRTCModule.mediaStreamRelease(this._reactTag);\n }\n}\n\n/**\n * Define the `onxxx` event handlers.\n */\nconst proto = MediaStream.prototype;\n\ndefineEventAttribute(proto, 'addtrack');\ndefineEventAttribute(proto, 'removetrack');\n"],"mappings":";AAAA,SAASA,WAAW,EAAEC,oBAAoB,QAAQ,yBAAyB;AAC3E,SAASC,aAAa,QAAQ,cAAc;AAE5C,OAAOC,gBAAgB,MAAgC,oBAAoB;AAE3E,S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amError.js b/lib/module/MediaStreamError.js new file mode 100644 index 000000000..ffbf834c0 --- /dev/null +++ b/lib/module/MediaStreamError.js @@ -0,0 +1,12 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +export default class MediaStreamError { + constructor(error) { + _defineProperty(this, "name", void 0); + _defineProperty(this, "message", void 0); + _defineProperty(this, "constraintName", void 0); + this.name = error.name; + this.message = error.message; + this.constraintName = error.constraintName; + } +} +//# sourceMappingURL=MediaStreamError.js.map \ No newline at end of file diff --git a/lib/module/MediaStreamError.js.map b/lib/module/MediaStreamError.js.map new file mode 100644 index 000000000..c68cc1b1d --- /dev/null +++ b/lib/module/MediaStreamError.js.map @@ -0,0 +1 @@ +{"version":3,"names":["MediaStreamError","constructor","error","_defineProperty","name","message","constraintName"],"sources":["MediaStreamError.ts"],"sourcesContent":["\nexport default class MediaStreamError {\n name: string;\n message?: string;\n constraintName?: string;\n\n constructor(error) {\n this.name = error.name;\n this.message = error.message;\n this.constraintName = error.constraintName;\n }\n}\n"],"mappings":";AACA,eAAe,MAAMA,gBAAgB,CAAC;EAKlCC,WAAWA,CAACC,KAAK,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACf,IAAI,CAACC,IAAI,GAAGF,KAAK,CAACE,IAAI;IACtB,IAAI,CAACC,OAAO,GAAGH,KAAK,CAACG,OAAO;IAC5B,IAAI,CAACC,cAAc,GAAGJ,KAAK,CAACI,cAAc;EAC9C;AACJ"} \ No newline at end of file diff --git a/lib/module/MediaStreamErrorEvent.js b/lib/module/MediaStreamErrorEvent.js new file mode 100644 index 000000000..9756146ce --- /dev/null +++ b/lib/module/MediaStreamErrorEvent.js @@ -0,0 +1,10 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +export default class MediaStreamErrorEvent { + constructor(type, eventInitDict) { + _defineProperty(this, "type", void 0); + _defineProperty(this, "error", void 0); + this.type = type.toString(); + Object.assign(this, eventInitDict); + } +} +//# sourceMappingURL=MediaStreamErrorEvent.js.map \ No newline at end of file diff --git a/lib/module/MediaStreamErrorEvent.js.map b/lib/module/MediaStreamErrorEvent.js.map new file mode 100644 index 000000000..2a2c66e97 --- /dev/null +++ b/lib/module/MediaStreamErrorEvent.js.map @@ -0,0 +1 @@ +{"version":3,"names":["MediaStreamErrorEvent","constructor","type","eventInitDict","_defineProperty","toString","Object","assign"],"sources":["MediaStreamErrorEvent.ts"],"sourcesContent":["\nimport type MediaStreamError from './MediaStreamError';\n\nexport default class MediaStreamErrorEvent {\n type: string;\n error?: MediaStreamError;\n constructor(type, eventInitDict) {\n this.type = type.toString();\n Object.assign(this, eventInitDict);\n }\n}\n"],"mappings":";AAGA,eAAe,MAAMA,qBAAqB,CAAC;EAGvCC,WAAWA,CAACC,IAAI,EAAEC,aAAa,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAC7B,IAAI,CAACF,IAAI,GAAGA,IAAI,CAACG,QAAQ,CAAC,CAAC;IAC3BC,MAAM,CAACC,MAAM,CAAC,IAAI,EAAEJ,aAAa,CAAC;EACtC;AACJ"} \ No newline at end of file diff --git a/lib/module/MediaStreamTrack.js b/lib/module/MediaStreamTrack.js new file mode 100644 index 000000000..ba2b715aa --- /dev/null +++ b/lib/module/MediaStreamTrack.js @@ -0,0 +1,180 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import { EventTarget, Event, defineEventAttribute } from 'event-target-shim/index'; +import { NativeModules } from 'react-native'; +import { addListener, removeListener } from './EventEmitter'; +import Logger from './Logger'; +import { deepClone, normalizeConstraints } from './RTCUtil'; +const log = new Logger('pc'); +const { + WebRTCModule +} = NativeModules; +export default class MediaStreamTrack extends EventTarget { + constructor(info) { + super(); + _defineProperty(this, "_constraints", void 0); + _defineProperty(this, "_enabled", void 0); + _defineProperty(this, "_settings", void 0); + _defineProperty(this, "_muted", void 0); + _defineProperty(this, "_peerConnectionId", void 0); + _defineProperty(this, "_readyState", void 0); + _defineProperty(this, "id", void 0); + _defineProperty(this, "kind", void 0); + _defineProperty(this, "label", ''); + _defineProperty(this, "remote", void 0); + this._constraints = info.constraints || {}; + this._enabled = info.enabled; + this._settings = info.settings || {}; + this._muted = false; + this._peerConnectionId = info.peerConnectionId; + this._readyState = info.readyState; + this.id = info.id; + this.kind = info.kind; + this.remote = info.remote; + if (!this.remote) { + this._registerEvents(); + } + } + get enabled() { + return this._enabled; + } + set enabled(enabled) { + if (enabled === this._enabled) { + return; + } + this._enabled = Boolean(enabled); + if (this._readyState === 'ended') { + return; + } + WebRTCModule.mediaStreamTrackSetEnabled(this.remote ? this._peerConnectionId : -1, this.id, this._enabled); + } + get muted() { + return this._muted; + } + get readyState() { + return this._readyState; + } + stop() { + this.enabled = false; + this._readyState = 'ended'; + } + + /** + * Private / custom API for switching the cameras on the fly, without the + * need for adding / removing tracks or doing any SDP renegotiation. + * + * This is how the reference application (AppRTCMobile) implements camera + * switching. + * + * @deprecated Use applyConstraints instead. + */ + _switchCamera() { + if (this.remote) { + throw new Error('Not implemented for remote tracks'); + } + if (this.kind !== 'video') { + throw new Error('Only implemented for video tracks'); + } + const constraints = deepClone(this._settings); + delete constraints.deviceId; + constraints.facingMode = this._settings.facingMode === 'user' ? 'environment' : 'user'; + this.applyConstraints(constraints); + } + _setVideoEffects(names) { + if (this.remote) { + throw new Error('Not implemented for remote tracks'); + } + if (this.kind !== 'video') { + throw new Error('Only implemented for video tracks'); + } + WebRTCModule.mediaStreamTrackSetVideoEffects(this.id, names); + } + _setVideoEffect(name) { + this._setVideoEffects([name]); + } + + /** + * Internal function which is used to set the muted state on remote tracks and + * emit the mute / unmute event. + * + * @param muted Whether the track should be marked as muted / unmuted. + */ + _setMutedInternal(muted) { + if (!this.remote) { + throw new Error('Track is not remote!'); + } + this._muted = muted; + this.dispatchEvent(new Event(muted ? 'mute' : 'unmute')); + } + + /** + * Custom API for setting the volume on an individual audio track. + * + * @param volume a gain value in the range of 0-10. defaults to 1.0 + */ + _setVolume(volume) { + if (this.kind !== 'audio') { + throw new Error('Only implemented for audio tracks'); + } + WebRTCModule.mediaStreamTrackSetVolume(this.remote ? this._peerConnectionId : -1, this.id, volume); + } + + /** + * Applies a new set of constraints to the track. + * + * @param constraints An object listing the constraints + * to apply to the track's constrainable properties; any existing + * constraints are replaced with the new values specified, and any + * constrainable properties not included are restored to their default + * constraints. If this parameter is omitted, all currently set custom + * constraints are cleared. + */ + async applyConstraints(constraints) { + if (this.kind !== 'video') { + log.info(`Only implemented for video tracks, ignoring applyConstraints for ${this.id}`); + return; + } + const normalized = normalizeConstraints({ + video: constraints !== null && constraints !== void 0 ? constraints : true + }); + this._settings = await WebRTCModule.mediaStreamTrackApplyConstraints(this.id, normalized.video); + this._constraints = constraints !== null && constraints !== void 0 ? constraints : {}; + } + clone() { + throw new Error('Not implemented.'); + } + getCapabilities() { + throw new Error('Not implemented.'); + } + getConstraints() { + return deepClone(this._constraints); + } + getSettings() { + return deepClone(this._settings); + } + _registerEvents() { + addListener(this, 'mediaStreamTrackEnded', ev => { + if (ev.trackId !== this.id || this._readyState === 'ended') { + return; + } + log.debug(`${this.id} mediaStreamTrackEnded`); + this._readyState = 'ended'; + this.dispatchEvent(new Event('ended')); + }); + } + release() { + if (this.remote) { + return; + } + removeListener(this); + WebRTCModule.mediaStreamTrackRelease(this.id); + } +} + +/** + * Define the `onxxx` event handlers. + */ +const proto = MediaStreamTrack.prototype; +defineEventAttribute(proto, 'ended'); +defineEventAttribute(proto, 'mute'); +defineEventAttribute(proto, 'unmute'); +//# sourceMappingURL=MediaStreamTrack.js.map \ No newline at end of file diff --git a/lib/module/MediaStreamTrack.js.map b/lib/module/MediaStreamTrack.js.map new file mode 100644 index 000000000..c8aebd837 --- /dev/null +++ b/lib/module/MediaStreamTrack.js.map @@ -0,0 +1 @@ +{"version":3,"names":["EventTarget","Event","defineEventAttribute","NativeModules","addListener","removeListener","Logger","deepClone","normalizeConstraints","log","WebRTCModule","MediaStreamTrack","constructor","info","_defineProperty","_constraints","constraints","_enabled","enabled","_settings","settings","_muted","_peerConnectionId","peerConnectionId","_readyState","readyState","id","kind","remote","_registerEvents","Boolean","mediaStreamTrackSetEnabled","muted","stop","_switchCamera","Error","deviceId","facingMode","applyConstraints","_setVideoEffects","names","mediaStreamTrackSetVideoEffects","_setVideoEffect","name","_setMutedInternal","dispatchEvent","_setVolume","volume","mediaStreamTrackSetVolume","normalized","video","mediaStreamTrackApplyConstraints","clone","getCapabilities","getConstraints","getSettings","ev","trackId","debug","release","mediaStreamTrackRelease","proto","prototype"],"sources":["MediaStreamTrack.ts"],"sourcesContent":["import { EventTarget, Event, defineEventAttribute } from 'event-target-shim/index';\nimport { NativeModules } from 'react-native';\n\nimport { MediaTrackConstraints } from './Constraints';\nimport { addListener, removeListener } from './EventEmitter';\nimport Logger from './Logger';\nimport { deepClone, normalizeConstraints } from './RTCUtil';\n\nconst log = new Logger('pc');\nconst { WebRTCModule } = NativeModules;\n\n\ntype MediaStreamTrackState = 'live' | 'ended';\n\nexport type MediaStreamTrackInfo = {\n id: string;\n kind: string;\n remote: boolean;\n constraints: object;\n enabled: boolean;\n settings: object;\n peerConnectionId: number;\n readyState: MediaStreamTrackState;\n}\n\nexport type MediaTrackSettings = {\n width?: number;\n height?: number;\n frameRate?: number;\n facingMode?: string;\n deviceId?: string;\n groupId?: string;\n}\n\ntype MediaStreamTrackEventMap = {\n ended: Event<'ended'>;\n mute: Event<'mute'>;\n unmute: Event<'unmute'>;\n}\n\nexport default class MediaStreamTrack extends EventTarget {\n _constraints: MediaTrackConstraints;\n _enabled: boolean;\n _settings: MediaTrackSettings;\n _muted: boolean;\n _peerConnectionId: number;\n _readyState: MediaStreamTrackState;\n\n readonly id: string;\n readonly kind: string;\n readonly label: string = '';\n readonly remote: boolean;\n\n constructor(info: MediaStreamTrackInfo) {\n super();\n\n this._constraints = info.constraints || {};\n this._enabled = info.enabled;\n this._settings = info.settings || {};\n this._muted = false;\n this._peerConnectionId = info.peerConnectionId;\n this._readyState = info.readyState;\n\n this.id = info.id;\n this.kind = info.kind;\n this.remote = info.remote;\n\n if (!this.remote) {\n this._registerEvents();\n }\n }\n\n get enabled(): boolean {\n return this._enabled;\n }\n\n set enabled(enabled: boolean) {\n if (enabled === this._enabled) {\n return;\n }\n\n this._enabled = Boolean(enabled);\n\n if (this._readyState === 'ended') {\n return;\n }\n\n WebRTCModule.mediaStreamTrackSetEnabled(this.remote ? this._peerConnectionId : -1, this.id, this._enabled);\n }\n\n get muted(): boolean {\n return this._muted;\n }\n\n get readyState(): string {\n return this._readyState;\n }\n\n stop(): void {\n this.enabled = false;\n this._readyState = 'ended';\n }\n\n /**\n * Private / custom API for switching the cameras on the fly, without the\n * need for adding / removing tracks or doing any SDP renegotiation.\n *\n * This is how the reference application (AppRTCMobile) implements camera\n * switching.\n *\n * @deprecated Use applyConstraints instead.\n */\n _switchCamera(): void {\n if (this.remote) {\n throw new Error('Not implemented for remote tracks');\n }\n\n if (this.kind !== 'video') {\n throw new Error('Only implemented for video tracks');\n }\n\n const constraints = deepClone(this._settings);\n\n delete constraints.deviceId;\n constraints.facingMode = this._settings.facingMode === 'user' ? 'environment' : 'user';\n\n this.applyConstraints(constraints);\n }\n\n _setVideoEffects(names: string[]) {\n if (this.remote) {\n throw new Error('Not implemented for remote tracks');\n }\n\n if (this.kind !== 'video') {\n throw new Error('Only implemented for video tracks');\n }\n\n WebRTCModule.mediaStreamTrackSetVideoEffects(this.id, names);\n }\n\n _setVideoEffect(name: string) {\n this._setVideoEffects([ name ]);\n }\n\n /**\n * Internal function which is used to set the muted state on remote tracks and\n * emit the mute / unmute event.\n *\n * @param muted Whether the track should be marked as muted / unmuted.\n */\n _setMutedInternal(muted: boolean) {\n if (!this.remote) {\n throw new Error('Track is not remote!');\n }\n\n this._muted = muted;\n this.dispatchEvent(new Event(muted ? 'mute' : 'unmute'));\n }\n\n /**\n * Custom API for setting the volume on an individual audio track.\n *\n * @param volume a gain value in the range of 0-10. defaults to 1.0\n */\n _setVolume(volume: number) {\n if (this.kind !== 'audio') {\n throw new Error('Only implemented for audio tracks');\n }\n\n WebRTCModule.mediaStreamTrackSetVolume(this.remote ? this._peerConnectionId : -1, this.id, volume);\n }\n\n /**\n * Applies a new set of constraints to the track.\n *\n * @param constraints An object listing the constraints\n * to apply to the track's constrainable properties; any existing\n * constraints are replaced with the new values specified, and any\n * constrainable properties not included are restored to their default\n * constraints. If this parameter is omitted, all currently set custom\n * constraints are cleared.\n */\n async applyConstraints(constraints?: MediaTrackConstraints): Promise {\n if (this.kind !== 'video') {\n log.info(`Only implemented for video tracks, ignoring applyConstraints for ${this.id}`);\n\n return;\n }\n\n const normalized = normalizeConstraints({ video: constraints ?? true });\n\n this._settings = await WebRTCModule.mediaStreamTrackApplyConstraints(this.id, normalized.video);\n this._constraints = constraints ?? {};\n }\n\n clone(): never {\n throw new Error('Not implemented.');\n }\n\n getCapabilities(): never {\n throw new Error('Not implemented.');\n }\n\n getConstraints() {\n return deepClone(this._constraints);\n }\n\n getSettings(): MediaTrackSettings {\n return deepClone(this._settings);\n }\n\n _registerEvents(): void {\n addListener(this, 'mediaStreamTrackEnded', (ev: any) => {\n if (ev.trackId !== this.id || this._readyState === 'ended') {\n return;\n }\n\n log.debug(`${this.id} mediaStreamTrackEnded`);\n this._readyState = 'ended';\n\n this.dispatchEvent(new Event('ended'));\n });\n }\n\n release(): void {\n if (this.remote) {\n return;\n }\n\n removeListener(this);\n WebRTCModule.mediaStreamTrackRelease(this.id);\n }\n}\n\n/**\n * Define the `onxxx` event handlers.\n */\nconst proto = MediaStreamTrack.prototype;\n\ndefineEventAttribute(proto, 'ended');\ndefineEventAttribute(proto, 'mute');\ndefineEventAttribute(proto, 'unmute');\n"],"mappings":";AAAA,SAASA,WAAW,EAAEC,KAAK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E,OAAO,CAAC;AACpC3D,oBAAoB,CAAC2D,KAAK,EAAE,MAAM,CAAC;AACnC3D,oBAAoB,CAAC2D,KAAK,EAAE,QAAQ,CAAC"} \ No newline at end of file diff --git a/lib/module/MediaStreamTrackEvent.js b/lib/module/MediaStreamTrackEvent.js new file mode 100644 index 000000000..c18e565fe --- /dev/null +++ b/lib/module/MediaStreamTrackEvent.js @@ -0,0 +1,19 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import { Event } from 'event-target-shim/index'; +/** + * @eventClass + * This event is fired whenever the MediaStreamTrack has changed in any way. + * @param {MEDIA_STREAM_EVENTS} type - The type of event. + * @param {IMediaStreamTrackEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaStream#events MDN} for details. + */ +export default class MediaStreamTrackEvent extends Event { + /** @eventProperty */ + + constructor(type, eventInitDict) { + super(type, eventInitDict); + _defineProperty(this, "track", void 0); + this.track = eventInitDict.track; + } +} +//# sourceMappingURL=MediaStreamTrackEvent.js.map \ No newline at end of file diff --git a/lib/module/MediaStreamTrackEvent.js.map b/lib/module/MediaStreamTrackEvent.js.map new file mode 100644 index 000000000..8fc0f9ba5 --- /dev/null +++ b/lib/module/MediaStreamTrackEvent.js.map @@ -0,0 +1 @@ +{"version":3,"names":["Event","MediaStreamTrackEvent","constructor","type","eventInitDict","_defineProperty","track"],"sources":["MediaStreamTrackEvent.ts"],"sourcesContent":["import { Event } from 'event-target-shim/index';\n\nimport type MediaStreamTrack from './MediaStreamTrack';\n\ntype MEDIA_STREAM_EVENTS = 'addtrack'| 'removetrack'\n\ninterface IMediaStreamTrackEventInitDict extends Event.EventInit {\n track: MediaStreamTrack;\n}\n\n/**\n * @eventClass\n * This event is fired whenever the MediaStreamTrack has changed in any way.\n * @param {MEDIA_STREAM_EVENTS} type - The type of event.\n * @param {IMediaStreamTrackEventInitDict} eventInitDict - The event init properties.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaStream#events MDN} for details.\n */\nexport default class MediaStreamTrackEvent extends Event {\n /** @eventProperty */\n track: MediaStreamTrack;\n constructor(type: TEventType, eventInitDict: IMediaStreamTrackEventInitDict) {\n super(type, eventInitDict);\n this.track = eventInitDict.track;\n }\n}\n"],"mappings":";AAAA,SAASA,KAAK,QAAQ,yBAAyB;AAU/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,qBAAqB,SAAiDD,KAAK,CAAa;EACzG;;EAEAE,WAAWA,CAACC,IAAgB,EAAEC,aAA6C,EAAE;IACzE,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAACC,eAAA;IAC3B,IAAI,CAACC,KAAK,GAAGF,aAAa,CAACE,KAAK;EACpC;AACJ"} \ No newline at end of file diff --git a/lib/module/MessageEvent.js b/lib/module/MessageEvent.js new file mode 100644 index 000000000..5edf756b4 --- /dev/null +++ b/lib/module/MessageEvent.js @@ -0,0 +1,20 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import { Event } from 'event-target-shim/index'; +/** + * @eventClass + * This event is fired whenever the RTCDataChannel send message. + * @param {MESSAGE_EVENTS} type - The type of event. + * @param {IMessageEventInitDict} eventInitDict - The event init properties. + * @see + * {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/message_event#event_type MDN} for details. + */ +export default class MessageEvent extends Event { + /** @eventProperty */ + + constructor(type, eventInitDict) { + super(type, eventInitDict); + _defineProperty(this, "data", void 0); + this.data = eventInitDict.data; + } +} +//# sourceMappingURL=MessageEvent.js.map \ No newline at end of file diff --git a/lib/module/MessageEvent.js.map b/lib/module/MessageEvent.js.map new file mode 100644 index 000000000..64e404383 --- /dev/null +++ b/lib/module/MessageEvent.js.map @@ -0,0 +1 @@ +{"version":3,"names":["Event","MessageEvent","constructor","type","eventInitDict","_defineProperty","data"],"sources":["MessageEvent.ts"],"sourcesContent":["import { Event } from 'event-target-shim/index';\n\nexport type MessageEventData = string | ArrayBuffer | Blob;\n\ntype MESSAGE_EVENTS = 'message' | 'messageerror';\n\ninterface IMessageEventInitDict extends Event.EventInit {\n data: MessageEventData;\n}\n\n/**\n * @eventClass\n * This event is fired whenever the RTCDataChannel send message.\n * @param {MESSAGE_EVENTS} type - The type of event.\n * @param {IMessageEventInitDict} eventInitDict - The event init properties.\n * @see\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/message_event#event_type MDN} for details.\n */\nexport default class MessageEvent extends Event {\n /** @eventProperty */\n data: MessageEventData;\n constructor(type: TEventType, eventInitDict: IMessageEventInitDict) {\n super(type, eventInitDict);\n this.data = eventInitDict.data;\n }\n}\n"],"mappings":";AAAA,SAASA,KAAK,QAAQ,yBAAyB;AAU/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,YAAY,SAA4CD,KAAK,CAAa;EAC3F;;EAEAE,WAAWA,CAACC,IAAgB,EAAEC,aAAoC,EAAE;IAChE,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAACC,eAAA;IAC3B,IAAI,CAACC,IAAI,GAAGF,aAAa,CAACE,IAAI;EAClC;AACJ"} \ No newline at end of file diff --git a/lib/module/Permissions.js b/lib/module/Permissions.js new file mode 100644 index 000000000..ede380a1f --- /dev/null +++ b/lib/module/Permissions.js @@ -0,0 +1,109 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import { NativeModules, PermissionsAndroid, Platform } from 'react-native'; +const { + WebRTCModule +} = NativeModules; + +/** + * Type declaration for a permissions descriptor. + */ + +/** + * Class implementing a subset of W3C's Permissions API as defined by: + * https://www.w3.org/TR/permissions/ + */ +class Permissions { + constructor() { + _defineProperty(this, "RESULT", { + DENIED: 'denied', + GRANTED: 'granted', + PROMPT: 'prompt' + }); + _defineProperty(this, "VALID_PERMISSIONS", ['camera', 'microphone']); + _defineProperty(this, "_lastReq", Promise.resolve()); + } + /** + * Possible result values for {@link query}, in accordance with: + * https://www.w3.org/TR/permissions/#status-of-a-permission + */ + /** + * This implementation only supports requesting these permissions, a subset + * of: https://www.w3.org/TR/permissions/#permission-registry + */ + /** + * Helper for requesting Android permissions. On Android only one permission + * can be requested at a time (unless the multi-permission API is used, + * but we are not using that for symmetry with the W3C API for querying) + * so we'll queue them up. + * + * @param perm - The requested permission from + * {@link PermissionsAndroid.PERMISSIONS} + * https://facebook.github.io/react-native/docs/permissionsandroid#permissions-that-require-prompting-the-user + */ + _requestPermissionAndroid(perm) { + return new Promise(resolve => { + PermissionsAndroid.request(perm).then(granted => resolve(granted === PermissionsAndroid.RESULTS.GRANTED), () => resolve(false)); + }); + } + + /** + * Validates the given permission descriptor. + */ + _validatePermissionDescriptior(permissionDesc) { + if (typeof permissionDesc !== 'object') { + throw new TypeError('Argument 1 of Permissions.query is not an object.'); + } + if (typeof permissionDesc.name === 'undefined') { + throw new TypeError('Missing required \'name\' member of PermissionDescriptor.'); + } + if (this.VALID_PERMISSIONS.indexOf(permissionDesc.name) === -1) { + throw new TypeError('\'name\' member of PermissionDescriptor is not a valid value for enumeration PermissionName.'); + } + } + + /** + * Method for querying the status of a permission, according to: + * https://www.w3.org/TR/permissions/#permissions-interface + */ + query(permissionDesc) { + try { + this._validatePermissionDescriptior(permissionDesc); + } catch (e) { + return Promise.reject(e); + } + if (Platform.OS === 'android') { + const perm = permissionDesc.name === 'camera' ? PermissionsAndroid.PERMISSIONS.CAMERA : PermissionsAndroid.PERMISSIONS.RECORD_AUDIO; + return new Promise(resolve => { + PermissionsAndroid.check(perm).then(granted => resolve(granted ? this.RESULT.GRANTED : this.RESULT.PROMPT), () => resolve(this.RESULT.PROMPT)); + }); + } else if (Platform.OS === 'ios' || Platform.OS === 'macos') { + return WebRTCModule.checkPermission(permissionDesc.name); + } else { + return Promise.reject(new TypeError('Unsupported platform.')); + } + } + + /** + * Custom method NOT defined by W3C's permissions API, which allows the + * caller to request a permission. + */ + request(permissionDesc) { + try { + this._validatePermissionDescriptior(permissionDesc); + } catch (e) { + return Promise.reject(e); + } + if (Platform.OS === 'android') { + const perm = permissionDesc.name === 'camera' ? PermissionsAndroid.PERMISSIONS.CAMERA : PermissionsAndroid.PERMISSIONS.RECORD_AUDIO; + const requestPermission = () => this._requestPermissionAndroid(perm); + this._lastReq = this._lastReq.then(requestPermission, requestPermission); + return this._lastReq; + } else if (Platform.OS === 'ios' || Platform.OS === 'macos') { + return WebRTCModule.requestPermission(permissionDesc.name); + } else { + return Promise.reject(new TypeError('Unsupported platform.')); + } + } +} +export default new Permissions(); +//# sourceMappingURL=Permissions.js.map \ No newline at end of file diff --git a/lib/module/Permissions.js.map b/lib/module/Permissions.js.map new file mode 100644 index 000000000..971620fd2 --- /dev/null +++ b/lib/module/Permissions.js.map @@ -0,0 +1 @@ +{"version":3,"names":["NativeModules","PermissionsAndroid","Platform","WebRTCModule","Permissions","constructor","_defineProperty","DENIED","GRANTED","PROMPT","Promise","resolve","_requestPermissionAndroid","perm","request","then","granted","RESULTS","_validatePermissionDescriptior","permissionDesc","TypeError","name","VALID_PERMISSIONS","indexOf","query","e","reject","OS","PERMISSIONS","CAMERA","RECORD_AUDIO","check","RESULT","checkPermission","requestPermission","_lastReq"],"sources":["Permissions.ts"],"sourcesContent":["\nimport { NativeModules, Permission, PermissionsAndroid, Platform } from 'react-native';\n\nconst { WebRTCModule } = NativeModules;\n\n/**\n * Type declaration for a permissions descriptor.\n */\ntype PermissionDescriptor = {\n name: string;\n};\n\n/**\n * Class implementing a subset of W3C's Permissions API as defined by:\n * https://www.w3.org/TR/permissions/\n */\nclass Permissions {\n /**\n * Possible result values for {@link query}, in accordance with:\n * https://www.w3.org/TR/permissions/#status-of-a-permission\n */\n RESULT = {\n DENIED: 'denied',\n GRANTED: 'granted',\n PROMPT: 'prompt'\n };\n\n /**\n * This implementation only supports requesting these permissions, a subset\n * of: https://www.w3.org/TR/permissions/#permission-registry\n */\n VALID_PERMISSIONS = [ 'camera', 'microphone' ];\n\n _lastReq: Promise = Promise.resolve();\n\n /**\n * Helper for requesting Android permissions. On Android only one permission\n * can be requested at a time (unless the multi-permission API is used,\n * but we are not using that for symmetry with the W3C API for querying)\n * so we'll queue them up.\n *\n * @param perm - The requested permission from\n * {@link PermissionsAndroid.PERMISSIONS}\n * https://facebook.github.io/react-native/docs/permissionsandroid#permissions-that-require-prompting-the-user\n */\n _requestPermissionAndroid(perm: Permission) {\n return new Promise(resolve => {\n PermissionsAndroid.request(perm).then(\n granted => resolve(granted === PermissionsAndroid.RESULTS.GRANTED),\n () => resolve(false)\n );\n });\n }\n\n /**\n * Validates the given permission descriptor.\n */\n _validatePermissionDescriptior(permissionDesc) {\n if (typeof permissionDesc !== 'object') {\n throw new TypeError('Argument 1 of Permissions.query is not an object.');\n }\n\n if (typeof permissionDesc.name === 'undefined') {\n throw new TypeError('Missing required \\'name\\' member of PermissionDescriptor.');\n }\n\n if (this.VALID_PERMISSIONS.indexOf(permissionDesc.name) === -1) {\n throw new TypeError(\n '\\'name\\' member of PermissionDescriptor is not a valid value for enumeration PermissionName.'\n );\n }\n }\n\n /**\n * Method for querying the status of a permission, according to:\n * https://www.w3.org/TR/permissions/#permissions-interface\n */\n query(permissionDesc: PermissionDescriptor) {\n try {\n this._validatePermissionDescriptior(permissionDesc);\n } catch (e) {\n return Promise.reject(e);\n }\n\n if (Platform.OS === 'android') {\n const perm =\n permissionDesc.name === 'camera'\n ? PermissionsAndroid.PERMISSIONS.CAMERA\n : PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;\n\n return new Promise(resolve => {\n PermissionsAndroid.check(perm).then(\n granted => resolve(granted ? this.RESULT.GRANTED : this.RESULT.PROMPT),\n () => resolve(this.RESULT.PROMPT)\n );\n });\n } else if (Platform.OS === 'ios' || Platform.OS === 'macos') {\n return WebRTCModule.checkPermission(permissionDesc.name);\n } else {\n return Promise.reject(new TypeError('Unsupported platform.'));\n }\n }\n\n /**\n * Custom method NOT defined by W3C's permissions API, which allows the\n * caller to request a permission.\n */\n request(permissionDesc: PermissionDescriptor) {\n try {\n this._validatePermissionDescriptior(permissionDesc);\n } catch (e) {\n return Promise.reject(e);\n }\n\n if (Platform.OS === 'android') {\n const perm =\n permissionDesc.name === 'camera'\n ? PermissionsAndroid.PERMISSIONS.CAMERA\n : PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;\n const requestPermission = () => this._requestPermissionAndroid(perm);\n\n this._lastReq = this._lastReq.then(requestPermission, requestPermission);\n\n return this._lastReq;\n } else if (Platform.OS === 'ios' || Platform.OS === 'macos') {\n return WebRTCModule.requestPermission(permissionDesc.name);\n } else {\n return Promise.reject(new TypeError('Unsupported platform.'));\n }\n }\n}\n\nexport default new Permissions();\n"],"mappings":";AACA,SAASA,aAAa,EAAcC,kBAAkB,EAAEC,QAAQ,QAAQ,cAAc;AAEtF,MAAM;EAAEC;AAAa,CAAC,GAAGH,aAAa;;AAEtC;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA,MAAMI,WAAW,CAAC;EAAAC,YAAA;IAAAC,eAAA,iBAKL;MACLC,MAAM,EAAE,QAAQ;MAChBC,OAAO,EAAE,SAAS;MAClBC,MAAM,EAAE;IACZ,CAAC;IAAAH,eAAA,4BAMmB,CAAE,QAAQ,EAAE,YAAY,CAAE;IAAAA,eAAA,mBAEjBI,OAAO,CAACC,OAAO,CAAC,CAAC;EAAA;EAhB9C;AACJ;AACA;AACA;EAOI;AACJ;AACA;AACA;EAKI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACIC,yBAAyBA,CAACC,IAAgB,EAAE;IACxC,OAAO,IAAIH,OAAO,CAACC,OAAO,IAAI;MAC1BV,kBAAkB,CAACa,OAAO,CAACD,IAAI,CAAC,CAACE,IAAI,CACjCC,OAAO,IAAIL,OAAO,CAACK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CAAC"} \ No newline at end of file diff --git a/lib/module/RTCAudioSession.js b/lib/module/RTCAudioSession.js new file mode 100644 index 000000000..1de961e9c --- /dev/null +++ b/lib/module/RTCAudioSession.js @@ -0,0 +1,26 @@ +import { NativeModules, Platform } from 'react-native'; +const { + WebRTCModule +} = NativeModules; +export default class RTCAudioSession { + /** + * To be called when CallKit activates the audio session. + */ + static audioSessionDidActivate() { + // Only valid for iOS + if (Platform.OS === 'ios') { + WebRTCModule.audioSessionDidActivate(); + } + } + + /** + * To be called when CallKit deactivates the audio session. + */ + static audioSessionDidDeactivate() { + // Only valid for iOS + if (Platform.OS === 'ios') { + WebRTCModule.audioSessionDidDeactivate(); + } + } +} +//# sourceMappingURL=RTCAudioSession.js.map \ No newline at end of file diff --git a/lib/module/RTCAudioSession.js.map b/lib/module/RTCAudioSession.js.map new file mode 100644 index 000000000..738dcedbe --- /dev/null +++ b/lib/module/RTCAudioSession.js.map @@ -0,0 +1 @@ +{"version":3,"names":["NativeModules","Platform","WebRTCModule","RTCAudioSession","audioSessionDidActivate","OS","audioSessionDidDeactivate"],"sources":["RTCAudioSession.ts"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\n\nconst { WebRTCModule } = NativeModules;\n\nexport default class RTCAudioSession {\n /**\n * To be called when CallKit activates the audio session.\n */\n static audioSessionDidActivate() {\n // Only valid for iOS\n if (Platform.OS === 'ios') {\n WebRTCModule.audioSessionDidActivate();\n }\n }\n\n /**\n * To be called when CallKit deactivates the audio session.\n */\n static audioSessionDidDeactivate() {\n // Only valid for iOS\n if (Platform.OS === 'ios') {\n WebRTCModule.audioSessionDidDeactivate();\n }\n }\n}\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAM;EAAEC;AAAa,CAAC,GAAGF,aAAa;AAEtC,eAAe,MAAMG,eAAe,CAAC;EACjC;AACJ;AACA;EACI,OAAOC,uBAAuBA,CAAA,EAAG;IAC7B;IACA,IAAIH,QAAQ,CAACI,EAAE,KAAK,KAAK,EAAE;MACvBH,YAAY,CAACE,uBAAuB,CAAC,CAAC;IAC1C;EACJ;;EAEA;AACJ;AACA;EACI,OAAOE,yBAAyBA,CAAA,EAAG;IAC/B;IACA,IAAIL,QAAQ,CAACI,EAAE,KAAK,KAAK,EAAE;MACvBH,YAAY,CAACI,yBAAyB,CAAC,CAAC;IAC5C;EACJ;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCDataChannel.js b/lib/module/RTCDataChannel.js new file mode 100644 index 000000000..f1666023d --- /dev/null +++ b/lib/module/RTCDataChannel.js @@ -0,0 +1,155 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import * as base64 from 'base64-js'; +import { EventTarget, defineEventAttribute } from 'event-target-shim/index'; +import { NativeModules } from 'react-native'; +import { addListener, removeListener } from './EventEmitter'; +import MessageEvent from './MessageEvent'; +import RTCDataChannelEvent from './RTCDataChannelEvent'; +const { + WebRTCModule +} = NativeModules; +export default class RTCDataChannel extends EventTarget { + // we only support 'arraybuffer' + + constructor(info) { + super(); + _defineProperty(this, "_peerConnectionId", void 0); + _defineProperty(this, "_reactTag", void 0); + _defineProperty(this, "_bufferedAmount", void 0); + _defineProperty(this, "_id", void 0); + _defineProperty(this, "_label", void 0); + _defineProperty(this, "_maxPacketLifeTime", void 0); + _defineProperty(this, "_maxRetransmits", void 0); + _defineProperty(this, "_negotiated", void 0); + _defineProperty(this, "_ordered", void 0); + _defineProperty(this, "_protocol", void 0); + _defineProperty(this, "_readyState", void 0); + _defineProperty(this, "binaryType", 'arraybuffer'); + _defineProperty(this, "bufferedAmountLowThreshold", 0); + this._peerConnectionId = info.peerConnectionId; + this._reactTag = info.reactTag; + this._bufferedAmount = 0; + this._label = info.label; + this._id = info.id === -1 ? null : info.id; // null until negotiated. + this._ordered = Boolean(info.ordered); + this._maxPacketLifeTime = info.maxPacketLifeTime; + this._maxRetransmits = info.maxRetransmits; + this._protocol = info.protocol || ''; + this._negotiated = Boolean(info.negotiated); + this._readyState = info.readyState; + this._registerEvents(); + } + get bufferedAmount() { + return this._bufferedAmount; + } + get label() { + return this._label; + } + get id() { + return this._id; + } + get ordered() { + return this._ordered; + } + get maxPacketLifeTime() { + return this._maxPacketLifeTime; + } + get maxRetransmits() { + return this._maxRetransmits; + } + get protocol() { + return this._protocol; + } + get negotiated() { + return this._negotiated; + } + get readyState() { + return this._readyState; + } + send(data) { + if (typeof data === 'string') { + WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, data, 'text'); + return; + } + + // Safely convert the buffer object to an Uint8Array for base64-encoding + if (ArrayBuffer.isView(data)) { + data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength); + } else if (data instanceof ArrayBuffer) { + data = new Uint8Array(data); + } else { + throw new TypeError('Data must be either string, ArrayBuffer, or ArrayBufferView'); + } + const base64data = base64.fromByteArray(data); + WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, base64data, 'binary'); + } + close() { + if (this._readyState === 'closing' || this._readyState === 'closed') { + return; + } + WebRTCModule.dataChannelClose(this._peerConnectionId, this._reactTag); + } + _registerEvents() { + addListener(this, 'dataChannelStateChanged', ev => { + if (ev.reactTag !== this._reactTag) { + return; + } + this._readyState = ev.state; + if (this._id === null && ev.id !== -1) { + this._id = ev.id; + } + if (this._readyState === 'open') { + this.dispatchEvent(new RTCDataChannelEvent('open', { + channel: this + })); + } else if (this._readyState === 'closing') { + this.dispatchEvent(new RTCDataChannelEvent('closing', { + channel: this + })); + } else if (this._readyState === 'closed') { + this.dispatchEvent(new RTCDataChannelEvent('close', { + channel: this + })); + + // This DataChannel is done, clean up event handlers. + removeListener(this); + WebRTCModule.dataChannelDispose(this._peerConnectionId, this._reactTag); + } + }); + addListener(this, 'dataChannelReceiveMessage', ev => { + if (ev.reactTag !== this._reactTag) { + return; + } + let data = ev.data; + if (ev.type === 'binary') { + data = base64.toByteArray(ev.data).buffer; + } + this.dispatchEvent(new MessageEvent('message', { + data + })); + }); + addListener(this, 'dataChannelDidChangeBufferedAmount', ev => { + if (ev.reactTag !== this._reactTag) { + return; + } + this._bufferedAmount = ev.bufferedAmount; + if (this._bufferedAmount < this.bufferedAmountLowThreshold) { + this.dispatchEvent(new RTCDataChannelEvent('bufferedamountlow', { + channel: this + })); + } + }); + } +} + +/** + * Define the `onxxx` event handlers. + */ +const proto = RTCDataChannel.prototype; +defineEventAttribute(proto, 'bufferedamountlow'); +defineEventAttribute(proto, 'close'); +defineEventAttribute(proto, 'closing'); +defineEventAttribute(proto, 'error'); +defineEventAttribute(proto, 'message'); +defineEventAttribute(proto, 'open'); +//# sourceMappingURL=RTCDataChannel.js.map \ No newline at end of file diff --git a/lib/module/RTCDataChannel.js.map b/lib/module/RTCDataChannel.js.map new file mode 100644 index 000000000..b3e7f4992 --- /dev/null +++ b/lib/module/RTCDataChannel.js.map @@ -0,0 +1 @@ +{"version":3,"names":["base64","EventTarget","defineEventAttribute","NativeModules","addListener","removeListener","MessageEvent","RTCDataChannelEvent","WebRTCModule","RTCDataChannel","constructor","info","_defineProperty","_peerConnectionId","peerConnectionId","_reactTag","reactTag","_bufferedAmount","_label","label","_id","id","_ordered","Boolean","ordered","_maxPacketLifeTime","maxPacketLifeTime","_maxRetransmits","maxRetransmits","_protocol","protocol","_negotiated","negotiated","_readyState","readyState","_registerEvents","bufferedAmount","send","data","dataChannelSend","ArrayBuffer","isView","Uint8Array","buffer","byteOffset","byteLength","TypeError","base64data","fromByteArray","close","dataChannelClose","ev","state","dispatchEvent","channel","dataChannelDispose","type","toByteArray","bufferedAmountLowThreshold","proto","prototype"],"sources":["RTCDataChannel.ts"],"sourcesContent":["import * as base64 from 'base64-js';\nimport { EventTarget, defineEventAttribute } from 'event-target-shim/index';\nimport { NativeModules } from 'react-native';\n\nimport { addListener, removeListener } from './EventEmitter';\nimport MessageEvent from './MessageEvent';\nimport RTCDataChannelEvent from './RTCDataChannelEvent';\n\nconst { WebRTCModule } = NativeModules;\n\ntype RTCDataChannelState = 'connecting' | 'open' | 'closing' | 'closed';\n\ntype DataChannelEventMap = {\n bufferedamountlow: RTCDataChannelEvent<'bufferedamountlow'>;\n close: RTCDataChannelEvent<'close'>;\n closing: RTCDataChannelEvent<'closing'>;\n error: RTCDataChannelEvent<'error'>;\n message: MessageEvent<'message'>;\n open: RTCDataChannelEvent<'open'>;\n};\n\nexport default class RTCDataChannel extends EventTarget {\n _peerConnectionId: number;\n _reactTag: string;\n\n _bufferedAmount: number;\n _id: number;\n _label: string;\n _maxPacketLifeTime?: number;\n _maxRetransmits?: number;\n _negotiated: boolean;\n _ordered: boolean;\n _protocol: string;\n _readyState: RTCDataChannelState;\n\n binaryType = 'arraybuffer'; // we only support 'arraybuffer'\n bufferedAmountLowThreshold = 0;\n\n constructor(info) {\n super();\n\n this._peerConnectionId = info.peerConnectionId;\n this._reactTag = info.reactTag;\n\n this._bufferedAmount = 0;\n this._label = info.label;\n this._id = info.id === -1 ? null : info.id; // null until negotiated.\n this._ordered = Boolean(info.ordered);\n this._maxPacketLifeTime = info.maxPacketLifeTime;\n this._maxRetransmits = info.maxRetransmits;\n this._protocol = info.protocol || '';\n this._negotiated = Boolean(info.negotiated);\n this._readyState = info.readyState;\n\n this._registerEvents();\n }\n\n get bufferedAmount(): number {\n return this._bufferedAmount;\n }\n\n get label(): string {\n return this._label;\n }\n\n get id(): number {\n return this._id;\n }\n\n get ordered(): boolean {\n return this._ordered;\n }\n\n get maxPacketLifeTime(): number | undefined {\n return this._maxPacketLifeTime;\n }\n\n get maxRetransmits(): number | undefined {\n return this._maxRetransmits;\n }\n\n get protocol(): string {\n return this._protocol;\n }\n\n get negotiated(): boolean {\n return this._negotiated;\n }\n\n get readyState(): string {\n return this._readyState;\n }\n\n send(data: string): void;\n send(data: ArrayBuffer): void;\n send(data: ArrayBufferView): void;\n send(data: string | ArrayBuffer | ArrayBufferView): void {\n if (typeof data === 'string') {\n WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, data, 'text');\n\n return;\n }\n\n // Safely convert the buffer object to an Uint8Array for base64-encoding\n if (ArrayBuffer.isView(data)) {\n data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n } else if (data instanceof ArrayBuffer) {\n data = new Uint8Array(data);\n } else {\n throw new TypeError('Data must be either string, ArrayBuffer, or ArrayBufferView');\n }\n\n const base64data = base64.fromByteArray(data as Uint8Array);\n\n WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, base64data, 'binary');\n }\n\n close(): void {\n if (this._readyState === 'closing' || this._readyState === 'closed') {\n return;\n }\n\n WebRTCModule.dataChannelClose(this._peerConnectionId, this._reactTag);\n }\n\n _registerEvents(): void {\n addListener(this, 'dataChannelStateChanged', (ev: any) => {\n if (ev.reactTag !== this._reactTag) {\n return;\n }\n\n this._readyState = ev.state;\n\n if (this._id === null && ev.id !== -1) {\n this._id = ev.id;\n }\n\n if (this._readyState === 'open') {\n this.dispatchEvent(new RTCDataChannelEvent('open', { channel: this }));\n } else if (this._readyState === 'closing') {\n this.dispatchEvent(new RTCDataChannelEvent('closing', { channel: this }));\n } else if (this._readyState === 'closed') {\n this.dispatchEvent(new RTCDataChannelEvent('close', { channel: this }));\n\n // This DataChannel is done, clean up event handlers.\n removeListener(this);\n\n WebRTCModule.dataChannelDispose(this._peerConnectionId, this._reactTag);\n }\n });\n\n addListener(this, 'dataChannelReceiveMessage', (ev: any) => {\n if (ev.reactTag !== this._reactTag) {\n return;\n }\n\n let data = ev.data;\n\n if (ev.type === 'binary') {\n data = base64.toByteArray(ev.data).buffer;\n }\n\n this.dispatchEvent(new MessageEvent('message', { data }));\n });\n\n addListener(this, 'dataChannelDidChangeBufferedAmount', (ev: any) => {\n if (ev.reactTag !== this._reactTag) {\n return;\n }\n\n this._bufferedAmount = ev.bufferedAmount;\n\n if (this._bufferedAmount < this.bufferedAmountLowThreshold) {\n this.dispatchEvent(new RTCDataChannelEvent('bufferedamountlow', { channel: this }));\n }\n });\n }\n}\n\n/**\n * Define the `onxxx` event handlers.\n */\nconst proto = RTCDataChannel.prototype;\n\ndefineEventAttribute(proto, 'bufferedamountlow');\ndefineEventAttribute(proto, 'close');\ndefineEventAttribute(proto, 'closing');\ndefineEventAttribute(proto, 'error');\ndefineEventAttribute(proto, 'message');\ndefineEventAttribute(proto, 'open');\n"],"mappings":";AAAA,OAAO,KAAKA,MAAM,MAAM,WAAW;AACnC,SAASC,WAAW,EAAEC,oBAAoB,QAAQ,yBAAyB;AAC3E,SAASC,aAAa,QAAQ,cAAc;AAE5C,SAASC,WAAW,EAAEC,cAAc,QAAQ,gBAAgB;AAC5D,OAAOC,YAAY,MAAM,gBAAgB;AACzC,OAAOC,mBAAmB,MAAM,uBAAuB;AAEvD,MAAM;EAAEC;AAAa,CAAC,GAAGL,aAAa;AAatC,eAAe,MAAMM,cAAc,SAASR,WAAW,CAAsB;EAc7C;;EAG5BS,WAAWA,CAACC,IAAI,EAAE;IACd,KAAK,CAAC,CAAC;IAACC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA,qBAJC,aAAa;IAAAA,eAAA,qCACG,CAAC;IAK1B,IAAI,CAACC,iBAAiB,GAAGF,IAAI,CAACG,gBAAgB;IAC9C,IAAI,CAACC,SAAS,GAAGJ,IAAI,CAACK,QAAQ;IAE9B,IAAI,CAACC,eAAe,GAAG,CAAC;IACxB,IAAI,CAACC,MAAM,GAAGP,IAAI,CAACQ,KAAK;IACxB,IAAI,CAACC,GAAG,GAAGT,IAAI,CAACU,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,GAAGV,IAAI,CAACU,EAAE,CAAC,CAAC;IAC5C,IAAI,CAACC,QAAQ,GAAGC,OAAO,CAACZ,IAAI,CAACa,OAAO,CAAC;IACrC,IAAI,CAACC,kBAAkB,GAAGd,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C,OAAO,EAAE;QAAK,CAAC,CAAC,CAAC;MACvF;IACJ,CAAC,CAAC;EACN;AACJ;;AAEA;AACA;AACA;AACA,MAAMK,KAAK,GAAGlD,cAAc,CAACmD,SAAS;AAEtC1D,oBAAoB,CAACyD,KAAK,EAAE,mBAAmB,CAAC;AAChDzD,oBAAoB,CAACyD,KAAK,EAAE,OAAO,CAAC;AACpCzD,oBAAoB,CAACyD,KAAK,EAAE,SAAS,CAAC;AACtCzD,oBAAoB,CAACyD,KAAK,EAAE,OAAO,CAAC;AACpCzD,oBAAoB,CAACyD,KAAK,EAAE,SAAS,CAAC;AACtCzD,oBAAoB,CAACyD,KAAK,EAAE,MAAM,CAAC"} \ No newline at end of file diff --git a/lib/module/RTCDataChannelEvent.js b/lib/module/RTCDataChannelEvent.js new file mode 100644 index 000000000..ed9090f79 --- /dev/null +++ b/lib/module/RTCDataChannelEvent.js @@ -0,0 +1,19 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import { Event } from 'event-target-shim/index'; +/** + * @eventClass + * This event is fired whenever the RTCDataChannel has changed in any way. + * @param {DATA_CHANNEL_EVENTS} type - The type of event. + * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel#events MDN} for details. + */ +export default class RTCDataChannelEvent extends Event { + /** @eventProperty */ + + constructor(type, eventInitDict) { + super(type, eventInitDict); + _defineProperty(this, "channel", void 0); + this.channel = eventInitDict.channel; + } +} +//# sourceMappingURL=RTCDataChannelEvent.js.map \ No newline at end of file diff --git a/lib/module/RTCDataChannelEvent.js.map b/lib/module/RTCDataChannelEvent.js.map new file mode 100644 index 000000000..e6980bde4 --- /dev/null +++ b/lib/module/RTCDataChannelEvent.js.map @@ -0,0 +1 @@ +{"version":3,"names":["Event","RTCDataChannelEvent","constructor","type","eventInitDict","_defineProperty","channel"],"sources":["RTCDataChannelEvent.ts"],"sourcesContent":["import { Event } from 'event-target-shim/index';\n\nimport type RTCDataChannel from './RTCDataChannel';\n\ntype DATA_CHANNEL_EVENTS = 'open'| 'message'| 'bufferedamountlow'| 'closing'| 'close'| 'error' | 'datachannel';\n\ninterface IRTCDataChannelEventInitDict extends Event.EventInit {\n channel: RTCDataChannel;\n}\n\n\n/**\n * @eventClass\n * This event is fired whenever the RTCDataChannel has changed in any way.\n * @param {DATA_CHANNEL_EVENTS} type - The type of event.\n * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel#events MDN} for details.\n */\nexport default class RTCDataChannelEvent<\nTEventType extends DATA_CHANNEL_EVENTS\n> extends Event {\n /** @eventProperty */\n channel: RTCDataChannel;\n constructor(type: TEventType, eventInitDict: IRTCDataChannelEventInitDict) {\n super(type, eventInitDict);\n this.channel = eventInitDict.channel;\n }\n}\n"],"mappings":";AAAA,SAASA,KAAK,QAAQ,yBAAyB;AAW/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,mBAAmB,SAE9BD,KAAK,CAAa;EACxB;;EAEAE,WAAWA,CAACC,IAAgB,EAAEC,aAA2C,EAAE;IACvE,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAACC,eAAA;IAC3B,IAAI,CAACC,OAAO,GAAGF,aAAa,CAACE,OAAO;EACxC;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCErrorEvent.js b/lib/module/RTCErrorEvent.js new file mode 100644 index 000000000..e8fd7f747 --- /dev/null +++ b/lib/module/RTCErrorEvent.js @@ -0,0 +1,16 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import { Event } from 'event-target-shim/index'; +/** + * @brief This class Represents internal error happening on the native side as + * part of asynchronous invocations to synchronous web APIs. + */ +export default class RTCErrorEvent extends Event { + constructor(type, func, message) { + super(type); + _defineProperty(this, "func", void 0); + _defineProperty(this, "message", void 0); + this.func = func; + this.message = message; + } +} +//# sourceMappingURL=RTCErrorEvent.js.map \ No newline at end of file diff --git a/lib/module/RTCErrorEvent.js.map b/lib/module/RTCErrorEvent.js.map new file mode 100644 index 000000000..336542af6 --- /dev/null +++ b/lib/module/RTCErrorEvent.js.map @@ -0,0 +1 @@ +{"version":3,"names":["Event","RTCErrorEvent","constructor","type","func","message","_defineProperty"],"sources":["RTCErrorEvent.ts"],"sourcesContent":["import { Event } from 'event-target-shim/index';\n\ntype RTCPeerConnectionErrorFunc =\n | 'addTransceiver'\n | 'getTransceivers'\n | 'addTrack'\n | 'removeTrack';\n\n/**\n * @brief This class Represents internal error happening on the native side as\n * part of asynchronous invocations to synchronous web APIs.\n */\nexport default class RTCErrorEvent extends Event {\n readonly func: RTCPeerConnectionErrorFunc;\n readonly message: string;\n constructor(type: TEventType, func: RTCPeerConnectionErrorFunc, message: string) {\n super(type);\n this.func = func;\n this.message = message;\n }\n}"],"mappings":";AAAA,SAASA,KAAK,QAAQ,yBAAyB;AAQ/C;AACA;AACA;AACA;AACA,eAAe,MAAMC,aAAa,SAAwDD,KAAK,CAAa;EAGxGE,WAAWA,CAACC,IAAgB,EAAEC,IAAgC,EAAEC,OAAe,EAAE;IAC7E,KAAK,CAACF,IAAI,CAAC;IAACG,eAAA;IAAAA,eAAA;IACZ,IAAI,CAACF,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,OAAO,GAAGA,OAAO;EAC1B;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCFrameCryptor.js b/lib/module/RTCFrameCryptor.js new file mode 100644 index 000000000..ae95c18e5 --- /dev/null +++ b/lib/module/RTCFrameCryptor.js @@ -0,0 +1,128 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import { Event, EventTarget, defineEventAttribute } from 'event-target-shim/index'; +import { NativeModules } from 'react-native'; +import { addListener, removeListener } from './EventEmitter'; +import Logger from './Logger'; +const { + WebRTCModule +} = NativeModules; +const log = new Logger('pc'); +/** + * @eventClass + * This event is fired whenever the RTCDataChannel has changed in any way. + * @param {FRAME_CRYPTOR_EVENTS} type - The type of event. + * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel#events MDN} for details. + */ +export class RTCFrameCryptorStateEvent extends Event { + /** @eventProperty */ + + /** @eventProperty */ + + constructor(type, eventInitDict) { + super(type, eventInitDict); + _defineProperty(this, "frameCryptor", void 0); + _defineProperty(this, "state", void 0); + this.frameCryptor = eventInitDict.frameCryptor; + this.state = eventInitDict.state; + } +} +export let RTCFrameCryptorState; +(function (RTCFrameCryptorState) { + RTCFrameCryptorState[RTCFrameCryptorState["FrameCryptorStateNew"] = 0] = "FrameCryptorStateNew"; + RTCFrameCryptorState[RTCFrameCryptorState["FrameCryptorStateOk"] = 1] = "FrameCryptorStateOk"; + RTCFrameCryptorState[RTCFrameCryptorState["FrameCryptorStateEncryptionFailed"] = 2] = "FrameCryptorStateEncryptionFailed"; + RTCFrameCryptorState[RTCFrameCryptorState["FrameCryptorStateDecryptionFailed"] = 3] = "FrameCryptorStateDecryptionFailed"; + RTCFrameCryptorState[RTCFrameCryptorState["FrameCryptorStateMissingKey"] = 4] = "FrameCryptorStateMissingKey"; + RTCFrameCryptorState[RTCFrameCryptorState["FrameCryptorStateKeyRatcheted"] = 5] = "FrameCryptorStateKeyRatcheted"; + RTCFrameCryptorState[RTCFrameCryptorState["FrameCryptorStateInternalError"] = 6] = "FrameCryptorStateInternalError"; +})(RTCFrameCryptorState || (RTCFrameCryptorState = {})); +export default class RTCFrameCryptor extends EventTarget { + constructor(frameCryptorId, participantId) { + super(); + _defineProperty(this, "_frameCryptorId", void 0); + _defineProperty(this, "_participantId", void 0); + this._frameCryptorId = frameCryptorId; + this._participantId = participantId; + this._registerEvents(); + } + get id() { + return this._frameCryptorId; + } + get participantId() { + return this._participantId; + } + _cryptorStateFromString(str) { + switch (str) { + case 'new': + return RTCFrameCryptorState.FrameCryptorStateNew; + case 'ok': + return RTCFrameCryptorState.FrameCryptorStateOk; + case 'decryptionFailed': + return RTCFrameCryptorState.FrameCryptorStateDecryptionFailed; + case 'encryptionFailed': + return RTCFrameCryptorState.FrameCryptorStateEncryptionFailed; + case 'internalError': + return RTCFrameCryptorState.FrameCryptorStateInternalError; + case 'keyRatcheted': + return RTCFrameCryptorState.FrameCryptorStateKeyRatcheted; + case 'missingKey': + return RTCFrameCryptorState.FrameCryptorStateMissingKey; + default: + throw 'Unknown FrameCryptorState: $str'; + } + } + async setKeyIndex(keyIndex) { + const params = { + frameCryptorId: this._frameCryptorId, + keyIndex + }; + return WebRTCModule.frameCryptorSetKeyIndex(params).then(data => data['result']); + } + async getKeyIndex() { + const params = { + frameCryptorId: this._frameCryptorId + }; + return WebRTCModule.frameCryptorGetKeyIndex(params).then(data => data['keyIndex']); + } + async setEnabled(enabled) { + const params = { + frameCryptorId: this._frameCryptorId, + enabled + }; + return WebRTCModule.frameCryptorSetEnabled(params).then(data => data['result']); + } + async getEnabled() { + const params = { + frameCryptorId: this._frameCryptorId + }; + return WebRTCModule.frameCryptorGetEnabled(params).then(data => data['enabled']); + } + async dispose() { + const params = { + frameCryptorId: this._frameCryptorId + }; + await WebRTCModule.frameCryptorDispose(params); + removeListener(this); + } + _registerEvents() { + addListener(this, 'frameCryptionStateChanged', ev => { + if (ev.participantId !== this._participantId || ev.frameCryptorId !== this._frameCryptorId) { + return; + } + log.debug(`${this.id} frameCryptionStateChanged ${ev.state}`); + const initDict = { + frameCryptor: this, + state: ev.state + }; + this.dispatchEvent(new RTCFrameCryptorStateEvent('onframecryptorstatechanged', initDict)); + }); + } +} + +/** + * Define the `onxxx` event handlers. + */ +const proto = RTCFrameCryptor.prototype; +defineEventAttribute(proto, 'onframecryptorstatechanged'); +//# sourceMappingURL=RTCFrameCryptor.js.map \ No newline at end of file diff --git a/lib/module/RTCFrameCryptor.js.map b/lib/module/RTCFrameCryptor.js.map new file mode 100644 index 000000000..8acdcd479 --- /dev/null +++ b/lib/module/RTCFrameCryptor.js.map @@ -0,0 +1 @@ +{"version":3,"names":["Event","EventTarget","defineEventAttribute","NativeModules","addListener","removeListener","Logger","WebRTCModule","log","RTCFrameCryptorStateEvent","constructor","type","eventInitDict","_defineProperty","frameCryptor","state","RTCFrameCryptorState","RTCFrameCryptor","frameCryptorId","participantId","_frameCryptorId","_participantId","_registerEvents","id","_cryptorStateFromString","str","FrameCryptorStateNew","FrameCryptorStateOk","FrameCryptorStateDecryptionFailed","FrameCryptorStateEncryptionFailed","FrameCryptorStateInternalError","FrameCryptorStateKeyRatcheted","FrameCryptorStateMissingKey","setKeyIndex","keyIndex","params","frameCryptorSetKeyIndex","then","data","getKeyIndex","frameCryptorGetKeyIndex","setEnabled","enabled","frameCryptorSetEnabled","getEnabled","frameCryptorGetEnabled","dispose","frameCryptorDispose","ev","debug","initDict","dispatchEvent","proto","prototype"],"sources":["RTCFrameCryptor.ts"],"sourcesContent":["import { Event, EventTarget, defineEventAttribute } from 'event-target-shim/index';\nimport { NativeModules } from 'react-native';\n\nimport { addListener, removeListener } from './EventEmitter';\nimport Logger from './Logger';\nconst { WebRTCModule } = NativeModules;\n\nconst log = new Logger('pc');\n\ntype FRAME_CRYPTOR_EVENTS = 'onframecryptorstatechanged';\n\ninterface IRTCDataChannelEventInitDict extends Event.EventInit {\n frameCryptor: RTCFrameCryptor;\n state: RTCFrameCryptorState;\n}\n\n/**\n * @eventClass\n * This event is fired whenever the RTCDataChannel has changed in any way.\n * @param {FRAME_CRYPTOR_EVENTS} type - The type of event.\n * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel#events MDN} for details.\n */\nexport class RTCFrameCryptorStateEvent<\nTEventType extends FRAME_CRYPTOR_EVENTS\n> extends Event {\n /** @eventProperty */\n frameCryptor: RTCFrameCryptor;\n /** @eventProperty */\n state: RTCFrameCryptorState;\n constructor(type: TEventType, eventInitDict: IRTCDataChannelEventInitDict) {\n super(type, eventInitDict);\n this.frameCryptor = eventInitDict.frameCryptor;\n this.state = eventInitDict.state;\n }\n}\n\ntype RTCFrameCryptorEventMap = {\n onframecryptorstatechanged: RTCFrameCryptorStateEvent<'onframecryptorstatechanged'>;\n}\n\nexport enum RTCFrameCryptorState {\n FrameCryptorStateNew,\n FrameCryptorStateOk,\n FrameCryptorStateEncryptionFailed,\n FrameCryptorStateDecryptionFailed,\n FrameCryptorStateMissingKey,\n FrameCryptorStateKeyRatcheted,\n FrameCryptorStateInternalError,\n}\n\nexport default class RTCFrameCryptor extends EventTarget {\n private _frameCryptorId: string;\n private _participantId: string;\n\n constructor(frameCryptorId: string, participantId: string) {\n super();\n this._frameCryptorId = frameCryptorId;\n this._participantId = participantId;\n this._registerEvents();\n }\n\n get id() {\n return this._frameCryptorId;\n }\n\n get participantId() {\n return this._participantId;\n }\n\n _cryptorStateFromString(str: string): RTCFrameCryptorState {\n switch (str) {\n case 'new':\n return RTCFrameCryptorState.FrameCryptorStateNew;\n case 'ok':\n return RTCFrameCryptorState.FrameCryptorStateOk;\n case 'decryptionFailed':\n return RTCFrameCryptorState.FrameCryptorStateDecryptionFailed;\n case 'encryptionFailed':\n return RTCFrameCryptorState.FrameCryptorStateEncryptionFailed;\n case 'internalError':\n return RTCFrameCryptorState.FrameCryptorStateInternalError;\n case 'keyRatcheted':\n return RTCFrameCryptorState.FrameCryptorStateKeyRatcheted;\n case 'missingKey':\n return RTCFrameCryptorState.FrameCryptorStateMissingKey;\n default:\n throw 'Unknown FrameCryptorState: $str';\n }\n }\n\n async setKeyIndex(keyIndex: number): Promise {\n const params = {\n frameCryptorId: this._frameCryptorId,\n keyIndex,\n };\n\n return WebRTCModule.frameCryptorSetKeyIndex(params)\n .then(data => data['result']);\n }\n\n async getKeyIndex(): Promise {\n const params = {\n frameCryptorId: this._frameCryptorId,\n };\n\n return WebRTCModule.frameCryptorGetKeyIndex(params)\n .then(data => data['keyIndex']);\n }\n\n async setEnabled(enabled: boolean): Promise {\n const params = {\n frameCryptorId: this._frameCryptorId,\n enabled,\n };\n\n return WebRTCModule.frameCryptorSetEnabled(params)\n .then(data => data['result']);\n }\n\n async getEnabled(): Promise {\n const params = {\n frameCryptorId: this._frameCryptorId,\n };\n\n return WebRTCModule.frameCryptorGetEnabled(params)\n .then(data => data['enabled']);\n }\n\n async dispose(): Promise {\n const params = {\n frameCryptorId: this._frameCryptorId,\n };\n\n await WebRTCModule.frameCryptorDispose(params);\n removeListener(this);\n }\n\n\n _registerEvents(): void {\n addListener(this, 'frameCryptionStateChanged', (ev: any) => {\n if (ev.participantId !== this._participantId || ev.frameCryptorId !== this._frameCryptorId) {\n return;\n }\n\n log.debug(`${this.id} frameCryptionStateChanged ${ev.state}`);\n\n const initDict = {\n frameCryptor: this,\n state: ev.state,\n };\n\n this.dispatchEvent(new RTCFrameCryptorStateEvent('onframecryptorstatechanged', initDict));\n });\n }\n}\n\n/**\n * Define the `onxxx` event handlers.\n */\nconst proto = RTCFrameCryptor.prototype;\n\ndefineEventAttribute(proto, 'onframecryptorstatechanged');"],"mappings":";AAAA,SAASA,KAAK,EAAEC,WAAW,EAAEC,oBAAoB,QAAQ,yBAAyB;AAClF,SAASC,aAAa,QAAQ,cAAc;AAE5C,SAASC,WAAW,EAAEC,cAAc,QAAQ,gBAAgB;AAC5D,OAAOC,MAAM,MAAM,UAAU;AAC7B,MAAM;EAAEC;AAAa,CAAC,GAAGJ,aAAa;AAEtC,MAAMK,GAAG,GAAG,IAAIF,MAAM,CAAC,IAAI,CAAC;AAS5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,yBAAyB,SAE5BT,KAAK,CAAa;EACxB;;EAEA;;EAEAU,WAAWA,CAACC,IAAgB,EAAEC,aAA2C,EAAE;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AC9C9B,cAAc,CAAC,IAAI,CAAC;EACxB;EAGAiB,eAAeA,CAAA,EAAS;IACpBlB,WAAW,CAAC,IAAI,EAAE,2BAA2B,EAAG4C,EAAO,IAAK;MACxD,IAAIA,EAAE,CAAC7B,aAAa,KAAK,IAAI,CAACE,cAAc,IAAI2B,EAAE,CAAC9B,cAAc,KAAK,IAAI,CAACE,eAAe,EAAE;QACxF;MACJ;MAEAZ,GAAG,CAACyC,KAAK,CAAE,GAAE,IAAI,CAAC1B,EAAG,8BAA6ByB,EAAE,CAACjC,KAAM,EAAC,CAAC;MAE7D,MAAMmC,QAAQ,GAAG;QACbpC,YAAY,EAAE,IAAI;QAClBC,KAAK,EAAEiC,EAAE,CAACjC;MACd,CAAC;MAED,IAAI,CAACoC,aAAa,CAAC,IAAI1C,yBAAyB,CAAC,4BAA4B,EAAEyC,QAAQ,CAAC,CAAC;IAC7F,CAAC,CAAC;EACN;AACJ;;AAEA;AACA;AACA;AACA,MAAME,KAAK,GAAGnC,eAAe,CAACoC,SAAS;AAEvCnD,oBAAoB,CAACkD,KAAK,EAAE,4BAA4B,CAAC"} \ No newline at end of file diff --git a/lib/module/RTCFrameCryptorFactory.js b/lib/module/RTCFrameCryptorFactory.js new file mode 100644 index 000000000..5a1ff1245 --- /dev/null +++ b/lib/module/RTCFrameCryptorFactory.js @@ -0,0 +1,70 @@ +import * as base64 from 'base64-js'; +import { NativeModules } from 'react-native'; +import RTCFrameCryptor from './RTCFrameCryptor'; +import RTCKeyProvider from './RTCKeyProvider'; +const { + WebRTCModule +} = NativeModules; +export let RTCFrameCryptorAlgorithm; // kAesCbc = 1, +(function (RTCFrameCryptorAlgorithm) { + RTCFrameCryptorAlgorithm[RTCFrameCryptorAlgorithm["kAesGcm"] = 0] = "kAesGcm"; +})(RTCFrameCryptorAlgorithm || (RTCFrameCryptorAlgorithm = {})); +export default class RTCFrameCryptorFactory { + static createFrameCryptorForRtpSender(participantId, sender, algorithm, keyProvider) { + const params = { + 'peerConnectionId': sender._peerConnectionId, + 'rtpSenderId': sender._id, + participantId, + 'keyProviderId': keyProvider._id, + 'type': 'sender', + 'algorithm': algorithm + }; + const result = WebRTCModule.frameCryptorFactoryCreateFrameCryptor(params); + if (!result) { + throw new Error('Error when creating frame cryptor for sender'); + } + return new RTCFrameCryptor(result, participantId); + } + static createFrameCryptorForRtpReceiver(participantId, receiver, algorithm, keyProvider) { + const params = { + 'peerConnectionId': receiver._peerConnectionId, + 'rtpReceiverId': receiver._id, + participantId, + 'keyProviderId': keyProvider._id, + 'type': 'receiver', + 'algorithm': algorithm + }; + const result = WebRTCModule.frameCryptorFactoryCreateFrameCryptor(params); + if (!result) { + throw new Error('Error when creating frame cryptor for receiver'); + } + return new RTCFrameCryptor(result, participantId); + } + static createDefaultKeyProvider(options) { + var _options$failureToler, _options$keyRingSize, _options$discardFrame; + const params = { + 'sharedKey': options.sharedKey, + 'ratchetWindowSize': options.ratchetWindowSize, + 'failureTolerance': (_options$failureToler = options.failureTolerance) !== null && _options$failureToler !== void 0 ? _options$failureToler : -1, + 'keyRingSize': (_options$keyRingSize = options.keyRingSize) !== null && _options$keyRingSize !== void 0 ? _options$keyRingSize : 16, + 'discardFrameWhenCryptorNotReady': (_options$discardFrame = options.discardFrameWhenCryptorNotReady) !== null && _options$discardFrame !== void 0 ? _options$discardFrame : false + }; + if (typeof options.ratchetSalt === 'string') { + params['ratchetSalt'] = options.ratchetSalt; + params['ratchetSaltIsBase64'] = false; + } else { + const bytes = options.ratchetSalt; + params['ratchetSalt'] = base64.fromByteArray(bytes); + params['ratchetSaltIsBase64'] = true; + } + if (options.uncryptedMagicBytes) { + params['uncryptedMagicBytes'] = base64.fromByteArray(options.uncryptedMagicBytes); + } + const result = WebRTCModule.frameCryptorFactoryCreateKeyProvider(params); + if (!result) { + throw new Error('Error when creating key provider!'); + } + return new RTCKeyProvider(result); + } +} +//# sourceMappingURL=RTCFrameCryptorFactory.js.map \ No newline at end of file diff --git a/lib/module/RTCFrameCryptorFactory.js.map b/lib/module/RTCFrameCryptorFactory.js.map new file mode 100644 index 000000000..c8b753ac2 --- /dev/null +++ b/lib/module/RTCFrameCryptorFactory.js.map @@ -0,0 +1 @@ +{"version":3,"names":["base64","NativeModules","RTCFrameCryptor","RTCKeyProvider","WebRTCModule","RTCFrameCryptorAlgorithm","RTCFrameCryptorFactory","createFrameCryptorForRtpSender","participantId","sender","algorithm","keyProvider","params","_peerConnectionId","_id","result","frameCryptorFactoryCreateFrameCryptor","Error","createFrameCryptorForRtpReceiver","receiver","createDefaultKeyProvider","options","_options$failureToler","_options$keyRingSize","_options$discardFrame","sharedKey","ratchetWindowSize","failureTolerance","keyRingSize","discardFrameWhenCryptorNotReady","ratchetSalt","bytes","fromByteArray","uncryptedMagicBytes","frameCryptorFactoryCreateKeyProvider"],"sources":["RTCFrameCryptorFactory.ts"],"sourcesContent":["import * as base64 from 'base64-js';\nimport { NativeModules } from 'react-native';\n\nimport RTCFrameCryptor from './RTCFrameCryptor';\nimport RTCKeyProvider from './RTCKeyProvider';\nimport RTCRtpReceiver from './RTCRtpReceiver';\nimport RTCRtpSender from './RTCRtpSender';\nconst { WebRTCModule } = NativeModules;\n\nexport enum RTCFrameCryptorAlgorithm {\n kAesGcm = 0,\n // kAesCbc = 1,\n}\n\nexport type RTCKeyProviderOptions = {\n sharedKey: boolean,\n ratchetSalt: string | Uint8Array,\n ratchetWindowSize: number,\n uncryptedMagicBytes?: Uint8Array,\n failureTolerance?: number,\n keyRingSize?: number,\n discardFrameWhenCryptorNotReady?: boolean\n}\n\nexport default class RTCFrameCryptorFactory {\n static createFrameCryptorForRtpSender(\n participantId: string,\n sender: RTCRtpSender,\n algorithm: RTCFrameCryptorAlgorithm,\n keyProvider: RTCKeyProvider\n ): RTCFrameCryptor {\n const params = {\n 'peerConnectionId': sender._peerConnectionId,\n 'rtpSenderId': sender._id,\n participantId,\n 'keyProviderId': keyProvider._id,\n 'type': 'sender',\n 'algorithm': algorithm\n };\n const result = WebRTCModule.frameCryptorFactoryCreateFrameCryptor(params);\n\n if (!result) {\n throw new Error('Error when creating frame cryptor for sender');\n }\n\n return new RTCFrameCryptor(result, participantId);\n }\n static createFrameCryptorForRtpReceiver(\n participantId: string,\n receiver: RTCRtpReceiver,\n algorithm: RTCFrameCryptorAlgorithm,\n keyProvider: RTCKeyProvider\n ): RTCFrameCryptor {\n const params = {\n 'peerConnectionId': receiver._peerConnectionId,\n 'rtpReceiverId': receiver._id,\n participantId,\n 'keyProviderId': keyProvider._id,\n 'type': 'receiver',\n 'algorithm': algorithm\n };\n const result = WebRTCModule.frameCryptorFactoryCreateFrameCryptor(params);\n\n if (!result) {\n throw new Error('Error when creating frame cryptor for receiver');\n }\n\n return new RTCFrameCryptor(result, participantId);\n }\n\n static createDefaultKeyProvider(options: RTCKeyProviderOptions): RTCKeyProvider {\n const params = {\n 'sharedKey': options.sharedKey,\n 'ratchetWindowSize': options.ratchetWindowSize,\n 'failureTolerance': options.failureTolerance ?? -1,\n 'keyRingSize': options.keyRingSize ?? 16,\n 'discardFrameWhenCryptorNotReady': options.discardFrameWhenCryptorNotReady ?? false\n };\n\n if (typeof options.ratchetSalt === 'string') {\n params['ratchetSalt'] = options.ratchetSalt;\n params['ratchetSaltIsBase64'] = false;\n } else {\n const bytes = options.ratchetSalt as Uint8Array;\n\n params['ratchetSalt'] = base64.fromByteArray(bytes);\n params['ratchetSaltIsBase64'] = true;\n }\n\n if (options.uncryptedMagicBytes) {\n params['uncryptedMagicBytes'] = base64.fromByteArray(options.uncryptedMagicBytes);\n }\n\n const result = WebRTCModule.frameCryptorFactoryCreateKeyProvider(params);\n\n if (!result) {\n throw new Error('Error when creating key provider!');\n }\n\n return new RTCKeyProvider(result);\n }\n}"],"mappings":"AAAA,OAAO,KAAKA,MAAM,MAAM,WAAW;AACnC,SAASC,aAAa,QAAQ,cAAc;AAE5C,OAAOC,eAAe,MAAM,mBAAmB;AAC/C,OAAOC,cAAc,MAAM,kBAAkB;AAG7C,MAAM;EAAEC;AAAa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644 index 000000000..36cad6df5 --- /dev/null +++ b/lib/module/RTCIceCandidate.js @@ -0,0 +1,27 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +export default class RTCIceCandidate { + constructor(_ref) { + let { + candidate = '', + sdpMLineIndex = null, + sdpMid = null + } = _ref; + _defineProperty(this, "candidate", void 0); + _defineProperty(this, "sdpMLineIndex", void 0); + _defineProperty(this, "sdpMid", void 0); + if (sdpMLineIndex === null && sdpMid === null) { + throw new TypeError('`sdpMLineIndex` and `sdpMid` must not be both null'); + } + this.candidate = candidate; + this.sdpMLineIndex = sdpMLineIndex; + this.sdpMid = sdpMid; + } + toJSON() { + return { + candidate: this.candidate, + sdpMLineIndex: this.sdpMLineIndex, + sdpMid: this.sdpMid + }; + } +} +//# sourceMappingURL=RTCIceCandidate.js.map \ No newline at end of file diff --git a/lib/module/RTCIceCandidate.js.map b/lib/module/RTCIceCandidate.js.map new file mode 100644 index 000000000..3aa816e4a --- /dev/null +++ b/lib/module/RTCIceCandidate.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCIceCandidate","constructor","_ref","candidate","sdpMLineIndex","sdpMid","_defineProperty","TypeError","toJSON"],"sources":["RTCIceCandidate.ts"],"sourcesContent":["interface RTCIceCandidateInfo {\n candidate?: string;\n sdpMLineIndex?: number | null;\n sdpMid?: string | null;\n}\n\nexport default class RTCIceCandidate {\n candidate: string;\n sdpMLineIndex?: number | null;\n sdpMid?: string | null;\n\n constructor({ candidate = '', sdpMLineIndex = null, sdpMid = null }: RTCIceCandidateInfo) {\n if (sdpMLineIndex === null && sdpMid === null) {\n throw new TypeError('`sdpMLineIndex` and `sdpMid` must not be both null');\n }\n\n this.candidate = candidate;\n this.sdpMLineIndex = sdpMLineIndex;\n this.sdpMid = sdpMid;\n }\n\n toJSON() {\n return {\n candidate: this.candidate,\n sdpMLineIndex: this.sdpMLineIndex,\n sdpMid: this.sdpMid\n };\n }\n}\n"],"mappings":";AAMA,eAAe,MAAMA,eAAe,CAAC;EAKjCC,WAAWA,CAAAC,IAAA,EAA+E;IAAA,IAA9E;MAAEC,SAAS,GAAG,EAAE;MAAEC,aAAa,GAAG,IAAI;MAAEC,MAAM,GAAG;IAA0B,CAAC,GAAAH,IAAA;IAAAI,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACpF,IAAIF,aAAa,KAAK,IAAI,IAAIC,MAAM,KAAK,IAAI,EAAE;MAC3C,MAAM,IAAIE,SAAS,CAAC,oDAAoD,CAAC;IAC7E;IAEA,IAAI,CAACJ,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,aAAa,GAAGA,aAAa;IAClC,IAAI,CAACC,MAAM,GAAGA,MAAM;EACxB;EAEAG,MAAMA,CAAA,EAAG;IACL,OAAO;MACHL,SAAS,EAAE,IAAI,CAACA,SAAS;MACzBC,aAAa,EAAE,IAAI,CAACA,aAAa;MACjCC,MAAM,EAAE,IAAI,CAACA;IACjB,CAAC;EACL;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCIceCandidateEvent.js b/lib/module/RTCIceCandidateEvent.js new file mode 100644 index 000000000..7c61d79a3 --- /dev/null +++ b/lib/module/RTCIceCandidateEvent.js @@ -0,0 +1,21 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import { Event } from 'event-target-shim/index'; +/** + * @eventClass + * This event is fired whenever the icecandidate related RTC_EVENTS changed. + * @type {RTCIceCandidateEvent} for icecandidate related. + * @param {RTC_ICECANDIDATE_EVENTS} type - The type of event. + * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection#events MDN} for details. + */ +export default class RTCIceCandidateEvent extends Event { + /** @eventProperty */ + + constructor(type, eventInitDict) { + var _eventInitDict$candid; + super(type, eventInitDict); + _defineProperty(this, "candidate", void 0); + this.candidate = (_eventInitDict$candid = eventInitDict === null || eventInitDict === void 0 ? void 0 : eventInitDict.candidate) !== null && _eventInitDict$candid !== void 0 ? _eventInitDict$candid : null; + } +} +//# sourceMappingURL=RTCIceCandidateEvent.js.map \ No newline at end of file diff --git a/lib/module/RTCIceCandidateEvent.js.map b/lib/module/RTCIceCandidateEvent.js.map new file mode 100644 index 000000000..cc779a870 --- /dev/null +++ b/lib/module/RTCIceCandidateEvent.js.map @@ -0,0 +1 @@ +{"version":3,"names":["Event","RTCIceCandidateEvent","constructor","type","eventInitDict","_eventInitDict$candid","_defineProperty","candidate"],"sources":["RTCIceCandidateEvent.ts"],"sourcesContent":["import { Event } from 'event-target-shim/index';\n\nimport type RTCIceCandidate from './RTCIceCandidate';\n\ntype RTC_ICECANDIDATE_EVENTS = 'icecandidate' | 'icecandidateerror'\n\ninterface IRTCDataChannelEventInitDict extends Event.EventInit {\n candidate: RTCIceCandidate | null\n}\n\n/**\n * @eventClass\n * This event is fired whenever the icecandidate related RTC_EVENTS changed.\n * @type {RTCIceCandidateEvent} for icecandidate related.\n * @param {RTC_ICECANDIDATE_EVENTS} type - The type of event.\n * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection#events MDN} for details.\n */\nexport default class RTCIceCandidateEvent extends Event {\n /** @eventProperty */\n candidate: RTCIceCandidate | null;\n constructor(type: TEventType, eventInitDict: IRTCDataChannelEventInitDict) {\n super(type, eventInitDict);\n this.candidate = eventInitDict?.candidate ?? null;\n }\n}\n"],"mappings":";AAAA,SAASA,KAAK,QAAQ,yBAAyB;AAU/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,oBAAoB,SAAqDD,KAAK,CAAa;EAC5G;;EAEAE,WAAWA,CAACC,IAAgB,EAAEC,aAA2C,EAAE;IAAA,IAAAC,qBAAA;IACvE,KAAK,CAACF,IAAI,EAAEC,aAAa,CAAC;IAACE,eAAA;IAC3B,IAAI,CAACC,SAAS,IAAAF,qBAAA,GAAGD,aAAa,aAAbA,aAAa,uBAAbA,aAAa,CAAEG,SAAS,cAAAF,qBAAA,cAAAA,qBAAA,GAAI,IAAI;EACrD;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCKeyProvider.js b/lib/module/RTCKeyProvider.js new file mode 100644 index 000000000..e938da10b --- /dev/null +++ b/lib/module/RTCKeyProvider.js @@ -0,0 +1,101 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import * as base64 from 'base64-js'; +import { NativeModules } from 'react-native'; +const { + WebRTCModule +} = NativeModules; +export let FrameCryptorState; +(function (FrameCryptorState) { + FrameCryptorState[FrameCryptorState["FrameCryptorStateNew"] = 0] = "FrameCryptorStateNew"; + FrameCryptorState[FrameCryptorState["FrameCryptorStateOk"] = 1] = "FrameCryptorStateOk"; + FrameCryptorState[FrameCryptorState["FrameCryptorStateEncryptionFailed"] = 2] = "FrameCryptorStateEncryptionFailed"; + FrameCryptorState[FrameCryptorState["FrameCryptorStateDecryptionFailed"] = 3] = "FrameCryptorStateDecryptionFailed"; + FrameCryptorState[FrameCryptorState["FrameCryptorStateMissingKey"] = 4] = "FrameCryptorStateMissingKey"; + FrameCryptorState[FrameCryptorState["FrameCryptorStateKeyRatcheted"] = 5] = "FrameCryptorStateKeyRatcheted"; + FrameCryptorState[FrameCryptorState["FrameCryptorStateInternalError"] = 6] = "FrameCryptorStateInternalError"; +})(FrameCryptorState || (FrameCryptorState = {})); +export default class RTCKeyProvider { + constructor(keyProviderId) { + _defineProperty(this, "_id", void 0); + this._id = keyProviderId; + } + async setSharedKey(key) { + let keyIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + const params = { + keyProviderId: this._id, + keyIndex + }; + if (typeof key === 'string') { + params['key'] = key; + params['keyIsBase64'] = false; + } else { + params['key'] = base64.fromByteArray(key); + params['keyIsBase64'] = true; + } + return WebRTCModule.keyProviderSetSharedKey(params).then(data => data['result']); + } + async ratchetSharedKey() { + let keyIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + const params = { + keyProviderId: this._id, + keyIndex + }; + return WebRTCModule.keyProviderRatchetSharedKey(params).then(data => base64.toByteArray(data['result'])); + } + async exportSharedKey() { + let keyIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + const params = { + keyProviderId: this._id, + keyIndex + }; + return WebRTCModule.keyProviderExportSharedKey(params).then(data => base64.toByteArray(data['result'])); + } + async setKey(participantId, key) { + let keyIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; + const params = { + keyProviderId: this._id, + participantId, + keyIndex + }; + if (typeof key === 'string') { + params['key'] = key; + params['keyIsBase64'] = false; + } else { + params['key'] = base64.fromByteArray(key); + params['keyIsBase64'] = true; + } + return WebRTCModule.keyProviderSetKey(params).then(data => data['result']); + } + async ratchetKey(participantId) { + let keyIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + const params = { + keyProviderId: this._id, + participantId, + keyIndex + }; + return WebRTCModule.keyProviderRatchetKey(params).then(data => base64.toByteArray(data['result'])); + } + async exportKey(participantId) { + let keyIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + const params = { + keyProviderId: this._id, + participantId, + keyIndex + }; + return WebRTCModule.keyProviderExportKey(params).then(data => base64.toByteArray(data['result'])); + } + async setSifTrailer(trailer) { + const params = { + keyProviderId: this._id, + 'sifTrailer': base64.fromByteArray(trailer) + }; + return WebRTCModule.keyProviderSetSifTrailer(params); + } + async dispose() { + const params = { + keyProviderId: this._id + }; + return WebRTCModule.keyProviderDispose(params); + } +} +//# sourceMappingURL=RTCKeyProvider.js.map \ No newline at end of file diff --git a/lib/module/RTCKeyProvider.js.map b/lib/module/RTCKeyProvider.js.map new file mode 100644 index 000000000..faeac04cb --- /dev/null +++ b/lib/module/RTCKeyProvider.js.map @@ -0,0 +1 @@ +{"version":3,"names":["base64","NativeModules","WebRTCModule","FrameCryptorState","RTCKeyProvider","constructor","keyProviderId","_defineProperty","_id","setSharedKey","key","keyIndex","arguments","length","undefined","params","fromByteArray","keyProviderSetSharedKey","then","data","ratchetSharedKey","keyProviderRatchetSharedKey","toByteArray","exportSharedKey","keyProviderExportSharedKey","setKey","participantId","keyProviderSetKey","ratchetKey","keyProviderRatchetKey","exportKey","keyProviderExportKey","setSifTrailer","trailer","keyProviderSetSifTrailer","dispose","keyProviderDispose"],"sources":["RTCKeyProvider.ts"],"sourcesContent":["import * as base64 from 'base64-js';\nimport { NativeModules } from 'react-native';\nconst { WebRTCModule } = NativeModules;\n\nexport enum FrameCryptorState {\n FrameCryptorStateNew,\n FrameCryptorStateOk,\n FrameCryptorStateEncryptionFailed,\n FrameCryptorStateDecryptionFailed,\n FrameCryptorStateMissingKey,\n FrameCryptorStateKeyRatcheted,\n FrameCryptorStateInternalError,\n}\n\nexport default class RTCKeyProvider {\n _id: string;\n\n constructor(keyProviderId: string) {\n this._id = keyProviderId;\n }\n\n async setSharedKey(key: string | Uint8Array, keyIndex = 0) {\n const params = {\n keyProviderId: this._id,\n keyIndex,\n };\n\n if (typeof key === 'string') {\n params['key'] = key;\n params['keyIsBase64'] = false;\n } else {\n params['key'] = base64.fromByteArray(key as Uint8Array);\n params['keyIsBase64'] = true;\n }\n\n return WebRTCModule.keyProviderSetSharedKey(params)\n .then(data => data['result']);\n }\n\n async ratchetSharedKey(keyIndex = 0): Promise {\n const params = {\n keyProviderId: this._id,\n keyIndex,\n };\n\n return WebRTCModule.keyProviderRatchetSharedKey(params)\n .then(data => base64.toByteArray(data['result']));\n }\n\n async exportSharedKey(keyIndex = 0): Promise {\n const params = {\n keyProviderId: this._id,\n keyIndex,\n };\n\n return WebRTCModule.keyProviderExportSharedKey(params)\n .then(data => base64.toByteArray(data['result']));\n }\n\n async setKey(participantId: string, key: string | Uint8Array, keyIndex = 0): Promise {\n const params = {\n keyProviderId: this._id,\n participantId,\n keyIndex,\n };\n\n if (typeof key === 'string') {\n params['key'] = key;\n params['keyIsBase64'] = false;\n } else {\n params['key'] = base64.fromByteArray(key as Uint8Array);\n params['keyIsBase64'] = true;\n }\n\n return WebRTCModule.keyProviderSetKey(params)\n .then(data => data['result']);\n }\n\n async ratchetKey(participantId: string, keyIndex = 0): Promise {\n const params = {\n keyProviderId: this._id,\n participantId,\n keyIndex,\n };\n\n return WebRTCModule.keyProviderRatchetKey(params)\n .then(data => base64.toByteArray(data['result']));\n }\n\n async exportKey(participantId: string, keyIndex = 0): Promise {\n const params = {\n keyProviderId: this._id,\n participantId,\n keyIndex,\n };\n\n return WebRTCModule.keyProviderExportKey(params)\n .then(data => base64.toByteArray(data['result']));\n }\n\n async setSifTrailer(trailer: Uint8Array) {\n const params = {\n keyProviderId: this._id,\n 'sifTrailer': base64.fromByteArray(trailer),\n };\n\n return WebRTCModule.keyProviderSetSifTrailer(params);\n }\n\n async dispose() {\n const params = {\n keyProviderId: this._id,\n };\n\n return WebRTCModule.keyProviderDispose(params);\n }\n}\n"],"mappings":";AAAA,OAAO,KAAKA,MAAM,MAAM,WAAW;AACnC,SAASC,aAAa,QAAQ,cAAc;AAC5C,MAAM;EAAEC;AAAa,CAAC,GAAGD,aAAa;AAEtC,WAAYE,iBAAiB;AAQ5B,WARWA,iBAAiB;EAAjBA,iBAAiB,CAAjBA,iBAAiB;EAAjBA,iBAAiB,CAAjBA,iBAAiB;EAAjBA,iBAAiB,CAAjBA,iBAAiB;EAAjBA,iBAAiB,CAAjBA,iBAAiB;EAAjBA,iBAAiB,CAAjBA,iBAAiB;EAAjBA,iBAAiB,CAAjBA,iBAAiB;EAAjBA,iBAAiB,CAAjBA,iBAAiB;AAAA,GAAjBA,iBAAiB,KAAjBA,iBAAiB;AAU7B,eAAe,MAAMC,cAAc,CAAC;EAGhCC,WAAWA,CAACC,aAAqB,EAAE;IAAAC,eAAA;IAC/B,IAAI,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AqC;IAAA,IAAnCf,QAAQ,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC;IAC/C,MAAMG,MAAM,GAAG;MACXT,aAAa,EAAE,IAAI,CAACE,GAAG;MACvBkB,aAAa;MACbf;IACJ,CAAC;IAED,OAAOT,YAAY,CAAC6B,oBAAoB,CAAChB,MAAM,CAAC,CAC3CG,IAAI,CAACC,IAAI,IAAInB,MAAM,CAACsB,WAAW,CAACH,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;EACzD;EAEA,MAAMa,aAAaA,CAACC,OAAmB,EAAE;IACrC,MAAMlB,MAAM,GAAG;MACXT,aAAa,EAAE,IAAI,CAACE,GAAG;MACvB,YAAY,EAAER,MAAM,CAACgB,aAAa,CAACiB,OAAO;IAC9C,CAAC;IAED,OAAO/B,YAAY,CAACgC,wBAAwB,CAACnB,MAAM,CAAC;EACxD;EAEA,MAAMoB,OAAOA,CAAA,EAAG;IACZ,MAAMpB,MAAM,GAAG;MACXT,aAAa,EAAE,IAAI,CAACE;IACxB,CAAC;IAED,OAAON,YAAY,CAACkC,kBAAkB,CAACrB,MAAM,CAAC;EAClD;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCPIPView.js b/lib/module/RTCPIPView.js new file mode 100644 index 000000000..9b05e78a7 --- /dev/null +++ b/lib/module/RTCPIPView.js @@ -0,0 +1,26 @@ +function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } +import { forwardRef } from 'react'; +import ReactNative, { UIManager } from 'react-native'; +import RTCView from './RTCView'; +/** + * A convenience wrapper around RTCView to handle the fallback view as a prop. + */ +const RTCPIPView = /*#__PURE__*/forwardRef((props, ref) => { + var _rtcViewProps$iosPIP, _rtcViewProps$iosPIP2; + const rtcViewProps = { + ...props + }; + const fallbackView = (_rtcViewProps$iosPIP = rtcViewProps.iosPIP) === null || _rtcViewProps$iosPIP === void 0 ? void 0 : _rtcViewProps$iosPIP.fallbackView; + (_rtcViewProps$iosPIP2 = rtcViewProps.iosPIP) === null || _rtcViewProps$iosPIP2 === void 0 ? true : delete _rtcViewProps$iosPIP2.fallbackView; + return /*#__PURE__*/React.createElement(RTCView, _extends({ + ref: ref + }, rtcViewProps), fallbackView); +}); +export function startIOSPIP(ref) { + UIManager.dispatchViewManagerCommand(ReactNative.findNodeHandle(ref.current), UIManager.getViewManagerConfig('RTCVideoView').Commands.startIOSPIP, []); +} +export function stopIOSPIP(ref) { + UIManager.dispatchViewManagerCommand(ReactNative.findNodeHandle(ref.current), UIManager.getViewManagerConfig('RTCVideoView').Commands.stopIOSPIP, []); +} +export default RTCPIPView; +//# sourceMappingURL=RTCPIPView.js.map \ No newline at end of file diff --git a/lib/module/RTCPIPView.js.map b/lib/module/RTCPIPView.js.map new file mode 100644 index 000000000..005301454 --- /dev/null +++ b/lib/module/RTCPIPView.js.map @@ -0,0 +1 @@ +{"version":3,"names":["forwardRef","ReactNative","UIManager","RTCView","RTCPIPView","props","ref","_rtcViewProps$iosPIP","_rtcViewProps$iosPIP2","rtcViewProps","fallbackView","iosPIP","React","createElement","_extends","startIOSPIP","dispatchViewManagerCommand","findNodeHandle","current","getViewManagerConfig","Commands","stopIOSPIP"],"sources":["RTCPIPView.tsx"],"sourcesContent":["import { Component, forwardRef } from 'react';\nimport ReactNative, { UIManager } from 'react-native';\n\nimport RTCView, { RTCIOSPIPOptions, RTCVideoViewProps } from './RTCView';\n\nexport interface RTCPIPViewProps extends RTCVideoViewProps {\n iosPIP?: RTCIOSPIPOptions & {\n fallbackView?: Component;\n };\n}\n\ntype RTCViewInstance = InstanceType;\n\n/**\n * A convenience wrapper around RTCView to handle the fallback view as a prop.\n */\nconst RTCPIPView = forwardRef((props, ref) => {\n const rtcViewProps = { ...props };\n const fallbackView = rtcViewProps.iosPIP?.fallbackView;\n\n delete rtcViewProps.iosPIP?.fallbackView;\n\n return (\n \n {fallbackView}\n \n );\n});\n\nexport function startIOSPIP(ref) {\n UIManager.dispatchViewManagerCommand(\n ReactNative.findNodeHandle(ref.current),\n UIManager.getViewManagerConfig('RTCVideoView').Commands.startIOSPIP,\n []\n );\n}\n\nexport function stopIOSPIP(ref) {\n UIManager.dispatchViewManagerCommand(\n ReactNative.findNodeHandle(ref.current),\n UIManager.getViewManagerConfig('RTCVideoView').Commands.stopIOSPIP,\n []\n );\n}\n\nexport default RTCPIPView;"],"mappings":";AAAA,SAAoBA,UAAU,QAAQ,OAAO;AAC7C,OAAOC,WAAW,IAAIC,SAAS,QAAQ,cAAc;AAErD,OAAOC,OAAO,MAA+C,WAAW;AAUxE;AACA;AACA;AACA,MAAMC,UAAU,gBAAGJ,UAAU,CAAmC,CAACK,KAAK,EAAEC,GAAG,KAAK;EAAA,IAAAC,oBAAA,EAAAC,qBAAA;EAC5E,MAAMC,YAAY,GAAG;IAAE,GAAGJ;EAAM,CAAC;EACjC,MAAMK,YAAY,IAAAH,oBAAA,GAAGE,YAAY,CAACE,MAAM,cAAAJ,oBAAA,uBAAnBA,oBAAA,CAAqBG,YAAY;EAEtD,CAAAF,qBAAA,GAAOC,YAAY,CAACE,MAAM,cAAAH,qBAAA,qBAA1B,OAAOA,qBAAA,CAAqBE,YAAY;EAExC,oBACIE,KAAA,CAAAC,aAAA,CAACV,OAAO,EAAAW,QAAA;IAACR,GAAG,EAAEA;EAAI,GACVG,YAAY,GACfC,YACI,CAAC;AAElB,CAAC,CAAC;AAEF,OAAO,SAASK,WAAWA,CAACT,GAAG,EAAE;EAC7BJ,SAAS,CAACc,0BAA0B,CAChCf,WAAW,CAACgB,cAAc,CAACX,GAAG,CAACY,OAAO,CAAC,EACvChB,SAAS,CAACiB,oBAAoB,CAAC,cAAc,CAAC,CAACC,QAAQ,CAACL,WAAW,EACnE,EACJ,CAAC;AACL;AAEA,OAAO,SAASM,UAAUA,CAACf,GAAG,EAAE;EAC5BJ,SAAS,CAACc,0BAA0B,CAChCf,WAAW,CAACgB,cAAc,CAACX,GAAG,CAACY,OAAO,CAAC,EACvChB,SAAS,CAACiB,oBAAoB,CAAC,cAAc,CAAC,CAACC,QAAQ,CAACC,UAAU,EAClE,EACJ,CAAC;AACL;AAEA,eAAejB,UAAU"} \ No newline at end of file diff --git a/lib/module/RTCPeerConnection.js b/lib/module/RTCPeerConnection.js new file mode 100644 index 000000000..5d6d1c86c --- /dev/null +++ b/lib/module/RTCPeerConnection.js @@ -0,0 +1,684 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import { EventTarget, Event, defineEventAttribute } from 'event-target-shim/index'; +import { NativeModules } from 'react-native'; +import { addListener, removeListener } from './EventEmitter'; +import Logger from './Logger'; +import MediaStream from './MediaStream'; +import MediaStreamTrack from './MediaStreamTrack'; +import MediaStreamTrackEvent from './MediaStreamTrackEvent'; +import RTCDataChannel from './RTCDataChannel'; +import RTCDataChannelEvent from './RTCDataChannelEvent'; +import RTCIceCandidate from './RTCIceCandidate'; +import RTCIceCandidateEvent from './RTCIceCandidateEvent'; +import RTCRtpReceiveParameters from './RTCRtpReceiveParameters'; +import RTCRtpReceiver from './RTCRtpReceiver'; +import RTCRtpSendParameters from './RTCRtpSendParameters'; +import RTCRtpSender from './RTCRtpSender'; +import RTCRtpTransceiver from './RTCRtpTransceiver'; +import RTCSessionDescription from './RTCSessionDescription'; +import RTCTrackEvent from './RTCTrackEvent'; +import * as RTCUtil from './RTCUtil'; +const log = new Logger('pc'); +const { + WebRTCModule +} = NativeModules; +let nextPeerConnectionId = 0; +export default class RTCPeerConnection extends EventTarget { + constructor(configuration) { + super(); + _defineProperty(this, "localDescription", null); + _defineProperty(this, "remoteDescription", null); + _defineProperty(this, "signalingState", 'stable'); + _defineProperty(this, "iceGatheringState", 'new'); + _defineProperty(this, "connectionState", 'new'); + _defineProperty(this, "iceConnectionState", 'new'); + _defineProperty(this, "_pcId", void 0); + _defineProperty(this, "_transceivers", void 0); + _defineProperty(this, "_remoteStreams", void 0); + _defineProperty(this, "_pendingTrackEvents", void 0); + this._pcId = nextPeerConnectionId++; + + // Sanitize ICE servers. + if (configuration) { + var _configuration$iceSer; + const servers = (_configuration$iceSer = configuration === null || configuration === void 0 ? void 0 : configuration.iceServers) !== null && _configuration$iceSer !== void 0 ? _configuration$iceSer : []; + for (const server of servers) { + let urls = server.url || server.urls; + delete server.url; + delete server.urls; + if (!urls) { + continue; + } + if (!Array.isArray(urls)) { + urls = [urls]; + } + + // Native WebRTC does case sensitive parsing. + server.urls = urls.map(url => url.toLowerCase()); + } + + // Filter out bogus servers. + configuration.iceServers = servers.filter(s => s.urls); + } + if (!WebRTCModule.peerConnectionInit(configuration, this._pcId)) { + throw new Error('Failed to initialize PeerConnection, check the native logs!'); + } + this._transceivers = []; + this._remoteStreams = new Map(); + this._pendingTrackEvents = []; + this._registerEvents(); + log.debug(`${this._pcId} ctor`); + } + async createOffer(options) { + log.debug(`${this._pcId} createOffer`); + const { + sdpInfo, + newTransceivers, + transceiversInfo + } = await WebRTCModule.peerConnectionCreateOffer(this._pcId, RTCUtil.normalizeOfferOptions(options)); + log.debug(`${this._pcId} createOffer OK`); + newTransceivers === null || newTransceivers === void 0 ? void 0 : newTransceivers.forEach(t => { + const { + transceiverOrder, + transceiver + } = t; + const newSender = new RTCRtpSender({ + ...transceiver.sender, + track: null + }); + const remoteTrack = transceiver.receiver.track ? new MediaStreamTrack(transceiver.receiver.track) : null; + const newReceiver = new RTCRtpReceiver({ + ...transceiver.receiver, + track: remoteTrack + }); + const newTransceiver = new RTCRtpTransceiver({ + ...transceiver, + sender: newSender, + receiver: newReceiver + }); + this._insertTransceiverSorted(transceiverOrder, newTransceiver); + }); + this._updateTransceivers(transceiversInfo); + return sdpInfo; + } + async createAnswer() { + log.debug(`${this._pcId} createAnswer`); + const { + sdpInfo, + transceiversInfo + } = await WebRTCModule.peerConnectionCreateAnswer(this._pcId, {}); + this._updateTransceivers(transceiversInfo); + return sdpInfo; + } + setConfiguration(configuration) { + WebRTCModule.peerConnectionSetConfiguration(configuration, this._pcId); + } + async setLocalDescription(sessionDescription) { + var _desc; + log.debug(`${this._pcId} setLocalDescription`); + let desc; + if (sessionDescription) { + var _sessionDescription$s; + desc = { + type: sessionDescription.type, + sdp: (_sessionDescription$s = sessionDescription.sdp) !== null && _sessionDescription$s !== void 0 ? _sessionDescription$s : '' + }; + if (!RTCUtil.isSdpTypeValid(desc.type)) { + throw new Error(`Invalid session description: invalid type: ${desc.type}`); + } + } else { + desc = null; + } + const { + sdpInfo, + transceiversInfo + } = await WebRTCModule.peerConnectionSetLocalDescription(this._pcId, desc); + if (sdpInfo.type && sdpInfo.sdp) { + this.localDescription = new RTCSessionDescription(sdpInfo); + } else { + this.localDescription = null; + } + this._updateTransceivers(transceiversInfo, /* removeStopped */((_desc = desc) === null || _desc === void 0 ? void 0 : _desc.type) === 'answer'); + log.debug(`${this._pcId} setLocalDescription OK`); + } + async setRemoteDescription(sessionDescription) { + var _sessionDescription$s2, _desc$type; + log.debug(`${this._pcId} setRemoteDescription`); + if (!sessionDescription) { + return Promise.reject(new Error('No session description provided')); + } + const desc = { + type: sessionDescription.type, + sdp: (_sessionDescription$s2 = sessionDescription.sdp) !== null && _sessionDescription$s2 !== void 0 ? _sessionDescription$s2 : '' + }; + if (!RTCUtil.isSdpTypeValid((_desc$type = desc.type) !== null && _desc$type !== void 0 ? _desc$type : '')) { + throw new Error(`Invalid session description: invalid type: ${desc.type}`); + } + const { + sdpInfo, + newTransceivers, + transceiversInfo + } = await WebRTCModule.peerConnectionSetRemoteDescription(this._pcId, desc); + if (sdpInfo.type && sdpInfo.sdp) { + this.remoteDescription = new RTCSessionDescription(sdpInfo); + } else { + this.remoteDescription = null; + } + newTransceivers === null || newTransceivers === void 0 ? void 0 : newTransceivers.forEach(t => { + const { + transceiverOrder, + transceiver + } = t; + const newSender = new RTCRtpSender({ + ...transceiver.sender, + track: null + }); + const remoteTrack = transceiver.receiver.track ? new MediaStreamTrack(transceiver.receiver.track) : null; + const newReceiver = new RTCRtpReceiver({ + ...transceiver.receiver, + track: remoteTrack + }); + const newTransceiver = new RTCRtpTransceiver({ + ...transceiver, + sender: newSender, + receiver: newReceiver + }); + this._insertTransceiverSorted(transceiverOrder, newTransceiver); + }); + this._updateTransceivers(transceiversInfo, /* removeStopped */desc.type === 'answer'); + + // Fire track events. They must fire before sRD resolves. + const pendingTrackEvents = this._pendingTrackEvents; + this._pendingTrackEvents = []; + for (const ev of pendingTrackEvents) { + const [transceiver] = this.getTransceivers().filter(t => t.receiver.id === ev.receiver.id); + + // We need to fire this event for an existing track sometimes, like + // when the transceiver direction (on the sending side) switches from + // sendrecv to recvonly and then back. + + // @ts-ignore + const track = transceiver.receiver.track; + transceiver._mid = ev.transceiver.mid; + transceiver._currentDirection = ev.transceiver.currentDirection; + transceiver._direction = ev.transceiver.direction; + + // Get the stream object from the event. Create if necessary. + const streams = ev.streams.map(streamInfo => { + // Here we are making sure that we don't create stream objects that already exist + // So that event listeners do get the same object if it has been created before. + if (!this._remoteStreams.has(streamInfo.streamId)) { + const stream = new MediaStream({ + streamId: streamInfo.streamId, + streamReactTag: streamInfo.streamReactTag, + tracks: [] + }); + this._remoteStreams.set(streamInfo.streamId, stream); + } + const stream = this._remoteStreams.get(streamInfo.streamId); + if (!(stream !== null && stream !== void 0 && stream._tracks.includes(track))) { + stream === null || stream === void 0 ? void 0 : stream._tracks.push(track); + } + return stream; + }); + const eventData = { + streams, + transceiver, + track, + receiver: transceiver.receiver + }; + this.dispatchEvent(new RTCTrackEvent('track', eventData)); + streams.forEach(stream => { + stream.dispatchEvent(new MediaStreamTrackEvent('addtrack', { + track + })); + }); + + // Dispatch an unmute event for the track. + track._setMutedInternal(false); + } + log.debug(`${this._pcId} setRemoteDescription OK`); + } + async addIceCandidate(candidate) { + log.debug(`${this._pcId} addIceCandidate`); + if (!candidate || !candidate.candidate) { + // XXX end-of candidates is not implemented: https://bugs.chromium.org/p/webrtc/issues/detail?id=9218 + return; + } + if ((candidate.sdpMLineIndex === null || candidate.sdpMLineIndex === undefined) && (candidate.sdpMid === null || candidate.sdpMid === undefined)) { + throw new TypeError('`sdpMLineIndex` and `sdpMid` must not be both null or undefined'); + } + const newSdp = await WebRTCModule.peerConnectionAddICECandidate(this._pcId, RTCUtil.deepClone(candidate)); + this.remoteDescription = new RTCSessionDescription(newSdp); + } + + /** + * @brief Adds a new track to the {@link RTCPeerConnection}, + * and indicates that it is contained in the specified {@link MediaStream}s. + * This method has to be synchronous as the W3C API expects a track to be returned + * @param {MediaStreamTrack} track The track to be added + * @param {...MediaStream} streams One or more {@link MediaStream}s the track needs to be added to + * https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack + */ + addTrack(track) { + log.debug(`${this._pcId} addTrack`); + if (this.connectionState === 'closed') { + throw new Error('Peer Connection is closed'); + } + if (this._trackExists(track)) { + throw new Error('Track already exists in a sender'); + } + for (var _len = arguments.length, streams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + streams[_key - 1] = arguments[_key]; + } + const streamIds = streams.map(s => s.id); + const result = WebRTCModule.peerConnectionAddTrack(this._pcId, track.id, { + streamIds + }); + if (result === null) { + throw new Error('Could not add sender'); + } + const { + transceiverOrder, + transceiver, + sender + } = result; + + // According to the W3C docs, the sender could have been reused, and + // so we check if that is the case, and update accordingly. + const [existingSender] = this.getSenders().filter(s => s.id === sender.id); + if (existingSender) { + // Update sender + existingSender._track = track; + + // Update the corresponding transceiver as well + const [existingTransceiver] = this.getTransceivers().filter(t => t.sender.id === existingSender.id); + existingTransceiver._direction = transceiver.direction; + existingTransceiver._currentDirection = transceiver.currentDirection; + return existingSender; + } + + // This is a new transceiver, should create a transceiver for it and add it + const newSender = new RTCRtpSender({ + ...transceiver.sender, + track + }); + const remoteTrack = transceiver.receiver.track ? new MediaStreamTrack(transceiver.receiver.track) : null; + const newReceiver = new RTCRtpReceiver({ + ...transceiver.receiver, + track: remoteTrack + }); + const newTransceiver = new RTCRtpTransceiver({ + ...transceiver, + sender: newSender, + receiver: newReceiver + }); + this._insertTransceiverSorted(transceiverOrder, newTransceiver); + return newSender; + } + addTransceiver(source, init) { + log.debug(`${this._pcId} addTransceiver`); + let src = {}; + if (source === 'audio') { + src = { + type: 'audio' + }; + } else if (source === 'video') { + src = { + type: 'video' + }; + } else { + src = { + trackId: source.id + }; + } + + // Extract the stream ids + if (init && init.streams) { + init.streamIds = init.streams.map(stream => stream.id); + } + const result = WebRTCModule.peerConnectionAddTransceiver(this._pcId, { + ...src, + init: { + ...init + } + }); + if (result === null) { + throw new Error('Transceiver could not be added'); + } + const t = result.transceiver; + let track = null; + if (typeof source === 'string') { + if (t.sender.track) { + track = new MediaStreamTrack(t.sender.track); + } + } else { + // 'source' is a MediaStreamTrack + track = source; + } + const sender = new RTCRtpSender({ + ...t.sender, + track + }); + const remoteTrack = t.receiver.track ? new MediaStreamTrack(t.receiver.track) : null; + const receiver = new RTCRtpReceiver({ + ...t.receiver, + track: remoteTrack + }); + const transceiver = new RTCRtpTransceiver({ + ...result.transceiver, + sender, + receiver + }); + this._insertTransceiverSorted(result.transceiverOrder, transceiver); + return transceiver; + } + removeTrack(sender) { + log.debug(`${this._pcId} removeTrack`); + if (this._pcId !== sender._peerConnectionId) { + throw new Error('Sender does not belong to this peer connection'); + } + if (this.connectionState === 'closed') { + throw new Error('Peer Connection is closed'); + } + const existingSender = this.getSenders().find(s => s === sender); + if (!existingSender) { + throw new Error('Sender does not exist'); + } + if (existingSender.track === null) { + return; + } + + // Blocking! + WebRTCModule.peerConnectionRemoveTrack(this._pcId, sender.id); + existingSender._track = null; + const [existingTransceiver] = this.getTransceivers().filter(t => t.sender.id === existingSender.id); + existingTransceiver._direction = existingTransceiver.direction === 'sendrecv' ? 'recvonly' : 'inactive'; + } + async getStats(selector) { + log.debug(`${this._pcId} getStats`); + if (!selector) { + const data = await WebRTCModule.peerConnectionGetStats(this._pcId); + + /** + * On both Android and iOS it is faster to construct a single + * JSON string representing the Map of StatsReports and have it + * pass through the React Native bridge rather than the Map of + * StatsReports. While the implementations do try to be faster in + * general, the stress is on being faster to pass through the React + * Native bridge which is a bottleneck that tends to be visible in + * the UI when there is congestion involving UI-related passing. + */ + return new Map(JSON.parse(data)); + } else { + const senders = this.getSenders().filter(s => s.track === selector); + const receivers = this.getReceivers().filter(r => r.track === selector); + const matches = senders.length + receivers.length; + if (matches === 0) { + throw new Error('Invalid selector: could not find matching sender / receiver'); + } else if (matches > 1) { + throw new Error('Invalid selector: multiple matching senders / receivers'); + } else { + const sr = senders[0] || receivers[0]; + return sr.getStats(); + } + } + } + getTransceivers() { + return this._transceivers.map(e => e.transceiver); + } + getSenders() { + return this._transceivers.filter(e => !e.transceiver.stopped).map(e => e.transceiver.sender); + } + getReceivers() { + return this._transceivers.filter(e => !e.transceiver.stopped).map(e => e.transceiver.receiver); + } + close() { + log.debug(`${this._pcId} close`); + if (this.connectionState === 'closed') { + return; + } + WebRTCModule.peerConnectionClose(this._pcId); + + // Mark transceivers as stopped. + this._transceivers.forEach(_ref => { + let { + transceiver + } = _ref; + transceiver._setStopped(); + }); + } + restartIce() { + WebRTCModule.peerConnectionRestartIce(this._pcId); + } + _registerEvents() { + addListener(this, 'peerConnectionOnRenegotiationNeeded', ev => { + if (ev.pcId !== this._pcId) { + return; + } + this.dispatchEvent(new Event('negotiationneeded')); + }); + addListener(this, 'peerConnectionIceConnectionChanged', ev => { + if (ev.pcId !== this._pcId) { + return; + } + this.iceConnectionState = ev.iceConnectionState; + this.dispatchEvent(new Event('iceconnectionstatechange')); + }); + addListener(this, 'peerConnectionStateChanged', ev => { + if (ev.pcId !== this._pcId) { + return; + } + this.connectionState = ev.connectionState; + this.dispatchEvent(new Event('connectionstatechange')); + if (ev.connectionState === 'closed') { + // This PeerConnection is done, clean up. + removeListener(this); + WebRTCModule.peerConnectionDispose(this._pcId); + } + }); + addListener(this, 'peerConnectionSignalingStateChanged', ev => { + if (ev.pcId !== this._pcId) { + return; + } + this.signalingState = ev.signalingState; + this.dispatchEvent(new Event('signalingstatechange')); + }); + + // Consider moving away from this event: https://github.com/WebKit/WebKit/pull/3953 + addListener(this, 'peerConnectionOnTrack', ev => { + if (ev.pcId !== this._pcId) { + return; + } + log.debug(`${this._pcId} ontrack`); + + // NOTE: We need to make sure the track event fires right before sRD completes, + // so we queue them up here and dispatch the events when sRD fires, but before completing it. + // In the future we should probably implement out own logic and drop this event altogether. + this._pendingTrackEvents.push(ev); + }); + addListener(this, 'peerConnectionOnRemoveTrack', ev => { + if (ev.pcId !== this._pcId) { + return; + } + log.debug(`${this._pcId} onremovetrack ${ev.receiverId}`); + const receiver = this.getReceivers().find(r => r.id === ev.receiverId); + const track = receiver === null || receiver === void 0 ? void 0 : receiver.track; + if (receiver && track) { + // As per the spec: + // - Remove the track from any media streams that were previously passed to the `track` event. + // https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-removetrack, + // - Mark the track as muted: + // https://w3c.github.io/webrtc-pc/#process-remote-track-removal + for (const stream of this._remoteStreams.values()) { + if (stream._tracks.includes(track)) { + const trackIdx = stream._tracks.indexOf(track); + log.debug(`${this._pcId} removetrack ${track.id}`); + stream._tracks.splice(trackIdx, 1); + stream.dispatchEvent(new MediaStreamTrackEvent('removetrack', { + track + })); + + // Dispatch a mute event for the track. + track._setMutedInternal(true); + } + } + } + }); + addListener(this, 'peerConnectionGotICECandidate', ev => { + if (ev.pcId !== this._pcId) { + return; + } + const sdpInfo = ev.sdp; + + // Can happen when doing a rollback. + if (sdpInfo.type && sdpInfo.sdp) { + this.localDescription = new RTCSessionDescription(sdpInfo); + } else { + this.localDescription = null; + } + const candidate = new RTCIceCandidate(ev.candidate); + this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', { + candidate + })); + }); + addListener(this, 'peerConnectionIceGatheringChanged', ev => { + if (ev.pcId !== this._pcId) { + return; + } + this.iceGatheringState = ev.iceGatheringState; + if (this.iceGatheringState === 'complete') { + const sdpInfo = ev.sdp; + + // Can happen when doing a rollback. + if (sdpInfo.type && sdpInfo.sdp) { + this.localDescription = new RTCSessionDescription(sdpInfo); + } else { + this.localDescription = null; + } + this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', { + candidate: null + })); + } + this.dispatchEvent(new Event('icegatheringstatechange')); + }); + addListener(this, 'peerConnectionDidOpenDataChannel', ev => { + if (ev.pcId !== this._pcId) { + return; + } + const channel = new RTCDataChannel(ev.dataChannel); + this.dispatchEvent(new RTCDataChannelEvent('datachannel', { + channel + })); + + // Send 'open' event. Native doesn't update the state since it's already + // set at this point. + channel.dispatchEvent(new RTCDataChannelEvent('open', { + channel + })); + }); + addListener(this, 'mediaStreamTrackMuteChanged', ev => { + if (ev.pcId !== this._pcId) { + return; + } + const [track] = this.getReceivers().map(r => r.track).filter(t => (t === null || t === void 0 ? void 0 : t.id) === ev.trackId); + if (track) { + track._setMutedInternal(ev.muted); + } + }); + } + + /** + * Creates a new RTCDataChannel object with the given label. The + * RTCDataChannelInit dictionary can be used to configure properties of the + * underlying channel such as data reliability. + * + * @param {string} label - the value with which the label attribute of the new + * instance is to be initialized + * @param {RTCDataChannelInit} dataChannelDict - an optional dictionary of + * values with which to initialize corresponding attributes of the new + * instance such as id + */ + createDataChannel(label, dataChannelDict) { + if (arguments.length === 0) { + throw new TypeError('1 argument required, but 0 present'); + } + if (dataChannelDict && 'id' in dataChannelDict) { + const id = dataChannelDict.id; + if (typeof id !== 'number') { + throw new TypeError('DataChannel id must be a number: ' + id); + } + } + const channelInfo = WebRTCModule.createDataChannel(this._pcId, String(label), dataChannelDict); + if (channelInfo === null) { + throw new TypeError('Failed to create new DataChannel'); + } + return new RTCDataChannel(channelInfo); + } + + /** + * Check whether a media stream track exists already in a sender. + * See https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack for more information + */ + _trackExists(track) { + const [sender] = this.getSenders().filter(sender => { + var _sender$track; + return ((_sender$track = sender.track) === null || _sender$track === void 0 ? void 0 : _sender$track.id) === track.id; + }); + return sender ? true : false; + } + + /** + * Updates transceivers after offer/answer updates if necessary. + */ + _updateTransceivers(transceiverUpdates) { + let removeStopped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + for (const update of transceiverUpdates) { + const [transceiver] = this.getTransceivers().filter(t => t.sender.id === update.transceiverId); + if (!transceiver) { + continue; + } + if (update.currentDirection) { + transceiver._currentDirection = update.currentDirection; + } + transceiver._mid = update.mid; + transceiver._stopped = Boolean(update.isStopped); + transceiver._sender._rtpParameters = new RTCRtpSendParameters(update.senderRtpParameters); + transceiver._receiver._rtpParameters = new RTCRtpReceiveParameters(update.receiverRtpParameters); + } + if (removeStopped) { + const stopped = this.getTransceivers().filter(t => t.stopped); + const newTransceivers = this._transceivers.filter(t => !stopped.includes(t.transceiver)); + this._transceivers = newTransceivers; + } + } + + /** + * Inserts transceiver into the transceiver array in the order they are created (timestamp). + * @param order an index that refers to when it it was created relatively. + * @param transceiver the transceiver object to be inserted. + */ + _insertTransceiverSorted(order, transceiver) { + this._transceivers.push({ + order, + transceiver + }); + this._transceivers.sort((a, b) => a.order - b.order); + } +} + +/** + * Define the `onxxx` event handlers. + */ +const proto = RTCPeerConnection.prototype; +defineEventAttribute(proto, 'connectionstatechange'); +defineEventAttribute(proto, 'icecandidate'); +defineEventAttribute(proto, 'icecandidateerror'); +defineEventAttribute(proto, 'iceconnectionstatechange'); +defineEventAttribute(proto, 'icegatheringstatechange'); +defineEventAttribute(proto, 'negotiationneeded'); +defineEventAttribute(proto, 'signalingstatechange'); +defineEventAttribute(proto, 'datachannel'); +defineEventAttribute(proto, 'track'); +defineEventAttribute(proto, 'error'); +//# sourceMappingURL=RTCPeerConnection.js.map \ No newline at end of file diff --git a/lib/module/RTCPeerConnection.js.map b/lib/module/RTCPeerConnection.js.map new file mode 100644 index 000000000..2c0055fef --- /dev/null +++ b/lib/module/RTCPeerConnection.js.map @@ -0,0 +1 @@ +{"version":3,"names":["EventTarget","Event","defineEventAttribute","NativeModules","addListener","removeListener","Logger","MediaStream","MediaStreamTrack","MediaStreamTrackEvent","RTCDataChannel","RTCDataChannelEvent","RTCIceCandidate","RTCIceCandidateEvent","RTCRtpReceiveParameters","RTCRtpReceiver","RTCRtpSendParameters","RTCRtpSender","RTCRtpTransceiver","RTCSessionDescription","RTCTrackEvent","RTCUtil","log","WebRTCModule","nextPeerConnectionId","RTCPeerConnection","constructor","configuration","_defineProperty","_pcId","_configuration$iceSer","servers","iceServers","server","urls","url","Array","isArray","map","toLowerCase","filter","s","peerConnectionInit","Error","_transceivers","_remoteStreams","Map","_pendingTrackEvents","_registerEvents","debug","createOffer","options","sdpInfo","newTransceivers","transceiversInfo","peerConnectionCreateOffer","normalizeOfferOptions","forEach","t","transceiverOrder","transceiver","newSender","sender","track","remoteTrack","receiver","newReceiver","newTransceiver","_insertTransceiverSorted","_updateTransceivers","createAnswer","peerConnectionCreateAnswer","setConfiguration","peerConnectionSetConfiguration","setLocalDescription","sessionDescription","_desc","desc","_sessionDescription$s","type","sdp","isSdpTypeValid","peerConnectionSetLocalDescription","localDescription","setRemoteDescription","_sessionDescription$s2","_desc$type","Promise","reject","peerConnectionSetRemoteDescription","remoteDescription","pendingTrackEvents","ev","getTransceivers","id","_mid","mid","_currentDirection","currentDirection","_direction","direction","streams","streamInfo","has","streamId","stream","streamReactTag","tracks","set","get","_tracks","includes","push","eventData","dispatchEvent","_setMutedInternal","addIceCandidate","candidate","sdpMLineIndex","undefined","sdpMid","TypeError","newSdp","peerConnectionAddICECandidate","deepClone","addTrack","connectionState","_trackExists","_len","arguments","length","_key","streamIds","result","peerConnectionAddTrack","existingSender","getSenders","_track","existingTransceiver","addTransceiver","source","init","src","trackId","peerConnectionAddTransceiver","removeTrack","_peerConnectionId","find","peerConnectionRemoveTrack","getStats","selector","data","peerConnectionGetStats","JSON","parse","senders","receivers","getReceivers","r","matches","sr","e","stopped","close","peerConnectionClose","_ref","_setStopped","restartIce","peerConnectionRestartIce","pcId","iceConnectionState","peerConnectionDispose","signalingState","receiverId","values","trackIdx","indexOf","splice","iceGatheringState","channel","dataChannel","muted","createDataChannel","label","dataChannelDict","channelInfo","String","_sender$track","transceiverUpdates","removeStopped","update","transceiverId","_stopped","Boolean","isStopped","_sender","_rtpParameters","senderRtpParameters","_receiver","receiverRtpParameters","order","sort","a","b","proto","prototype"],"sources":["RTCPeerConnection.ts"],"sourcesContent":["import { EventTarget, Event, defineEventAttribute } from 'event-target-shim/index';\nimport { NativeModules } from 'react-native';\n\nimport { addListener, removeListener } from './EventEmitter';\nimport Logger from './Logger';\nimport MediaStream from './MediaStream';\nimport MediaStreamTrack from './MediaStreamTrack';\nimport MediaStreamTrackEvent from './MediaStreamTrackEvent';\nimport RTCDataChannel from './RTCDataChannel';\nimport RTCDataChannelEvent from './RTCDataChannelEvent';\nimport RTCIceCandidate from './RTCIceCandidate';\nimport RTCIceCandidateEvent from './RTCIceCandidateEvent';\nimport RTCRtpReceiveParameters from './RTCRtpReceiveParameters';\nimport RTCRtpReceiver from './RTCRtpReceiver';\nimport RTCRtpSendParameters from './RTCRtpSendParameters';\nimport RTCRtpSender from './RTCRtpSender';\nimport RTCRtpTransceiver from './RTCRtpTransceiver';\nimport RTCSessionDescription, { RTCSessionDescriptionInit } from './RTCSessionDescription';\nimport RTCTrackEvent from './RTCTrackEvent';\nimport * as RTCUtil from './RTCUtil';\nimport { RTCOfferOptions } from './RTCUtil';\n\nconst log = new Logger('pc');\nconst { WebRTCModule } = NativeModules;\n\ntype RTCSignalingState =\n | 'stable'\n | 'have-local-offer'\n | 'have-remote-offer'\n | 'have-local-pranswer'\n | 'have-remote-pranswer'\n | 'closed';\n\ntype RTCIceGatheringState = 'new' | 'gathering' | 'complete';\n\ntype RTCPeerConnectionState = 'new' | 'connecting' | 'connected' | 'disconnected' | 'failed' | 'closed';\n\ntype RTCIceConnectionState = 'new' | 'checking' | 'connected' | 'completed' | 'failed' | 'disconnected' | 'closed';\n\ntype RTCDataChannelInit = {\n ordered?: boolean,\n maxPacketLifeTime?: number,\n maxRetransmits?: number,\n protocol?: string,\n negotiated?: boolean,\n id?: number\n};\n\ntype RTCIceServer = {\n credential?: string,\n url?: string, // Deprecated.\n urls?: string | string[],\n username?: string\n};\n\ntype RTCConfiguration = {\n bundlePolicy?: 'balanced' | 'max-compat' | 'max-bundle',\n iceCandidatePoolSize?: number,\n iceServers?: RTCIceServer[],\n iceTransportPolicy?: 'all' | 'relay',\n rtcpMuxPolicy?: 'negotiate' | 'require'\n};\n\ntype RTCPeerConnectionEventMap = {\n connectionstatechange: Event<'connectionstatechange'>\n icecandidate: RTCIceCandidateEvent<'icecandidate'>\n icecandidateerror: RTCIceCandidateEvent<'icecandidateerror'>\n iceconnectionstatechange: Event<'iceconnectionstatechange'>\n icegatheringstatechange: Event<'icegatheringstatechange'>\n negotiationneeded: Event<'negotiationneeded'>\n signalingstatechange: Event<'signalingstatechange'>\n datachannel: RTCDataChannelEvent<'datachannel'>\n track: RTCTrackEvent<'track'>\n error: Event<'error'>\n}\n\nlet nextPeerConnectionId = 0;\n\nexport default class RTCPeerConnection extends EventTarget {\n localDescription: RTCSessionDescription | null = null;\n remoteDescription: RTCSessionDescription | null = null;\n signalingState: RTCSignalingState = 'stable';\n iceGatheringState: RTCIceGatheringState = 'new';\n connectionState: RTCPeerConnectionState = 'new';\n iceConnectionState: RTCIceConnectionState = 'new';\n\n _pcId: number;\n _transceivers: { order: number, transceiver: RTCRtpTransceiver }[];\n _remoteStreams: Map;\n _pendingTrackEvents: any[];\n\n constructor(configuration?: RTCConfiguration) {\n super();\n\n this._pcId = nextPeerConnectionId++;\n\n // Sanitize ICE servers.\n if (configuration) {\n const servers = configuration?.iceServers ?? [];\n\n for (const server of servers) {\n let urls = server.url || server.urls;\n\n delete server.url;\n delete server.urls;\n\n if (!urls) {\n continue;\n }\n\n if (!Array.isArray(urls)) {\n urls = [ urls ];\n }\n\n // Native WebRTC does case sensitive parsing.\n server.urls = urls.map(url => url.toLowerCase());\n }\n\n // Filter out bogus servers.\n configuration.iceServers = servers.filter(s => s.urls);\n }\n\n if (!WebRTCModule.peerConnectionInit(configuration, this._pcId)) {\n throw new Error('Failed to initialize PeerConnection, check the native logs!');\n }\n\n this._transceivers = [];\n this._remoteStreams = new Map();\n this._pendingTrackEvents = [];\n\n this._registerEvents();\n\n log.debug(`${this._pcId} ctor`);\n }\n\n async createOffer(options?:RTCOfferOptions) {\n log.debug(`${this._pcId} createOffer`);\n\n const {\n sdpInfo,\n newTransceivers,\n transceiversInfo\n } = await WebRTCModule.peerConnectionCreateOffer(this._pcId, RTCUtil.normalizeOfferOptions(options));\n\n log.debug(`${this._pcId} createOffer OK`);\n\n newTransceivers?.forEach(t => {\n const { transceiverOrder, transceiver } = t;\n const newSender = new RTCRtpSender({ ...transceiver.sender, track: null });\n const remoteTrack\n = transceiver.receiver.track ? new MediaStreamTrack(transceiver.receiver.track) : null;\n const newReceiver = new RTCRtpReceiver({ ...transceiver.receiver, track: remoteTrack });\n const newTransceiver = new RTCRtpTransceiver({\n ...transceiver,\n sender: newSender,\n receiver: newReceiver,\n });\n\n this._insertTransceiverSorted(transceiverOrder, newTransceiver);\n });\n\n this._updateTransceivers(transceiversInfo);\n\n return sdpInfo;\n }\n\n async createAnswer() {\n log.debug(`${this._pcId} createAnswer`);\n\n const {\n sdpInfo,\n transceiversInfo\n } = await WebRTCModule.peerConnectionCreateAnswer(this._pcId, {});\n\n this._updateTransceivers(transceiversInfo);\n\n return sdpInfo;\n }\n\n setConfiguration(configuration): void {\n WebRTCModule.peerConnectionSetConfiguration(configuration, this._pcId);\n }\n\n async setLocalDescription(sessionDescription?: RTCSessionDescription | RTCSessionDescriptionInit): Promise {\n log.debug(`${this._pcId} setLocalDescription`);\n\n let desc;\n\n if (sessionDescription) {\n desc = {\n type: sessionDescription.type,\n sdp: sessionDescription.sdp ?? ''\n };\n\n if (!RTCUtil.isSdpTypeValid(desc.type)) {\n throw new Error(`Invalid session description: invalid type: ${desc.type}`);\n }\n } else {\n desc = null;\n }\n\n const {\n sdpInfo,\n transceiversInfo\n } = await WebRTCModule.peerConnectionSetLocalDescription(this._pcId, desc);\n\n if (sdpInfo.type && sdpInfo.sdp) {\n this.localDescription = new RTCSessionDescription(sdpInfo);\n } else {\n this.localDescription = null;\n }\n\n this._updateTransceivers(transceiversInfo, /* removeStopped */ desc?.type === 'answer');\n\n log.debug(`${this._pcId} setLocalDescription OK`);\n }\n\n async setRemoteDescription(sessionDescription: RTCSessionDescription | RTCSessionDescriptionInit): Promise {\n log.debug(`${this._pcId} setRemoteDescription`);\n\n if (!sessionDescription) {\n return Promise.reject(new Error('No session description provided'));\n }\n\n const desc = {\n type: sessionDescription.type,\n sdp: sessionDescription.sdp ?? ''\n };\n\n if (!RTCUtil.isSdpTypeValid(desc.type ?? '')) {\n throw new Error(`Invalid session description: invalid type: ${desc.type}`);\n }\n\n const {\n sdpInfo,\n newTransceivers,\n transceiversInfo\n } = await WebRTCModule.peerConnectionSetRemoteDescription(this._pcId, desc);\n\n if (sdpInfo.type && sdpInfo.sdp) {\n this.remoteDescription = new RTCSessionDescription(sdpInfo);\n } else {\n this.remoteDescription = null;\n }\n\n newTransceivers?.forEach(t => {\n const { transceiverOrder, transceiver } = t;\n const newSender = new RTCRtpSender({ ...transceiver.sender, track: null });\n const remoteTrack\n = transceiver.receiver.track ? new MediaStreamTrack(transceiver.receiver.track) : null;\n const newReceiver = new RTCRtpReceiver({ ...transceiver.receiver, track: remoteTrack });\n const newTransceiver = new RTCRtpTransceiver({\n ...transceiver,\n sender: newSender,\n receiver: newReceiver,\n });\n\n this._insertTransceiverSorted(transceiverOrder, newTransceiver);\n });\n\n this._updateTransceivers(transceiversInfo, /* removeStopped */ desc.type === 'answer');\n\n // Fire track events. They must fire before sRD resolves.\n const pendingTrackEvents = this._pendingTrackEvents;\n\n this._pendingTrackEvents = [];\n\n for (const ev of pendingTrackEvents) {\n const [ transceiver ] = this\n .getTransceivers()\n .filter(t => t.receiver.id === ev.receiver.id);\n\n // We need to fire this event for an existing track sometimes, like\n // when the transceiver direction (on the sending side) switches from\n // sendrecv to recvonly and then back.\n\n // @ts-ignore\n const track: MediaStreamTrack = transceiver.receiver.track;\n\n transceiver._mid = ev.transceiver.mid;\n transceiver._currentDirection = ev.transceiver.currentDirection;\n transceiver._direction = ev.transceiver.direction;\n\n // Get the stream object from the event. Create if necessary.\n const streams: MediaStream[] = ev.streams.map(streamInfo => {\n // Here we are making sure that we don't create stream objects that already exist\n // So that event listeners do get the same object if it has been created before.\n if (!this._remoteStreams.has(streamInfo.streamId)) {\n const stream = new MediaStream({\n streamId: streamInfo.streamId,\n streamReactTag: streamInfo.streamReactTag,\n tracks: []\n });\n\n this._remoteStreams.set(streamInfo.streamId, stream);\n }\n\n const stream = this._remoteStreams.get(streamInfo.streamId);\n\n if (!stream?._tracks.includes(track)) {\n stream?._tracks.push(track);\n }\n\n return stream;\n });\n\n const eventData = {\n streams,\n transceiver,\n track,\n receiver: transceiver.receiver\n };\n\n\n this.dispatchEvent(new RTCTrackEvent('track', eventData));\n\n streams.forEach(stream => {\n stream.dispatchEvent(new MediaStreamTrackEvent('addtrack', { track }));\n });\n\n // Dispatch an unmute event for the track.\n track._setMutedInternal(false);\n }\n\n log.debug(`${this._pcId} setRemoteDescription OK`);\n }\n\n async addIceCandidate(candidate): Promise {\n log.debug(`${this._pcId} addIceCandidate`);\n\n if (!candidate || !candidate.candidate) {\n // XXX end-of candidates is not implemented: https://bugs.chromium.org/p/webrtc/issues/detail?id=9218\n return;\n }\n\n if ((candidate.sdpMLineIndex === null ||\n candidate.sdpMLineIndex === undefined) &&\n (candidate.sdpMid === null ||\n candidate.sdpMid === undefined)\n ) {\n throw new TypeError('`sdpMLineIndex` and `sdpMid` must not be both null or undefined');\n }\n\n const newSdp = await WebRTCModule.peerConnectionAddICECandidate(\n this._pcId,\n RTCUtil.deepClone(candidate)\n );\n\n this.remoteDescription = new RTCSessionDescription(newSdp);\n }\n\n /**\n * @brief Adds a new track to the {@link RTCPeerConnection},\n * and indicates that it is contained in the specified {@link MediaStream}s.\n * This method has to be synchronous as the W3C API expects a track to be returned\n * @param {MediaStreamTrack} track The track to be added\n * @param {...MediaStream} streams One or more {@link MediaStream}s the track needs to be added to\n * https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack\n */\n addTrack(track: MediaStreamTrack, ...streams: MediaStream[]): RTCRtpSender {\n log.debug(`${this._pcId} addTrack`);\n\n if (this.connectionState === 'closed') {\n throw new Error('Peer Connection is closed');\n }\n\n if (this._trackExists(track)) {\n throw new Error('Track already exists in a sender');\n }\n\n const streamIds = streams.map(s => s.id);\n const result = WebRTCModule.peerConnectionAddTrack(this._pcId, track.id, { streamIds });\n\n if (result === null) {\n throw new Error('Could not add sender');\n }\n\n const { transceiverOrder, transceiver, sender } = result;\n\n // According to the W3C docs, the sender could have been reused, and\n // so we check if that is the case, and update accordingly.\n const [ existingSender ] = this\n .getSenders()\n .filter(s => s.id === sender.id);\n\n if (existingSender) {\n // Update sender\n existingSender._track = track;\n\n // Update the corresponding transceiver as well\n const [ existingTransceiver ] = this\n .getTransceivers()\n .filter(t => t.sender.id === existingSender.id);\n\n existingTransceiver._direction = transceiver.direction;\n existingTransceiver._currentDirection = transceiver.currentDirection;\n\n return existingSender;\n }\n\n // This is a new transceiver, should create a transceiver for it and add it\n const newSender = new RTCRtpSender({ ...transceiver.sender, track });\n const remoteTrack = transceiver.receiver.track ? new MediaStreamTrack(transceiver.receiver.track) : null;\n const newReceiver = new RTCRtpReceiver({ ...transceiver.receiver, track: remoteTrack });\n const newTransceiver = new RTCRtpTransceiver({\n ...transceiver,\n sender: newSender,\n receiver: newReceiver,\n });\n\n this._insertTransceiverSorted(transceiverOrder, newTransceiver);\n\n return newSender;\n }\n\n addTransceiver(source: 'audio' | 'video' | MediaStreamTrack, init): RTCRtpTransceiver {\n log.debug(`${this._pcId} addTransceiver`);\n\n let src = {};\n\n if (source === 'audio') {\n src = { type: 'audio' };\n } else if (source === 'video') {\n src = { type: 'video' };\n } else {\n src = { trackId: source.id };\n }\n\n // Extract the stream ids\n if (init && init.streams) {\n init.streamIds = init.streams.map(stream => stream.id);\n }\n\n const result = WebRTCModule.peerConnectionAddTransceiver(this._pcId, { ...src, init: { ...init } });\n\n if (result === null) {\n throw new Error('Transceiver could not be added');\n }\n\n const t = result.transceiver;\n let track: MediaStreamTrack | null = null;\n\n if (typeof source === 'string') {\n if (t.sender.track) {\n track = new MediaStreamTrack(t.sender.track);\n }\n } else {\n // 'source' is a MediaStreamTrack\n track = source;\n }\n\n const sender = new RTCRtpSender({ ...t.sender, track });\n const remoteTrack = t.receiver.track ? new MediaStreamTrack(t.receiver.track) : null;\n const receiver = new RTCRtpReceiver({ ...t.receiver, track: remoteTrack });\n const transceiver = new RTCRtpTransceiver({\n ...result.transceiver,\n sender,\n receiver\n });\n\n this._insertTransceiverSorted(result.transceiverOrder, transceiver);\n\n return transceiver;\n }\n\n removeTrack(sender: RTCRtpSender) {\n log.debug(`${this._pcId} removeTrack`);\n\n if (this._pcId !== sender._peerConnectionId) {\n throw new Error('Sender does not belong to this peer connection');\n }\n\n if (this.connectionState === 'closed') {\n throw new Error('Peer Connection is closed');\n }\n\n const existingSender = this\n .getSenders()\n .find(s => s === sender);\n\n if (!existingSender) {\n throw new Error('Sender does not exist');\n }\n\n if (existingSender.track === null) {\n return;\n }\n\n // Blocking!\n WebRTCModule.peerConnectionRemoveTrack(this._pcId, sender.id);\n\n existingSender._track = null;\n\n const [ existingTransceiver ] = this\n .getTransceivers()\n .filter(t => t.sender.id === existingSender.id);\n\n existingTransceiver._direction = existingTransceiver.direction === 'sendrecv' ? 'recvonly' : 'inactive';\n }\n\n async getStats(selector?: MediaStreamTrack) {\n log.debug(`${this._pcId} getStats`);\n\n if (!selector) {\n const data = await WebRTCModule.peerConnectionGetStats(this._pcId);\n\n /**\n * On both Android and iOS it is faster to construct a single\n * JSON string representing the Map of StatsReports and have it\n * pass through the React Native bridge rather than the Map of\n * StatsReports. While the implementations do try to be faster in\n * general, the stress is on being faster to pass through the React\n * Native bridge which is a bottleneck that tends to be visible in\n * the UI when there is congestion involving UI-related passing.\n */\n return new Map(JSON.parse(data));\n } else {\n const senders = this.getSenders().filter(s => s.track === selector);\n const receivers = this.getReceivers().filter(r => r.track === selector);\n const matches = senders.length + receivers.length;\n\n if (matches === 0) {\n throw new Error('Invalid selector: could not find matching sender / receiver');\n } else if (matches > 1) {\n throw new Error('Invalid selector: multiple matching senders / receivers');\n } else {\n const sr = senders[0] || receivers[0];\n\n return sr.getStats();\n }\n }\n }\n\n getTransceivers(): RTCRtpTransceiver[] {\n return this._transceivers.map(e => e.transceiver);\n }\n\n getSenders(): RTCRtpSender[] {\n return this._transceivers.filter(e => !e.transceiver.stopped).map(e => e.transceiver.sender);\n }\n\n getReceivers(): RTCRtpReceiver[] {\n return this._transceivers.filter(e => !e.transceiver.stopped).map(e => e.transceiver.receiver);\n }\n\n close(): void {\n log.debug(`${this._pcId} close`);\n\n if (this.connectionState === 'closed') {\n return;\n }\n\n WebRTCModule.peerConnectionClose(this._pcId);\n\n // Mark transceivers as stopped.\n this._transceivers.forEach(({ transceiver })=> {\n transceiver._setStopped();\n });\n }\n\n restartIce(): void {\n WebRTCModule.peerConnectionRestartIce(this._pcId);\n }\n\n _registerEvents(): void {\n addListener(this, 'peerConnectionOnRenegotiationNeeded', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n this.dispatchEvent(new Event('negotiationneeded'));\n });\n\n addListener(this, 'peerConnectionIceConnectionChanged', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n this.iceConnectionState = ev.iceConnectionState;\n\n this.dispatchEvent(new Event('iceconnectionstatechange'));\n });\n\n addListener(this, 'peerConnectionStateChanged', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n this.connectionState = ev.connectionState;\n\n this.dispatchEvent(new Event('connectionstatechange'));\n\n if (ev.connectionState === 'closed') {\n // This PeerConnection is done, clean up.\n removeListener(this);\n\n WebRTCModule.peerConnectionDispose(this._pcId);\n }\n });\n\n addListener(this, 'peerConnectionSignalingStateChanged', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n this.signalingState = ev.signalingState;\n\n this.dispatchEvent(new Event('signalingstatechange'));\n });\n\n // Consider moving away from this event: https://github.com/WebKit/WebKit/pull/3953\n addListener(this, 'peerConnectionOnTrack', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n log.debug(`${this._pcId} ontrack`);\n\n // NOTE: We need to make sure the track event fires right before sRD completes,\n // so we queue them up here and dispatch the events when sRD fires, but before completing it.\n // In the future we should probably implement out own logic and drop this event altogether.\n this._pendingTrackEvents.push(ev);\n });\n\n addListener(this, 'peerConnectionOnRemoveTrack', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n log.debug(`${this._pcId} onremovetrack ${ev.receiverId}`);\n\n const receiver = this.getReceivers().find(r => r.id === ev.receiverId);\n const track = receiver?.track;\n\n if (receiver && track) {\n // As per the spec:\n // - Remove the track from any media streams that were previously passed to the `track` event.\n // https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-removetrack,\n // - Mark the track as muted:\n // https://w3c.github.io/webrtc-pc/#process-remote-track-removal\n for (const stream of this._remoteStreams.values()) {\n if (stream._tracks.includes(track)) {\n const trackIdx = stream._tracks.indexOf(track);\n\n log.debug(`${this._pcId} removetrack ${track.id}`);\n\n stream._tracks.splice(trackIdx, 1);\n\n stream.dispatchEvent(new MediaStreamTrackEvent('removetrack', { track }));\n\n // Dispatch a mute event for the track.\n track._setMutedInternal(true);\n }\n }\n }\n });\n\n addListener(this, 'peerConnectionGotICECandidate', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n const sdpInfo = ev.sdp;\n\n // Can happen when doing a rollback.\n if (sdpInfo.type && sdpInfo.sdp) {\n this.localDescription = new RTCSessionDescription(sdpInfo);\n } else {\n this.localDescription = null;\n }\n\n const candidate = new RTCIceCandidate(ev.candidate);\n\n this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', { candidate }));\n });\n\n addListener(this, 'peerConnectionIceGatheringChanged', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n this.iceGatheringState = ev.iceGatheringState;\n\n if (this.iceGatheringState === 'complete') {\n const sdpInfo = ev.sdp;\n\n // Can happen when doing a rollback.\n if (sdpInfo.type && sdpInfo.sdp) {\n this.localDescription = new RTCSessionDescription(sdpInfo);\n } else {\n this.localDescription = null;\n }\n\n this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', { candidate: null }));\n }\n\n this.dispatchEvent(new Event('icegatheringstatechange'));\n });\n\n addListener(this, 'peerConnectionDidOpenDataChannel', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n const channel = new RTCDataChannel(ev.dataChannel);\n\n this.dispatchEvent(new RTCDataChannelEvent('datachannel', { channel }));\n\n // Send 'open' event. Native doesn't update the state since it's already\n // set at this point.\n channel.dispatchEvent(new RTCDataChannelEvent('open', { channel }));\n });\n\n addListener(this, 'mediaStreamTrackMuteChanged', (ev: any) => {\n if (ev.pcId !== this._pcId) {\n return;\n }\n\n const [\n track\n ] = this.getReceivers().map(r => r.track).filter(t => t?.id === ev.trackId);\n\n if (track) {\n track._setMutedInternal(ev.muted);\n }\n });\n }\n\n /**\n * Creates a new RTCDataChannel object with the given label. The\n * RTCDataChannelInit dictionary can be used to configure properties of the\n * underlying channel such as data reliability.\n *\n * @param {string} label - the value with which the label attribute of the new\n * instance is to be initialized\n * @param {RTCDataChannelInit} dataChannelDict - an optional dictionary of\n * values with which to initialize corresponding attributes of the new\n * instance such as id\n */\n createDataChannel(label: string, dataChannelDict?: RTCDataChannelInit): RTCDataChannel {\n if (arguments.length === 0) {\n throw new TypeError('1 argument required, but 0 present');\n }\n\n if (dataChannelDict && 'id' in dataChannelDict) {\n const id = dataChannelDict.id;\n\n if (typeof id !== 'number') {\n throw new TypeError('DataChannel id must be a number: ' + id);\n }\n }\n\n const channelInfo = WebRTCModule.createDataChannel(this._pcId, String(label), dataChannelDict);\n\n if (channelInfo === null) {\n throw new TypeError('Failed to create new DataChannel');\n }\n\n return new RTCDataChannel(channelInfo);\n }\n\n /**\n * Check whether a media stream track exists already in a sender.\n * See https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack for more information\n */\n _trackExists(track: MediaStreamTrack): boolean {\n const [ sender ] = this\n .getSenders()\n .filter(\n sender => sender.track?.id === track.id\n );\n\n return sender? true : false;\n }\n\n /**\n * Updates transceivers after offer/answer updates if necessary.\n */\n _updateTransceivers(transceiverUpdates, removeStopped = false) {\n for (const update of transceiverUpdates) {\n const [ transceiver ] = this\n .getTransceivers()\n .filter(t => t.sender.id === update.transceiverId);\n\n if (!transceiver) {\n continue;\n }\n\n if (update.currentDirection) {\n transceiver._currentDirection = update.currentDirection;\n }\n\n transceiver._mid = update.mid;\n transceiver._stopped = Boolean(update.isStopped);\n transceiver._sender._rtpParameters = new RTCRtpSendParameters(update.senderRtpParameters);\n transceiver._receiver._rtpParameters = new RTCRtpReceiveParameters(update.receiverRtpParameters);\n }\n\n if (removeStopped) {\n const stopped = this.getTransceivers().filter(t => t.stopped);\n const newTransceivers = this._transceivers.filter(t => !stopped.includes(t.transceiver));\n\n this._transceivers = newTransceivers;\n }\n }\n\n /**\n * Inserts transceiver into the transceiver array in the order they are created (timestamp).\n * @param order an index that refers to when it it was created relatively.\n * @param transceiver the transceiver object to be inserted.\n */\n _insertTransceiverSorted(order: number, transceiver: RTCRtpTransceiver) {\n this._transceivers.push({ order, transceiver });\n this._transceivers.sort((a, b) => a.order - b.order);\n }\n}\n\n/**\n * Define the `onxxx` event handlers.\n */\nconst proto = RTCPeerConnection.prototype;\n\ndefineEventAttribute(proto, 'connectionstatechange');\ndefineEventAttribute(proto, 'icecandidate');\ndefineEventAttribute(proto, 'icecandidateerror');\ndefineEventAttribute(proto, 'iceconnectionstatechange');\ndefineEventAttribute(proto, 'icegatheringstatechange');\ndefineEventAttribute(proto, 'negotiationneeded');\ndefineEventAttribute(proto, 'signalingstatechange');\ndefineEventAttribute(proto, 'datachannel');\ndefineEventAttribute(proto, 'track');\ndefineEventAttribute(proto, 'error');\n"],"mappings":";AAAA,SAASA,WAAW,EAAEC,KAAK,EAAEC,oBAAoB,QAAQ,yBAAyB;AAClF,SAASC,aAAa,QAAQ,cAAc;AAE5C,SAASC,WAAW,EAAEC,cAAc,QAAQ,gBAAgB;AAC5D,OAAOC,MAAM,MAAM,UAAU;AAC7B,OAAOC,WAAW,MAAM,eAAe;AACvC,OAAOC,gBAAgB,MAAM,oBAAoB;AACjD,OAAOC,qBAAqB,MAAM,yBAAyB;AAC3D,OAAOC,cAAc,MAAM,kBAAkB;AAC7C,OAAOC,mBAAmB,MAAM,uBAAuB;AACvD,OAAOC,eAAe,MAAM,mBAAmB;AAC/C,OAAOC,oBAAoB,MAAM,wBAAwB;AACzD,OAAOC,uBAAuB,MAAM,2BAA2B;AAC/D,OAAOC,cAAc,MAAM,kBAAkB;AAC7C,OAAOC,oBAAoB,MAAM,wBAAwB;AACzD,OAAOC,YAAY,MAAM,gBAAgB;AACzC,OAAOC,iBAAiB,MAAM,qBAAqB;AACnD,OAAOC,qBAAqB,MAAqC,yBAAyB;AAC1F,OAAOC,aAAa,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,OAAO,MAAM,WAAW;AAGpC,MAAMC,GAAG,GAAG,IAAIhB,MAAM,CAAC,IAAI,CAAC;AAC5B,MAAM;EAAEiB;AAAa,CAAC,GAAGpB,aAAa;AAqDtC,IAAIqB,oBAAoB,GAAG,CAAC;AAE5B,eAAe,MAAMC,iBAAiB,SAASzB,WAAW,CAA4B;EAalF0B,WAAWA,CAACC,aAAgC,EAAE;IAC1C,KAAK,CAAC,CAAC;IAACC,eAAA,2BAbqC,IAAI;IAAAA,eAAA,4BACH,IAAI;IAAAA,eAAA,yB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oB,CAAC0M,KAAK,EAAE,aAAa,CAAC;AAC1C1M,oBAAoB,CAAC0M,KAAK,EAAE,OAAO,CAAC;AACpC1M,oBAAoB,CAAC0M,KAAK,EAAE,OAAO,CAAC"} \ No newline at end of file diff --git a/lib/module/RTCRtcpParameters.js b/lib/module/RTCRtcpParameters.js new file mode 100644 index 000000000..c3967a957 --- /dev/null +++ b/lib/module/RTCRtcpParameters.js @@ -0,0 +1,17 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +export default class RTCRtcpParameters { + constructor(init) { + _defineProperty(this, "cname", void 0); + _defineProperty(this, "reducedSize", void 0); + this.cname = init.cname; + this.reducedSize = init.reducedSize; + Object.freeze(this); + } + toJSON() { + return { + cname: this.cname, + reducedSize: this.reducedSize + }; + } +} +//# sourceMappingURL=RTCRtcpParameters.js.map \ No newline at end of file diff --git a/lib/module/RTCRtcpParameters.js.map b/lib/module/RTCRtcpParameters.js.map new file mode 100644 index 000000000..822addbdd --- /dev/null +++ b/lib/module/RTCRtcpParameters.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtcpParameters","constructor","init","_defineProperty","cname","reducedSize","Object","freeze","toJSON"],"sources":["RTCRtcpParameters.ts"],"sourcesContent":["export interface RTCRtcpParametersInit {\n cname: string;\n reducedSize: boolean;\n}\n\nexport default class RTCRtcpParameters {\n readonly cname: string;\n readonly reducedSize: boolean;\n\n constructor(init: RTCRtcpParametersInit) {\n this.cname = init.cname;\n this.reducedSize = init.reducedSize;\n\n Object.freeze(this);\n }\n\n toJSON(): RTCRtcpParametersInit {\n return {\n cname: this.cname,\n reducedSize: this.reducedSize\n };\n }\n}\n"],"mappings":";AAKA,eAAe,MAAMA,iBAAiB,CAAC;EAInCC,WAAWA,CAACC,IAA2B,EAAE;IAAAC,eAAA;IAAAA,eAAA;IACrC,IAAI,CAACC,KAAK,GAAGF,IAAI,CAACE,KAAK;IACvB,IAAI,CAACC,WAAW,GAAGH,IAAI,CAACG,WAAW;IAEnCC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC;EACvB;EAEAC,MAAMA,CAAA,EAA0B;IAC5B,OAAO;MACHJ,KAAK,EAAE,IAAI,CAACA,KAAK;MACjBC,WAAW,EAAE,IAAI,CAACA;IACtB,CAAC;EACL;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCRtpCapabilities.js b/lib/module/RTCRtpCapabilities.js new file mode 100644 index 000000000..4cebb9012 --- /dev/null +++ b/lib/module/RTCRtpCapabilities.js @@ -0,0 +1,15 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +/** + * @brief represents codec capabilities for senders and receivers. + */ +export default class RTCRtpCapabilities { + constructor(codecs) { + _defineProperty(this, "_codecs", []); + this._codecs = codecs; + Object.freeze(this); + } + get codecs() { + return this._codecs; + } +} +//# sourceMappingURL=RTCRtpCapabilities.js.map \ No newline at end of file diff --git a/lib/module/RTCRtpCapabilities.js.map b/lib/module/RTCRtpCapabilities.js.map new file mode 100644 index 000000000..14da097f1 --- /dev/null +++ b/lib/module/RTCRtpCapabilities.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtpCapabilities","constructor","codecs","_defineProperty","_codecs","Object","freeze"],"sources":["RTCRtpCapabilities.ts"],"sourcesContent":["import RTCRtpCodecCapability from './RTCRtpCodecCapability';\n\n/**\n * @brief represents codec capabilities for senders and receivers.\n */\nexport default class RTCRtpCapabilities {\n _codecs: RTCRtpCodecCapability[] = [];\n constructor(codecs: RTCRtpCodecCapability[]) {\n this._codecs = codecs;\n Object.freeze(this);\n }\n\n get codecs() {\n return this._codecs;\n }\n}\n"],"mappings":";AAEA;AACA;AACA;AACA,eAAe,MAAMA,kBAAkB,CAAC;EAEpCC,WAAWA,CAACC,MAA+B,EAAE;IAAAC,eAAA,kBADV,EAAE;IAEjC,IAAI,CAACC,OAAO,GAAGF,MAAM;IACrBG,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC;EACvB;EAEA,IAAIJ,MAAMA,CAAA,EAAG;IACT,OAAO,IAAI,CAACE,OAAO;EACvB;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCRtpCodecCapability.js b/lib/module/RTCRtpCodecCapability.js new file mode 100644 index 000000000..666b2b929 --- /dev/null +++ b/lib/module/RTCRtpCodecCapability.js @@ -0,0 +1,12 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +export default class RTCRtpCodecCapability { + constructor(init) { + _defineProperty(this, "_mimeType", void 0); + this._mimeType = init.mimeType; + Object.freeze(this); + } + get mimeType() { + return this._mimeType; + } +} +//# sourceMappingURL=RTCRtpCodecCapability.js.map \ No newline at end of file diff --git a/lib/module/RTCRtpCodecCapability.js.map b/lib/module/RTCRtpCodecCapability.js.map new file mode 100644 index 000000000..a62de94b0 --- /dev/null +++ b/lib/module/RTCRtpCodecCapability.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtpCodecCapability","constructor","init","_defineProperty","_mimeType","mimeType","Object","freeze"],"sources":["RTCRtpCodecCapability.ts"],"sourcesContent":["\nexport default class RTCRtpCodecCapability {\n _mimeType: string;\n\n constructor(init: { mimeType: string }) {\n this._mimeType = init.mimeType;\n Object.freeze(this);\n }\n\n get mimeType() {\n return this._mimeType;\n }\n}"],"mappings":";AACA,eAAe,MAAMA,qBAAqB,CAAC;EAGvCC,WAAWA,CAACC,IAA0B,EAAE;IAAAC,eAAA;IACpC,IAAI,CAACC,SAAS,GAAGF,IAAI,CAACG,QAAQ;IAC9BC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC;EACvB;EAEA,IAAIF,QAAQA,CAAA,EAAG;IACX,OAAO,IAAI,CAACD,SAAS;EACzB;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCRtpCodecParameters.js b/lib/module/RTCRtpCodecParameters.js new file mode 100644 index 000000000..e15158c34 --- /dev/null +++ b/lib/module/RTCRtpCodecParameters.js @@ -0,0 +1,31 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +export default class RTCRtpCodecParameters { + constructor(init) { + _defineProperty(this, "payloadType", void 0); + _defineProperty(this, "clockRate", void 0); + _defineProperty(this, "mimeType", void 0); + _defineProperty(this, "channels", void 0); + _defineProperty(this, "sdpFmtpLine", void 0); + this.payloadType = init.payloadType; + this.clockRate = init.clockRate; + this.mimeType = init.mimeType; + this.channels = init.channels ? init.channels : null; + this.sdpFmtpLine = init.sdpFmtpLine ? init.sdpFmtpLine : null; + Object.freeze(this); + } + toJSON() { + const obj = { + payloadType: this.payloadType, + clockRate: this.clockRate, + mimeType: this.mimeType + }; + if (this.channels !== null) { + obj['channels'] = this.channels; + } + if (this.sdpFmtpLine !== null) { + obj['sdpFmtpLine'] = this.sdpFmtpLine; + } + return obj; + } +} +//# sourceMappingURL=RTCRtpCodecParameters.js.map \ No newline at end of file diff --git a/lib/module/RTCRtpCodecParameters.js.map b/lib/module/RTCRtpCodecParameters.js.map new file mode 100644 index 000000000..6eb95043e --- /dev/null +++ b/lib/module/RTCRtpCodecParameters.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtpCodecParameters","constructor","init","_defineProperty","payloadType","clockRate","mimeType","channels","sdpFmtpLine","Object","freeze","toJSON","obj"],"sources":["RTCRtpCodecParameters.ts"],"sourcesContent":["export interface RTCRtpCodecParametersInit {\n payloadType: number;\n clockRate: number;\n mimeType: string;\n channels?: number;\n sdpFmtpLine?: string;\n}\n\nexport default class RTCRtpCodecParameters {\n readonly payloadType: number;\n readonly clockRate: number;\n readonly mimeType: string;\n readonly channels: number | null;\n readonly sdpFmtpLine: string | null;\n\n constructor(init: RTCRtpCodecParametersInit) {\n this.payloadType = init.payloadType;\n this.clockRate = init.clockRate;\n this.mimeType = init.mimeType;\n\n this.channels = init.channels ? init.channels : null;\n this.sdpFmtpLine = init.sdpFmtpLine ? init.sdpFmtpLine : null;\n\n Object.freeze(this);\n }\n\n toJSON(): RTCRtpCodecParametersInit {\n const obj = {\n payloadType: this.payloadType,\n clockRate: this.clockRate,\n mimeType: this.mimeType\n };\n\n if (this.channels !== null) {\n obj['channels'] = this.channels;\n }\n\n if (this.sdpFmtpLine !== null) {\n obj['sdpFmtpLine'] = this.sdpFmtpLine;\n }\n\n return obj;\n }\n}\n"],"mappings":";AAQA,eAAe,MAAMA,qBAAqB,CAAC;EAOvCC,WAAWA,CAACC,IAA+B,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACzC,IAAI,CAACC,WAAW,GAAGF,IAAI,CAACE,WAAW;IACnC,IAAI,CAACC,SAAS,GAAGH,IAAI,CAACG,SAAS;IAC/B,IAAI,CAACC,QAAQ,GAAGJ,IAAI,CAACI,QAAQ;IAE7B,IAAI,CAACC,QAAQ,GAAGL,IAAI,CAACK,QAAQ,GAAGL,IAAI,CAACK,QAAQ,GAAG,IAAI;IACpD,IAAI,CAACC,WAAW,GAAGN,IAAI,CAACM,WAAW,GAAGN,IAAI,CAACM,WAAW,GAAG,IAAI;IAE7DC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC;EACvB;EAEAC,MAAMA,CAAA,EAA8B;IAChC,MAAMC,GAAG,GAAG;MACRR,WAAW,EAAE,IAAI,CAACA,WAAW;MAC7BC,SAAS,EAAE,IAAI,CAACA,SAAS;MACzBC,QAAQ,EAAE,IAAI,CAACA;IACnB,CAAC;IAED,IAAI,IAAI,CAACC,QAAQ,KAAK,IAAI,EAAE;MACxBK,GAAG,CAAC,UAAU,CAAC,GAAG,IAAI,CAACL,QAAQ;IACnC;IAEA,IAAI,IAAI,CAACC,WAAW,KAAK,IAAI,EAAE;MAC3BI,GAAG,CAAC,aAAa,CAAC,GAAG,IAAI,CAACJ,WAAW;IACzC;IAEA,OAAOI,GAAG;EACd;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCRtpEncodingParameters.js b/lib/module/RTCRtpEncodingParameters.js new file mode 100644 index 000000000..2d26c224d --- /dev/null +++ b/lib/module/RTCRtpEncodingParameters.js @@ -0,0 +1,71 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +export default class RTCRtpEncodingParameters { + constructor(init) { + var _init$rid, _init$maxBitrate, _init$maxFramerate, _init$scaleResolution; + _defineProperty(this, "active", void 0); + _defineProperty(this, "_rid", void 0); + _defineProperty(this, "_maxFramerate", void 0); + _defineProperty(this, "_maxBitrate", void 0); + _defineProperty(this, "_scaleResolutionDownBy", void 0); + this.active = init.active; + this._rid = (_init$rid = init.rid) !== null && _init$rid !== void 0 ? _init$rid : null; + this._maxBitrate = (_init$maxBitrate = init.maxBitrate) !== null && _init$maxBitrate !== void 0 ? _init$maxBitrate : null; + this._maxFramerate = (_init$maxFramerate = init.maxFramerate) !== null && _init$maxFramerate !== void 0 ? _init$maxFramerate : null; + this._scaleResolutionDownBy = (_init$scaleResolution = init.scaleResolutionDownBy) !== null && _init$scaleResolution !== void 0 ? _init$scaleResolution : null; + } + get rid() { + return this._rid; + } + get maxFramerate() { + return this._maxFramerate; + } + set maxFramerate(framerate) { + // eslint-disable-next-line eqeqeq + if (framerate != null && framerate > 0) { + this._maxFramerate = framerate; + } else { + this._maxFramerate = null; + } + } + get maxBitrate() { + return this._maxBitrate; + } + set maxBitrate(bitrate) { + // eslint-disable-next-line eqeqeq + if (bitrate != null && bitrate >= 0) { + this._maxBitrate = bitrate; + } else { + this._maxBitrate = null; + } + } + get scaleResolutionDownBy() { + return this._scaleResolutionDownBy; + } + set scaleResolutionDownBy(resolutionScale) { + // eslint-disable-next-line eqeqeq + if (resolutionScale != null && resolutionScale >= 1) { + this._scaleResolutionDownBy = resolutionScale; + } else { + this._scaleResolutionDownBy = null; + } + } + toJSON() { + const obj = { + active: Boolean(this.active) + }; + if (this._rid !== null) { + obj['rid'] = this._rid; + } + if (this._maxBitrate !== null) { + obj['maxBitrate'] = this._maxBitrate; + } + if (this._maxFramerate !== null) { + obj['maxFramerate'] = this._maxFramerate; + } + if (this._scaleResolutionDownBy !== null) { + obj['scaleResolutionDownBy'] = this._scaleResolutionDownBy; + } + return obj; + } +} +//# sourceMappingURL=RTCRtpEncodingParameters.js.map \ No newline at end of file diff --git a/lib/module/RTCRtpEncodingParameters.js.map b/lib/module/RTCRtpEncodingParameters.js.map new file mode 100644 index 000000000..0a7c0164a --- /dev/null +++ b/lib/module/RTCRtpEncodingParameters.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtpEncodingParameters","constructor","init","_init$rid","_init$maxBitrate","_init$maxFramerate","_init$scaleResolution","_defineProperty","active","_rid","rid","_maxBitrate","maxBitrate","_maxFramerate","maxFramerate","_scaleResolutionDownBy","scaleResolutionDownBy","framerate","bitrate","resolutionScale","toJSON","obj","Boolean"],"sources":["RTCRtpEncodingParameters.ts"],"sourcesContent":["export interface RTCRtpEncodingParametersInit {\n active: boolean,\n rid?: string;\n maxFramerate?: number;\n maxBitrate?: number;\n scaleResolutionDownBy?: number;\n}\n\nexport default class RTCRtpEncodingParameters {\n active: boolean;\n _rid: string | null;\n _maxFramerate: number | null;\n _maxBitrate: number | null;\n _scaleResolutionDownBy: number | null;\n\n constructor(init: RTCRtpEncodingParametersInit) {\n this.active = init.active;\n this._rid = init.rid ?? null;\n this._maxBitrate = init.maxBitrate ?? null;\n this._maxFramerate = init.maxFramerate ?? null;\n this._scaleResolutionDownBy = init.scaleResolutionDownBy ?? null;\n }\n\n get rid() {\n return this._rid;\n }\n\n get maxFramerate() {\n return this._maxFramerate;\n }\n\n set maxFramerate(framerate) {\n // eslint-disable-next-line eqeqeq\n if (framerate != null && framerate > 0) {\n this._maxFramerate = framerate;\n } else {\n this._maxFramerate = null;\n }\n }\n\n get maxBitrate() {\n return this._maxBitrate;\n }\n\n set maxBitrate(bitrate) {\n // eslint-disable-next-line eqeqeq\n if (bitrate != null && bitrate >= 0) {\n this._maxBitrate = bitrate;\n } else {\n this._maxBitrate = null;\n }\n }\n\n get scaleResolutionDownBy() {\n return this._scaleResolutionDownBy;\n }\n\n set scaleResolutionDownBy(resolutionScale) {\n // eslint-disable-next-line eqeqeq\n if (resolutionScale != null && resolutionScale >= 1) {\n this._scaleResolutionDownBy = resolutionScale;\n } else {\n this._scaleResolutionDownBy = null;\n }\n }\n\n toJSON(): RTCRtpEncodingParametersInit {\n const obj = {\n active: Boolean(this.active),\n };\n\n if (this._rid !== null) {\n obj['rid'] = this._rid;\n }\n\n if (this._maxBitrate !== null) {\n obj['maxBitrate'] = this._maxBitrate;\n }\n\n if (this._maxFramerate !== null) {\n obj['maxFramerate'] = this._maxFramerate;\n }\n\n if (this._scaleResolutionDownBy !== null) {\n obj['scaleResolutionDownBy'] = this._scaleResolutionDownBy;\n }\n\n return obj;\n }\n}\n"],"mappings":";AAQA,eAAe,MAAMA,wBAAwB,CAAC;EAO1CC,WAAWA,CAACC,IAAkC,EAAE;IAAA,IAAAC,SAAA,EAAAC,gBAAA,EAAAC,kBAAA,EAAAC,qBAAA;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAC5C,IAAI,CAACC,MAAM,GAAGN,IAAI,CAACM,MAAM;IACzB,IAAI,CAACC,IAAI,IAAAN,SAAA,GAAGD,IAAI,CAACQ,GAAG,cAAAP,SAAA,cAAAA,SAAA,GAAI,IAAI;IAC5B,IAAI,CAACQ,WAAW,IAAAP,gBAAA,GAAGF,IAAI,CAACU,UAAU,cAAAR,gBAAA,cAAAA,gBAAA,GAAI,IAAI;IAC1C,IAAI,CAACS,aAAa,IAAAR,kBAAA,GAAGH,IAAI,CAACY,YAAY,cAAAT,kBAAA,cAAAA,kBAAA,GAAI,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,GAAG,IAAI,CAACZ,IAAI;IAC1B;IAEA,IAAI,IAAI,CAACE,WAAW,KAAK,IAAI,EAAE;MAC3BU,GAAG,CAAC,YAAY,CAAC,GAAG,IAAI,CAACV,WAAW;IACxC;IAEA,IAAI,IAAI,CAACE,aAAa,KAAK,IAAI,EAAE;MAC7BQ,GAAG,CAAC,cAAc,CAAC,GAAG,IAAI,CAACR,aAAa;IAC5C;IAEA,IAAI,IAAI,CAACE,sBAAsB,KAAK,IAAI,EAAE;MACtCM,GAAG,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAACN,sBAAsB;IAC9D;IAEA,OAAOM,GAAG;EACd;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCRtpHeaderExtension.js b/lib/module/RTCRtpHeaderExtension.js new file mode 100644 index 000000000..93f1f8e38 --- /dev/null +++ b/lib/module/RTCRtpHeaderExtension.js @@ -0,0 +1,20 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +export default class RTCRtpHeaderExtension { + constructor(init) { + _defineProperty(this, "id", void 0); + _defineProperty(this, "uri", void 0); + _defineProperty(this, "encrypted", void 0); + this.id = init.id; + this.uri = init.uri; + this.encrypted = init.encrypted; + Object.freeze(this); + } + toJSON() { + return { + id: this.id, + uri: this.uri, + encrypted: this.encrypted + }; + } +} +//# sourceMappingURL=RTCRtpHeaderExtension.js.map \ No newline at end of file diff --git a/lib/module/RTCRtpHeaderExtension.js.map b/lib/module/RTCRtpHeaderExtension.js.map new file mode 100644 index 000000000..a98332583 --- /dev/null +++ b/lib/module/RTCRtpHeaderExtension.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtpHeaderExtension","constructor","init","_defineProperty","id","uri","encrypted","Object","freeze","toJSON"],"sources":["RTCRtpHeaderExtension.ts"],"sourcesContent":["export interface RTCRtpHeaderExtensionInit {\n id: number;\n uri: string;\n encrypted: boolean;\n}\n\nexport default class RTCRtpHeaderExtension {\n readonly id: number;\n readonly uri: string;\n readonly encrypted: boolean;\n\n constructor(init: RTCRtpHeaderExtensionInit) {\n this.id = init.id;\n this.uri = init.uri;\n this.encrypted = init.encrypted;\n\n Object.freeze(this);\n }\n\n toJSON(): RTCRtpHeaderExtensionInit {\n return {\n id: this.id,\n uri: this.uri,\n encrypted: this.encrypted\n };\n }\n}\n"],"mappings":";AAMA,eAAe,MAAMA,qBAAqB,CAAC;EAKvCC,WAAWA,CAACC,IAA+B,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IACzC,IAAI,CAACC,EAAE,GAAGF,IAAI,CAACE,EAAE;IACjB,IAAI,CAACC,GAAG,GAAGH,IAAI,CAACG,GAAG;IACnB,IAAI,CAACC,SAAS,GAAGJ,IAAI,CAACI,SAAS;IAE/BC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC;EACvB;EAEAC,MAAMA,CAAA,EAA8B;IAChC,OAAO;MACHL,EAAE,EAAE,IAAI,CAACA,EAAE;MACXC,GAAG,EAAE,IAAI,CAACA,GAAG;MACbC,SAAS,EAAE,IAAI,CAACA;IACpB,CAAC;EACL;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCRtpParameters.js b/lib/module/RTCRtpParameters.js new file mode 100644 index 000000000..2fe746a27 --- /dev/null +++ b/lib/module/RTCRtpParameters.js @@ -0,0 +1,27 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import RTCRtcpParameters from './RTCRtcpParameters'; +import RTCRtpCodecParameters from './RTCRtpCodecParameters'; +import RTCRtpHeaderExtension from './RTCRtpHeaderExtension'; +import { deepClone } from './RTCUtil'; +export default class RTCRtpParameters { + constructor(init) { + _defineProperty(this, "codecs", []); + _defineProperty(this, "headerExtensions", []); + _defineProperty(this, "rtcp", void 0); + for (const codec of init.codecs) { + this.codecs.push(new RTCRtpCodecParameters(codec)); + } + for (const ext of init.headerExtensions) { + this.headerExtensions.push(new RTCRtpHeaderExtension(ext)); + } + this.rtcp = new RTCRtcpParameters(init.rtcp); + } + toJSON() { + return { + codecs: this.codecs.map(c => deepClone(c)), + headerExtensions: this.headerExtensions.map(he => deepClone(he)), + rtcp: deepClone(this.rtcp) + }; + } +} +//# sourceMappingURL=RTCRtpParameters.js.map \ No newline at end of file diff --git a/lib/module/RTCRtpParameters.js.map b/lib/module/RTCRtpParameters.js.map new file mode 100644 index 000000000..bd06e5f35 --- /dev/null +++ b/lib/module/RTCRtpParameters.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtcpParameters","RTCRtpCodecParameters","RTCRtpHeaderExtension","deepClone","RTCRtpParameters","constructor","init","_defineProperty","codec","codecs","push","ext","headerExtensions","rtcp","toJSON","map","c","he"],"sources":["RTCRtpParameters.ts"],"sourcesContent":["import RTCRtcpParameters, { RTCRtcpParametersInit } from './RTCRtcpParameters';\nimport RTCRtpCodecParameters, { RTCRtpCodecParametersInit } from './RTCRtpCodecParameters';\nimport RTCRtpHeaderExtension, { RTCRtpHeaderExtensionInit } from './RTCRtpHeaderExtension';\nimport { deepClone } from './RTCUtil';\n\n\nexport interface RTCRtpParametersInit {\n codecs: RTCRtpCodecParametersInit[],\n headerExtensions: RTCRtpHeaderExtensionInit[],\n rtcp: RTCRtcpParametersInit\n}\n\nexport default class RTCRtpParameters {\n codecs: (RTCRtpCodecParameters | RTCRtpCodecParametersInit)[] = [];\n readonly headerExtensions: RTCRtpHeaderExtension[] = [];\n readonly rtcp: RTCRtcpParameters;\n\n constructor(init: RTCRtpParametersInit) {\n for (const codec of init.codecs) {\n this.codecs.push(new RTCRtpCodecParameters(codec));\n }\n\n for (const ext of init.headerExtensions) {\n this.headerExtensions.push(new RTCRtpHeaderExtension(ext));\n }\n\n this.rtcp = new RTCRtcpParameters(init.rtcp);\n }\n\n toJSON() {\n return {\n codecs: this.codecs.map(c => deepClone(c)),\n headerExtensions: this.headerExtensions.map(he => deepClone(he)),\n rtcp: deepClone(this.rtcp)\n };\n }\n}\n"],"mappings":";AAAA,OAAOA,iBAAiB,MAAiC,qBAAqB;AAC9E,OAAOC,qBAAqB,MAAqC,yBAAyB;AAC1F,OAAOC,qBAAqB,MAAqC,yBAAyB;AAC1F,SAASC,SAAS,QAAQ,WAAW;AASrC,eAAe,MAAMC,gBAAgB,CAAC;EAKlCC,WAAWA,CAACC,IAA0B,EAAE;IAAAC,eAAA,iBAJwB,EAAE;IAAAA,eAAA,2BACb,EAAE;IAAAA,eAAA;IAInD,KAAK,MAAMC,KAAK,IAAIF,IAAI,CAACG,MAAM,EAAE;MAC7B,IAAI,CAACA,MAAM,CAACC,IAAI,CAAC,IAAIT,qBAAqB,CAACO,KAAK,CAAC,CAAC;IACtD;IAEA,KAAK,MAAMG,GAAG,IAAIL,IAAI,CAACM,gBAAgB,EAAE;MACrC,IAAI,CAACA,gBAAgB,CAACF,IAAI,CAAC,IAAIR,qBAAqB,CAACS,GAAG,CAAC,CAAC;IAC9D;IAEA,IAAI,CAACE,IAAI,GAAG,IAAIb,iBAAiB,CAACM,IAAI,CAACO,IAAI,CAAC;EAChD;EAEAC,MAAMA,CAAA,EAAG;IACL,OAAO;MACHL,MAAM,EAAE,IAAI,CAACA,MAAM,CAACM,GAAG,CAACC,CAAC,IAAIb,SAAS,CAACa,CAAC,CAAC,CAAC;MAC1CJ,gBAAgB,EAAE,IAAI,CAACA,gBAAgB,CAACG,GAAG,CAACE,EAAE,IAAId,SAAS,CAACc,EAAE,CAAC,CAAC;MAChEJ,IAAI,EAAEV,SAAS,CAAC,IAAI,CAACU,IAAI;IAC7B,CAAC;EACL;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCRtpReceiveParameters.js b/lib/module/RTCRtpReceiveParameters.js new file mode 100644 index 000000000..630e33cc1 --- /dev/null +++ b/lib/module/RTCRtpReceiveParameters.js @@ -0,0 +1,7 @@ +import RTCRtpParameters from './RTCRtpParameters'; +export default class RTCRtpReceiveParameters extends RTCRtpParameters { + constructor(init) { + super(init); + } +} +//# sourceMappingURL=RTCRtpReceiveParameters.js.map \ No newline at end of file diff --git a/lib/module/RTCRtpReceiveParameters.js.map b/lib/module/RTCRtpReceiveParameters.js.map new file mode 100644 index 000000000..6508fc1c9 --- /dev/null +++ b/lib/module/RTCRtpReceiveParameters.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtpParameters","RTCRtpReceiveParameters","constructor","init"],"sources":["RTCRtpReceiveParameters.ts"],"sourcesContent":["import RTCRtpParameters, { RTCRtpParametersInit } from './RTCRtpParameters';\n\nexport default class RTCRtpReceiveParameters extends RTCRtpParameters {\n constructor(init: RTCRtpParametersInit) {\n super(init);\n }\n}\n"],"mappings":"AAAA,OAAOA,gBAAgB,MAAgC,oBAAoB;AAE3E,eAAe,MAAMC,uBAAuB,SAASD,gBAAgB,CAAC;EAClEE,WAAWA,CAACC,IAA0B,EAAE;IACpC,KAAK,CAACA,IAAI,CAAC;EACf;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCRtpReceiver.js b/lib/module/RTCRtpReceiver.js new file mode 100644 index 000000000..801574bd4 --- /dev/null +++ b/lib/module/RTCRtpReceiver.js @@ -0,0 +1,45 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import { NativeModules } from 'react-native'; +import RTCRtpReceiveParameters from './RTCRtpReceiveParameters'; +const { + WebRTCModule +} = NativeModules; +export default class RTCRtpReceiver { + constructor(info) { + _defineProperty(this, "_id", void 0); + _defineProperty(this, "_peerConnectionId", void 0); + _defineProperty(this, "_track", null); + _defineProperty(this, "_rtpParameters", void 0); + this._id = info.id; + this._peerConnectionId = info.peerConnectionId; + this._rtpParameters = new RTCRtpReceiveParameters(info.rtpParameters); + if (info.track) { + this._track = info.track; + } + } + static getCapabilities(kind) { + return WebRTCModule.receiverGetCapabilities(kind); + } + getStats() { + return WebRTCModule.receiverGetStats(this._peerConnectionId, this._id).then(data => + /* On both Android and iOS it is faster to construct a single + JSON string representing the Map of StatsReports and have it + pass through the React Native bridge rather than the Map of + StatsReports. While the implementations do try to be faster in + general, the stress is on being faster to pass through the React + Native bridge which is a bottleneck that tends to be visible in + the UI when there is congestion involving UI-related passing. + */ + new Map(JSON.parse(data))); + } + getParameters() { + return this._rtpParameters; + } + get id() { + return this._id; + } + get track() { + return this._track; + } +} +//# sourceMappingURL=RTCRtpReceiver.js.map \ No newline at end of file diff --git a/lib/module/RTCRtpReceiver.js.map b/lib/module/RTCRtpReceiver.js.map new file mode 100644 index 000000000..182ace538 --- /dev/null +++ b/lib/module/RTCRtpReceiver.js.map @@ -0,0 +1 @@ +{"version":3,"names":["NativeModules","RTCRtpReceiveParameters","WebRTCModule","RTCRtpReceiver","constructor","info","_defineProperty","_id","id","_peerConnectionId","peerConnectionId","_rtpParameters","rtpParameters","track","_track","getCapabilities","kind","receiverGetCapabilities","getStats","receiverGetStats","then","data","Map","JSON","parse","getParameters"],"sources":["RTCRtpReceiver.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\nimport MediaStreamTrack from './MediaStreamTrack';\nimport RTCRtpCapabilities from './RTCRtpCapabilities';\nimport { RTCRtpParametersInit } from './RTCRtpParameters';\nimport RTCRtpReceiveParameters from './RTCRtpReceiveParameters';\n\nconst { WebRTCModule } = NativeModules;\n\nexport default class RTCRtpReceiver {\n _id: string;\n _peerConnectionId: number;\n _track: MediaStreamTrack | null = null;\n _rtpParameters: RTCRtpReceiveParameters;\n\n constructor(info: {\n peerConnectionId: number,\n id: string,\n track?: MediaStreamTrack,\n rtpParameters: RTCRtpParametersInit\n }) {\n this._id = info.id;\n this._peerConnectionId = info.peerConnectionId;\n this._rtpParameters = new RTCRtpReceiveParameters(info.rtpParameters);\n\n if (info.track) {\n this._track = info.track;\n }\n }\n\n static getCapabilities(kind: 'audio' | 'video'): RTCRtpCapabilities {\n return WebRTCModule.receiverGetCapabilities(kind);\n }\n\n getStats() {\n return WebRTCModule.receiverGetStats(this._peerConnectionId, this._id).then(data =>\n /* On both Android and iOS it is faster to construct a single\n JSON string representing the Map of StatsReports and have it\n pass through the React Native bridge rather than the Map of\n StatsReports. While the implementations do try to be faster in\n general, the stress is on being faster to pass through the React\n Native bridge which is a bottleneck that tends to be visible in\n the UI when there is congestion involving UI-related passing.\n */\n new Map(JSON.parse(data))\n );\n }\n\n getParameters(): RTCRtpReceiveParameters {\n return this._rtpParameters;\n }\n\n get id() {\n return this._id;\n }\n\n get track() {\n return this._track;\n }\n}\n"],"mappings":";AAAA,SAASA,aAAa,QAAQ,cAAc;AAK5C,OAAOC,uBAAuB,MAAM,2BAA2B;AAE/D,MAAM;EAAEC;AAAa,CAAC,GAAGF,aAAa;AAEtC,eAAe,MAAMG,cAAc,CAAC;EAMhCC,WAAWA,CAACC,IAKX,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA,iBAR+B,IAAI;IAAAA,eAAA;IASlC,IAAI,CAACC,GAAG,GAAGF,IAAI,CAACG,EAAE;IAClB,IAAI,CAACC,iBAAiB,GAAGJ,IAAI,CAACK,gBAAgB;IAC9C,IAAI,CAACC,cAAc,GAAG,IAAIV,uBAAuB,CAACI,IAAI,CAACO,aAAa,CAAC;IAErE,IAAIP,IAAI,CAACQ,KAAK,EAAE;MACZ,IAAI,CAACC,MAAM,GAAGT,IAAI,CAACQ,KAAK;IAC5B;EACJ;EAEA,OAAOE,eAAeA,CAACC,IAAuB,EAAsB;IAChE,OAAOd,YAAY,CAACe,uBAAuB,CAACD,IAAI,CAAC;EACrD;EAEAE,QAAQA,CAAA,EAAG;IACP,OAAOhB,YAAY,CAACiB,gBAAgB,CAAC,IAAI,CAACV,iBAAiB,EAAE,IAAI,CAACF,GAAG,CAAC,CAACa,IAAI,CAACC,IAAI;IAC5E;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;IACY,IAAIC,GAAG,CAACC,IAAI,CAACC,KAAK,CAACH,IAAI,CAAC,CAC5B,CAAC;EACL;EAEAI,aAAaA,CAAA,EAA4B;IACrC,OAAO,IAAI,CAACd,cAAc;EAC9B;EAEA,IAAIH,EAAEA,CAAA,EAAG;IACL,OAAO,IAAI,CAACD,GAAG;EACnB;EAEA,IAAIM,KAAKA,CAAA,EAAG;IACR,OAAO,IAAI,CAACC,MAAM;EACtB;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCRtpSendParameters.js b/lib/module/RTCRtpSendParameters.js new file mode 100644 index 000000000..fc46872ae --- /dev/null +++ b/lib/module/RTCRtpSendParameters.js @@ -0,0 +1,41 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import RTCRtpEncodingParameters from './RTCRtpEncodingParameters'; +import RTCRtpParameters from './RTCRtpParameters'; +import { deepClone } from './RTCUtil'; +/** + * Class to convert degradation preference format. Native has a format such as + * MAINTAIN_FRAMERATE whereas the web APIs expect maintain-framerate + */ +class DegradationPreference { + static fromNative(nativeFormat) { + const stringFormat = nativeFormat.toLowerCase().replace('_', '-'); + return stringFormat; + } + static toNative(format) { + return format.toUpperCase().replace('-', '_'); + } +} +export default class RTCRtpSendParameters extends RTCRtpParameters { + constructor(init) { + super(init); + _defineProperty(this, "transactionId", void 0); + _defineProperty(this, "encodings", void 0); + _defineProperty(this, "degradationPreference", void 0); + this.transactionId = init.transactionId; + this.encodings = []; + this.degradationPreference = init.degradationPreference ? DegradationPreference.fromNative(init.degradationPreference) : null; + for (const enc of init.encodings) { + this.encodings.push(new RTCRtpEncodingParameters(enc)); + } + } + toJSON() { + const obj = super.toJSON(); + obj['transactionId'] = this.transactionId; + obj['encodings'] = this.encodings.map(e => deepClone(e)); + if (this.degradationPreference !== null) { + obj['degradationPreference'] = DegradationPreference.toNative(this.degradationPreference); + } + return obj; + } +} +//# sourceMappingURL=RTCRtpSendParameters.js.map \ No newline at end of file diff --git a/lib/module/RTCRtpSendParameters.js.map b/lib/module/RTCRtpSendParameters.js.map new file mode 100644 index 000000000..9e5b0f845 --- /dev/null +++ b/lib/module/RTCRtpSendParameters.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCRtpEncodingParameters","RTCRtpParameters","deepClone","DegradationPreference","fromNative","nativeFormat","stringFormat","toLowerCase","replace","toNative","format","toUpperCase","RTCRtpSendParameters","constructor","init","_defineProperty","transactionId","encodings","degradationPreference","enc","push","toJSON","obj","map","e"],"sources":["RTCRtpSendParameters.ts"],"sourcesContent":["import RTCRtpEncodingParameters, { RTCRtpEncodingParametersInit } from './RTCRtpEncodingParameters';\nimport RTCRtpParameters, { RTCRtpParametersInit } from './RTCRtpParameters';\nimport { deepClone } from './RTCUtil';\n\ntype DegradationPreferenceType = 'maintain-framerate'\n | 'maintain-resolution'\n | 'balanced'\n | 'disabled'\n\n\n/**\n * Class to convert degradation preference format. Native has a format such as\n * MAINTAIN_FRAMERATE whereas the web APIs expect maintain-framerate\n */\nclass DegradationPreference {\n static fromNative(nativeFormat: string): DegradationPreferenceType {\n const stringFormat = nativeFormat.toLowerCase().replace('_', '-');\n\n return stringFormat as DegradationPreferenceType;\n }\n\n static toNative(format: DegradationPreferenceType): string {\n return format.toUpperCase().replace('-', '_');\n }\n}\n\nexport interface RTCRtpSendParametersInit extends RTCRtpParametersInit {\n transactionId: string;\n encodings: RTCRtpEncodingParametersInit[];\n degradationPreference?: string;\n}\n\nexport default class RTCRtpSendParameters extends RTCRtpParameters {\n readonly transactionId: string;\n encodings: (RTCRtpEncodingParameters | RTCRtpEncodingParametersInit)[];\n degradationPreference: DegradationPreferenceType | null;\n\n constructor(init: RTCRtpSendParametersInit) {\n super(init);\n\n this.transactionId = init.transactionId;\n this.encodings = [];\n this.degradationPreference = init.degradationPreference ?\n DegradationPreference.fromNative(init.degradationPreference) : null;\n\n for (const enc of init.encodings) {\n this.encodings.push(new RTCRtpEncodingParameters(enc));\n }\n }\n\n toJSON() {\n const obj = super.toJSON();\n\n obj['transactionId'] = this.transactionId;\n obj['encodings'] = this.encodings.map(e => deepClone(e));\n\n if (this.degradationPreference !== null) {\n obj['degradationPreference'] = DegradationPreference.toNative(this.degradationPreference);\n }\n\n return obj;\n }\n}\n"],"mappings":";AAAA,OAAOA,wBAAwB,MAAwC,4BAA4B;AACnG,OAAOC,gBAAgB,MAAgC,oBAAoB;AAC3E,SAASC,SAAS,QAAQ,WAAW;AAQrC;AACA;AACA;AACA;AACA,MAAMC,qBAAqB,CAAC;EACxB,OAAOC,UAAUA,CAACC,YAAoB,EAA6B;IAC/D,MAAMC,YAAY,GAAGD,YAAY,CAACE,WAAW,CAAC,CAAC,CAACC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;IAEjE,OAAOF,YAAY;EACvB;EAEA,OAAOG,QAAQA,CAACC,MAAiC,EAAU;IACvD,OAAOA,MAAM,CAACC,WAAW,CAAC,CAAC,CAACH,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;EACjD;AACJ;AAQA,eAAe,MAAMI,oBAAoB,SAASX,gBAAgB,CAAC;EAK/DY,WAAWA,CAACC,IAA8B,EAAE;IACxC,KAAK,CAACA,IAAI,CAAC;IAACC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAEZ,IAAI,CAACC,aAAa,GAAGF,IAAI,CAACE,aAAa;IACvC,IAAI,CAACC,SAAS,GAAG,EAAE;IACnB,IAAI,CAACC,qBAAqB,GAAGJ,IAAI,CAACI,qBAAqB,GACnDf,qBAAqB,CAACC,UAAU,CAACU,IAAI,CAACI,qBAAqB,CAAC,GAAG,IAAI;IAEvE,KAAK,MAAMC,GAAG,IAAIL,IAAI,CAACG,SAAS,EAAE;MAC9B,IAAI,CAACA,SAAS,CAACG,IAAI,CAAC,IAAIpB,wBAAwB,CAACmB,GAAG,CAAC,CAAC;IAC1D;EACJ;EAEAE,MAAMA,CAAA,EAAG;IACL,MAAMC,GAAG,GAAG,KAAK,CAACD,MAAM,CAAC,CAAC;IAE1BC,GAAG,CAAC,eAAe,CAAC,GAAG,IAAI,CAACN,aAAa;IACzCM,GAAG,CAAC,WAAW,CAAC,GAAG,IAAI,CAACL,SAAS,CAACM,GAAG,CAACC,CAAC,IAAItB,SAAS,CAACsB,CAAC,CAAC,CAAC;IAExD,IAAI,IAAI,CAACN,qBAAqB,KAAK,IAAI,EAAE;MACrCI,GAAG,CAAC,uBAAuB,CAAC,GAAGnB,qBAAqB,CAACM,QAAQ,CAAC,IAAI,CAACS,qBAAqB,CAAC;IAC7F;IAEA,OAAOI,GAAG;EACd;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCRtpSender.js b/lib/module/RTCRtpSender.js new file mode 100644 index 000000000..fdf62af52 --- /dev/null +++ b/lib/module/RTCRtpSender.js @@ -0,0 +1,59 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import { NativeModules } from 'react-native'; +import RTCRtpSendParameters from './RTCRtpSendParameters'; +const { + WebRTCModule +} = NativeModules; +export default class RTCRtpSender { + constructor(info) { + _defineProperty(this, "_id", void 0); + _defineProperty(this, "_track", null); + _defineProperty(this, "_peerConnectionId", void 0); + _defineProperty(this, "_rtpParameters", void 0); + this._peerConnectionId = info.peerConnectionId; + this._id = info.id; + this._rtpParameters = new RTCRtpSendParameters(info.rtpParameters); + if (info.track) { + this._track = info.track; + } + } + async replaceTrack(track) { + try { + await WebRTCModule.senderReplaceTrack(this._peerConnectionId, this._id, track ? track.id : null); + } catch (e) { + return; + } + this._track = track; + } + static getCapabilities(kind) { + return WebRTCModule.senderGetCapabilities(kind); + } + getParameters() { + return this._rtpParameters; + } + async setParameters(parameters) { + // This allows us to get rid of private "underscore properties" + const _params = JSON.parse(JSON.stringify(parameters)); + const newParameters = await WebRTCModule.senderSetParameters(this._peerConnectionId, this._id, _params); + this._rtpParameters = new RTCRtpSendParameters(newParameters); + } + getStats() { + return WebRTCModule.senderGetStats(this._peerConnectionId, this._id).then(data => + /* On both Android and iOS it is faster to construct a single + JSON string representing the Map of StatsReports and have it + pass through the React Native bridge rather than the Map of + StatsReports. While the implementations do try to be faster in + general, the stress is on being faster to pass through the React + Native bridge which is a bottleneck that tends to be visible in + the UI when there is congestion involving UI-related passing. + */ + new Map(JSON.parse(data))); + } + get track() { + return this._track; + } + get id() { + return this._id; + } +} +//# sourceMappingURL=RTCRtpSender.js.map \ No newline at end of file diff --git a/lib/module/RTCRtpSender.js.map b/lib/module/RTCRtpSender.js.map new file mode 100644 index 000000000..8b61b2311 --- /dev/null +++ b/lib/module/RTCRtpSender.js.map @@ -0,0 +1 @@ +{"version":3,"names":["NativeModules","RTCRtpSendParameters","WebRTCModule","RTCRtpSender","constructor","info","_defineProperty","_peerConnectionId","peerConnectionId","_id","id","_rtpParameters","rtpParameters","track","_track","replaceTrack","senderReplaceTrack","e","getCapabilities","kind","senderGetCapabilities","getParameters","setParameters","parameters","_params","JSON","parse","stringify","newParameters","senderSetParameters","getStats","senderGetStats","then","data","Map"],"sources":["RTCRtpSender.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\nimport MediaStreamTrack from './MediaStreamTrack';\nimport RTCRtpCapabilities from './RTCRtpCapabilities';\nimport RTCRtpSendParameters, { RTCRtpSendParametersInit } from './RTCRtpSendParameters';\n\nconst { WebRTCModule } = NativeModules;\n\n\nexport default class RTCRtpSender {\n _id: string;\n _track: MediaStreamTrack | null = null;\n _peerConnectionId: number;\n _rtpParameters: RTCRtpSendParameters;\n\n constructor(info: {\n peerConnectionId: number,\n id: string,\n track?: MediaStreamTrack,\n rtpParameters: RTCRtpSendParametersInit\n }) {\n this._peerConnectionId = info.peerConnectionId;\n this._id = info.id;\n this._rtpParameters = new RTCRtpSendParameters(info.rtpParameters);\n\n if (info.track) {\n this._track = info.track;\n }\n }\n\n async replaceTrack(track: MediaStreamTrack | null): Promise {\n try {\n await WebRTCModule.senderReplaceTrack(this._peerConnectionId, this._id, track ? track.id : null);\n } catch (e) {\n return;\n }\n\n this._track = track;\n }\n\n static getCapabilities(kind: 'audio' | 'video'): RTCRtpCapabilities {\n return WebRTCModule.senderGetCapabilities(kind);\n }\n\n getParameters(): RTCRtpSendParameters {\n return this._rtpParameters;\n }\n\n async setParameters(parameters: RTCRtpSendParameters): Promise {\n // This allows us to get rid of private \"underscore properties\"\n const _params = JSON.parse(JSON.stringify(parameters));\n const newParameters = await WebRTCModule.senderSetParameters(this._peerConnectionId, this._id, _params);\n\n this._rtpParameters = new RTCRtpSendParameters(newParameters);\n }\n\n getStats() {\n return WebRTCModule.senderGetStats(this._peerConnectionId, this._id).then(data =>\n /* On both Android and iOS it is faster to construct a single\n JSON string representing the Map of StatsReports and have it\n pass through the React Native bridge rather than the Map of\n StatsReports. While the implementations do try to be faster in\n general, the stress is on being faster to pass through the React\n Native bridge which is a bottleneck that tends to be visible in\n the UI when there is congestion involving UI-related passing.\n */\n new Map(JSON.parse(data))\n );\n }\n\n get track() {\n return this._track;\n }\n\n get id() {\n return this._id;\n }\n}\n"],"mappings":";AAAA,SAASA,aAAa,QAAQ,cAAc;AAI5C,OAAOC,oBAAoB,MAAoC,wBAAwB;AAEvF,MAAM;EAAEC;AAAa,CAAC,GAAGF,aAAa;AAGtC,eAAe,MAAMG,YAAY,CAAC;EAM9BC,WAAWA,CAACC,IAKX,EAAE;IAAAC,eAAA;IAAAA,eAAA,iBAT+B,IAAI;IAAAA,eAAA;IAAAA,eAAA;IAUlC,IAAI,CAACC,iBAAiB,GAAGF,IAAI,CAACG,gBAAgB;IAC9C,IAAI,CAACC,GAAG,GAAGJ,IAAI,CAACK,EAAE;IAClB,IAAI,CAACC,cAAc,GAAG,IAAIV,oBAAoB,CAACI,IAAI,CAACO,aAAa,CAAC;IAElE,IAAIP,IAAI,CAACQ,KAAK,EAAE;MACZ,IAAI,CAACC,MAAM,GAAGT,IAAI,CAACQ,KAAK;IAC5B;EACJ;EAEA,MAAME,YAAYA,CAACF,KAA8B,EAAiB;IAC9D,IAAI;MACA,MAAMX,YAAY,CAACc,kBAAkB,CAAC,IAAI,CAACT,iBAAiB,EAAE,IAAI,CAACE,GAAG,EAAEI,KAAK,GAAGA,KAAK,CAACH,EAAE,GAAG,IAAI,CAAC;IACpG,CAAC,CAAC,OAAOO,CAAC,EAAE;MACR;IACJ;IAEA,IAAI,CAACH,MAAM,GAAGD,KAAK;EACvB;EAEA,OAAOK,eAAeA,CAACC,IAAuB,EAAsB;IAChE,OAAOjB,YAAY,CAACkB,qBAAqB,CAACD,IAAI,CAAC;EACnD;EAEAE,aAAaA,CAAA,EAAyB;IAClC,OAAO,IAAI,CAACV,cAAc;EAC9B;EAEA,MAAMW,aAAaA,CAACC,UAAgC,EAAiB;IACjE;IACA,MAAMC,OAAO,GAAGC,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,SAAS,CAACJ,UAAU,CAAC,CAAC;IACtD,MAAMK,aAAa,GAAG,MAAM1B,YAAY,CAAC2B,mBAAmB,CAAC,IAAI,CAACtB,iBAAiB,EAAE,IAAI,CAACE,GAAG,EAAEe,OAAO,CAAC;IAEvG,IAAI,CAACb,cAAc,GAAG,IAAIV,oBAAoB,CAAC2B,aAAa,CAAC;EACjE;EAEAE,QAAQA,CAAA,EAAG;IACP,OAAO5B,YAAY,CAAC6B,cAAc,CAAC,IAAI,CAACxB,iBAAiB,EAAE,IAAI,CAACE,GAAG,CAAC,CAACuB,IAAI,CAACC,IAAI;IAC1E;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;IACY,IAAIC,GAAG,CAACT,IAAI,CAACC,KAAK,CAACO,IAAI,CAAC,CAC5B,CAAC;EACL;EAEA,IAAIpB,KAAKA,CAAA,EAAG;IACR,OAAO,IAAI,CAACC,MAAM;EACtB;EAEA,IAAIJ,EAAEA,CAAA,EAAG;IACL,OAAO,IAAI,CAACD,GAAG;EACnB;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCRtpTransceiver.js b/lib/module/RTCRtpTransceiver.js new file mode 100644 index 000000000..918830380 --- /dev/null +++ b/lib/module/RTCRtpTransceiver.js @@ -0,0 +1,74 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import { NativeModules } from 'react-native'; +const { + WebRTCModule +} = NativeModules; +export default class RTCRtpTransceiver { + constructor(args) { + var _args$mid, _args$currentDirectio; + _defineProperty(this, "_peerConnectionId", void 0); + _defineProperty(this, "_sender", void 0); + _defineProperty(this, "_receiver", void 0); + _defineProperty(this, "_mid", null); + _defineProperty(this, "_direction", void 0); + _defineProperty(this, "_currentDirection", void 0); + _defineProperty(this, "_stopped", void 0); + this._peerConnectionId = args.peerConnectionId; + this._mid = (_args$mid = args.mid) !== null && _args$mid !== void 0 ? _args$mid : null; + this._direction = args.direction; + this._currentDirection = (_args$currentDirectio = args.currentDirection) !== null && _args$currentDirectio !== void 0 ? _args$currentDirectio : null; + this._stopped = Boolean(args.isStopped); + this._sender = args.sender; + this._receiver = args.receiver; + } + get mid() { + return this._mid; + } + get stopped() { + return this._stopped; + } + get direction() { + return this._direction; + } + set direction(val) { + if (!['sendonly', 'recvonly', 'sendrecv', 'inactive'].includes(val)) { + throw new TypeError('Invalid direction provided'); + } + if (this._stopped) { + throw new Error('Transceiver Stopped'); + } + if (this._direction === val) { + return; + } + const oldDirection = this._direction; + WebRTCModule.transceiverSetDirection(this._peerConnectionId, this.sender.id, val).catch(() => { + this._direction = oldDirection; + }); + this._direction = val; + } + get currentDirection() { + return this._currentDirection; + } + get sender() { + return this._sender; + } + get receiver() { + return this._receiver; + } + stop() { + if (this._stopped) { + return; + } + WebRTCModule.transceiverStop(this._peerConnectionId, this.sender.id).then(() => this._setStopped()); + } + setCodecPreferences(codecs) { + WebRTCModule.transceiverSetCodecPreferences(this._peerConnectionId, this.sender.id, codecs); + } + _setStopped() { + this._stopped = true; + this._direction = 'stopped'; + this._currentDirection = 'stopped'; + this._mid = null; + } +} +//# sourceMappingURL=RTCRtpTransceiver.js.map \ No newline at end of file diff --git a/lib/module/RTCRtpTransceiver.js.map b/lib/module/RTCRtpTransceiver.js.map new file mode 100644 index 000000000..c858cb081 --- /dev/null +++ b/lib/module/RTCRtpTransceiver.js.map @@ -0,0 +1 @@ +{"version":3,"names":["NativeModules","WebRTCModule","RTCRtpTransceiver","constructor","args","_args$mid","_args$currentDirectio","_defineProperty","_peerConnectionId","peerConnectionId","_mid","mid","_direction","direction","_currentDirection","currentDirection","_stopped","Boolean","isStopped","_sender","sender","_receiver","receiver","stopped","val","includes","TypeError","Error","oldDirection","transceiverSetDirection","id","catch","stop","transceiverStop","then","_setStopped","setCodecPreferences","codecs","transceiverSetCodecPreferences"],"sources":["RTCRtpTransceiver.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\nimport RTCRtpCodecCapability from './RTCRtpCodecCapability';\nimport RTCRtpReceiver from './RTCRtpReceiver';\nimport RTCRtpSender from './RTCRtpSender';\n\nconst { WebRTCModule } = NativeModules;\n\nexport default class RTCRtpTransceiver {\n _peerConnectionId: number;\n _sender: RTCRtpSender;\n _receiver: RTCRtpReceiver;\n\n _mid: string | null = null;\n _direction: string;\n _currentDirection: string;\n _stopped: boolean;\n\n constructor(args: {\n peerConnectionId: number,\n isStopped: boolean,\n direction: string,\n currentDirection: string,\n mid?: string,\n sender: RTCRtpSender,\n receiver: RTCRtpReceiver,\n }) {\n this._peerConnectionId = args.peerConnectionId;\n this._mid = args.mid ?? null;\n this._direction = args.direction;\n this._currentDirection = args.currentDirection ?? null;\n this._stopped = Boolean(args.isStopped);\n this._sender = args.sender;\n this._receiver = args.receiver;\n }\n\n get mid() {\n return this._mid;\n }\n\n get stopped() {\n return this._stopped;\n }\n\n get direction() {\n return this._direction;\n }\n\n set direction(val) {\n if (![ 'sendonly', 'recvonly', 'sendrecv', 'inactive' ].includes(val)) {\n throw new TypeError('Invalid direction provided');\n }\n\n if (this._stopped) {\n throw new Error('Transceiver Stopped');\n }\n\n if (this._direction === val) {\n return;\n }\n\n const oldDirection = this._direction;\n\n WebRTCModule.transceiverSetDirection(this._peerConnectionId, this.sender.id, val)\n .catch(() => {\n this._direction = oldDirection;\n });\n\n this._direction = val;\n }\n\n get currentDirection() {\n return this._currentDirection;\n }\n\n get sender() {\n return this._sender;\n }\n\n get receiver() {\n return this._receiver;\n }\n\n stop() {\n if (this._stopped) {\n return;\n }\n\n WebRTCModule.transceiverStop(this._peerConnectionId, this.sender.id)\n .then(() => this._setStopped());\n }\n\n setCodecPreferences(codecs: RTCRtpCodecCapability[]) {\n WebRTCModule.transceiverSetCodecPreferences(\n this._peerConnectionId,\n this.sender.id,\n codecs\n );\n }\n\n _setStopped() {\n this._stopped = true;\n this._direction = 'stopped';\n this._currentDirection = 'stopped';\n this._mid = null;\n }\n}\n"],"mappings":";AAAA,SAASA,aAAa,QAAQ,cAAc;AAM5C,MAAM;EAAEC;AAAa,CAAC,GAAGD,aAAa;AAEtC,eAAe,MAAME,iBAAiB,CAAC;EAUnCC,WAAWA,CAACC,IAQX,EAAE;IAAA,IAAAC,SAAA,EAAAC,qBAAA;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA,eAbmB,IAAI;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IActB,IAAI,CAACC,iBAAiB,GAAGJ,IAAI,CAACK,gBAAgB;IAC9C,IAAI,CAACC,IAAI,IAAAL,SAAA,GAAGD,IAAI,CAACO,GAAG,cAAAN,SAAA,cAAAA,SAAA,GAAI,IAAI;IAC5B,IAAI,CAACO,UAAU,GAAGR,IAAI,CAACS,SAAS;IAChC,IAAI,CAACC,iBAAiB,IAAAR,qBAAA,GAAGF,IAAI,CAACW,gBAAgB,cAAAT,qBAAA,cAAAA,qBAAA,GAAI,IAAI;IACtD,IAAI,CAACU,QAAQ,GAAGC,OAAO,CAACb,IAAI,CAACc,SAAS,CAAC;IACvC,IAAI,CAACC,OAAO,GAAGf,IAAI,CAACgB,MAAM;IAC1B,IAAI,CAACC,SAAS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AM,CAACU,EAAE,CAAC,CAC/DI,IAAI,CAAC,MAAM,IAAI,CAACC,WAAW,CAAC,CAAC,CAAC;EACvC;EAEAC,mBAAmBA,CAACC,MAA+B,EAAE;IACjDpC,YAAY,CAACqC,8BAA8B,CACvC,IAAI,CAAC9B,iBAAiB,EACtB,IAAI,CAACY,MAAM,CAACU,EAAE,EACdO,MACJ,CAAC;EACL;EAEAF,WAAWA,CAAA,EAAG;IACV,IAAI,CAACnB,QAAQ,GAAG,IAAI;IACpB,IAAI,CAACJ,UAAU,GAAG,SAAS;IAC3B,IAAI,CAACE,iBAAiB,GAAG,SAAS;IAClC,IAAI,CAACJ,IAAI,GAAG,IAAI;EACpB;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCSessionDescription.js b/lib/module/RTCSessionDescription.js new file mode 100644 index 000000000..dc3497169 --- /dev/null +++ b/lib/module/RTCSessionDescription.js @@ -0,0 +1,26 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +export default class RTCSessionDescription { + constructor() { + let info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { + type: null, + sdp: '' + }; + _defineProperty(this, "_sdp", void 0); + _defineProperty(this, "_type", void 0); + this._sdp = info.sdp; + this._type = info.type; + } + get sdp() { + return this._sdp; + } + get type() { + return this._type; + } + toJSON() { + return { + sdp: this._sdp, + type: this._type + }; + } +} +//# sourceMappingURL=RTCSessionDescription.js.map \ No newline at end of file diff --git a/lib/module/RTCSessionDescription.js.map b/lib/module/RTCSessionDescription.js.map new file mode 100644 index 000000000..90b4276ca --- /dev/null +++ b/lib/module/RTCSessionDescription.js.map @@ -0,0 +1 @@ +{"version":3,"names":["RTCSessionDescription","constructor","info","arguments","length","undefined","type","sdp","_defineProperty","_sdp","_type","toJSON"],"sources":["RTCSessionDescription.ts"],"sourcesContent":["\nexport interface RTCSessionDescriptionInit {\n sdp: string;\n type: string | null;\n}\n\nexport default class RTCSessionDescription {\n _sdp: string;\n _type: string | null;\n\n constructor(info: RTCSessionDescriptionInit = { type: null, sdp: '' }) {\n this._sdp = info.sdp;\n this._type = info.type;\n }\n\n get sdp(): string {\n return this._sdp;\n }\n\n get type(): string | null {\n return this._type;\n }\n\n toJSON(): RTCSessionDescriptionInit {\n return {\n sdp: this._sdp,\n type: this._type\n };\n }\n}\n"],"mappings":";AAMA,eAAe,MAAMA,qBAAqB,CAAC;EAIvCC,WAAWA,CAAA,EAA4D;IAAA,IAA3DC,IAA+B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;MAAEG,IAAI,EAAE,IAAI;MAAEC,GAAG,EAAE;IAAG,CAAC;IAAAC,eAAA;IAAAA,eAAA;IACjE,IAAI,CAACC,IAAI,GAAGP,IAAI,CAACK,GAAG;IACpB,IAAI,CAACG,KAAK,GAAGR,IAAI,CAACI,IAAI;EAC1B;EAEA,IAAIC,GAAGA,CAAA,EAAW;IACd,OAAO,IAAI,CAACE,IAAI;EACpB;EAEA,IAAIH,IAAIA,CAAA,EAAkB;IACtB,OAAO,IAAI,CAACI,KAAK;EACrB;EAEAC,MAAMA,CAAA,EAA8B;IAChC,OAAO;MACHJ,GAAG,EAAE,IAAI,CAACE,IAAI;MACdH,IAAI,EAAE,IAAI,CAACI;IACf,CAAC;EACL;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCTrackEvent.js b/lib/module/RTCTrackEvent.js new file mode 100644 index 000000000..b582ea8c4 --- /dev/null +++ b/lib/module/RTCTrackEvent.js @@ -0,0 +1,31 @@ +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } +import { Event } from 'event-target-shim/index'; +/** + * @eventClass + * This event is fired whenever the Track is changed in PeerConnection. + * @param {TRACK_EVENTS} type - The type of event. + * @param {IRTCTrackEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/track_event MDN} for details. + */ +export default class RTCTrackEvent extends Event { + /** @eventProperty */ + + /** @eventProperty */ + + /** @eventProperty */ + + /** @eventProperty */ + + constructor(type, eventInitDict) { + super(type, eventInitDict); + _defineProperty(this, "streams", []); + _defineProperty(this, "transceiver", void 0); + _defineProperty(this, "receiver", void 0); + _defineProperty(this, "track", void 0); + this.streams = eventInitDict.streams; + this.transceiver = eventInitDict.transceiver; + this.receiver = eventInitDict.transceiver.receiver; + this.track = eventInitDict.transceiver.receiver ? eventInitDict.transceiver.receiver.track : null; + } +} +//# sourceMappingURL=RTCTrackEvent.js.map \ No newline at end of file diff --git a/lib/module/RTCTrackEvent.js.map b/lib/module/RTCTrackEvent.js.map new file mode 100644 index 000000000..14ff93240 --- /dev/null +++ b/lib/module/RTCTrackEvent.js.map @@ -0,0 +1 @@ +{"version":3,"names":["Event","RTCTrackEvent","constructor","type","eventInitDict","_defineProperty","streams","transceiver","receiver","track"],"sources":["RTCTrackEvent.ts"],"sourcesContent":["import { Event } from 'event-target-shim/index';\n\nimport MediaStream from './MediaStream';\nimport type MediaStreamTrack from './MediaStreamTrack';\nimport RTCRtpReceiver from './RTCRtpReceiver';\nimport RTCRtpTransceiver from './RTCRtpTransceiver';\n\ntype TRACK_EVENTS = 'track'\n\ninterface IRTCTrackEventInitDict extends Event.EventInit {\n streams: MediaStream[]\n transceiver: RTCRtpTransceiver\n}\n\n/**\n * @eventClass\n * This event is fired whenever the Track is changed in PeerConnection.\n * @param {TRACK_EVENTS} type - The type of event.\n * @param {IRTCTrackEventInitDict} eventInitDict - The event init properties.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/track_event MDN} for details.\n */\nexport default class RTCTrackEvent extends Event {\n /** @eventProperty */\n readonly streams: MediaStream[] = [];\n\n /** @eventProperty */\n readonly transceiver: RTCRtpTransceiver;\n\n /** @eventProperty */\n readonly receiver: RTCRtpReceiver | null;\n\n /** @eventProperty */\n readonly track: MediaStreamTrack | null;\n\n constructor(type: TEventType, eventInitDict: IRTCTrackEventInitDict) {\n super(type, eventInitDict);\n this.streams = eventInitDict.streams;\n this.transceiver = eventInitDict.transceiver;\n this.receiver = eventInitDict.transceiver.receiver;\n this.track = eventInitDict.transceiver.receiver ? eventInitDict.transceiver.receiver.track : null;\n }\n}\n"],"mappings":";AAAA,SAASA,KAAK,QAAQ,yBAAyB;AAc/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,aAAa,SAA0CD,KAAK,CAAa;EAC1F;;EAGA;;EAGA;;EAGA;;EAGAE,WAAWA,CAACC,IAAgB,EAAEC,aAAqC,EAAE;IACjE,KAAK,CAACD,IAAI,EAAEC,aAAa,CAAC;IAACC,eAAA,kBAZG,EAAE;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAahC,IAAI,CAACC,OAAO,GAAGF,aAAa,CAACE,OAAO;IACpC,IAAI,CAACC,WAAW,GAAGH,aAAa,CAACG,WAAW;IAC5C,IAAI,CAACC,QAAQ,GAAGJ,aAAa,CAACG,WAAW,CAACC,QAAQ;IAClD,IAAI,CAACC,KAAK,GAAGL,aAAa,CAACG,WAAW,CAACC,QAAQ,GAAGJ,aAAa,CAACG,WAAW,CAACC,QAAQ,CAACC,KAAK,GAAG,IAAI;EACrG;AACJ"} \ No newline at end of file diff --git a/lib/module/RTCUtil.js b/lib/module/RTCUtil.js new file mode 100644 index 000000000..2d4f40bf5 --- /dev/null +++ b/lib/module/RTCUtil.js @@ -0,0 +1,176 @@ +const DEFAULT_AUDIO_CONSTRAINTS = {}; +const DEFAULT_VIDEO_CONSTRAINTS = { + facingMode: 'user', + frameRate: 30, + height: 720, + width: 1280 +}; +const FACING_MODES = ['user', 'environment']; +const ASPECT_RATIO = 16 / 9; +const STANDARD_OFFER_OPTIONS = { + icerestart: 'IceRestart', + offertoreceiveaudio: 'OfferToReceiveAudio', + offertoreceivevideo: 'OfferToReceiveVideo', + voiceactivitydetection: 'VoiceActivityDetection' +}; +const SDP_TYPES = ['offer', 'pranswer', 'answer', 'rollback']; +function getDefaultMediaConstraints(mediaType) { + switch (mediaType) { + case 'audio': + return DEFAULT_AUDIO_CONSTRAINTS; + case 'video': + return DEFAULT_VIDEO_CONSTRAINTS; + default: + throw new TypeError(`Invalid media type: ${mediaType}`); + } +} +function extractString(constraints, prop) { + const value = constraints[prop]; + const type = typeof value; + if (type === 'object') { + for (const v of ['exact', 'ideal']) { + if (value[v]) { + return value[v]; + } + } + } else if (type === 'string') { + return value; + } +} +function extractNumber(constraints, prop) { + const value = constraints[prop]; + const type = typeof value; + if (type === 'number') { + return Number.parseInt(value); + } else if (type === 'object') { + for (const v of ['exact', 'ideal', 'max', 'min']) { + if (value[v]) { + return Number.parseInt(value[v]); + } + } + } +} +function normalizeMediaConstraints(constraints, mediaType) { + switch (mediaType) { + case 'audio': + return constraints; + case 'video': + { + const c = { + deviceId: extractString(constraints, 'deviceId'), + facingMode: extractString(constraints, 'facingMode'), + frameRate: extractNumber(constraints, 'frameRate'), + height: extractNumber(constraints, 'height'), + width: extractNumber(constraints, 'width') + }; + if (!c.deviceId) { + delete c.deviceId; + } + if (!FACING_MODES.includes(c.facingMode)) { + c.facingMode = DEFAULT_VIDEO_CONSTRAINTS.facingMode; + } + if (!c.frameRate) { + c.frameRate = DEFAULT_VIDEO_CONSTRAINTS.frameRate; + } + if (!c.height && !c.width) { + c.height = DEFAULT_VIDEO_CONSTRAINTS.height; + c.width = DEFAULT_VIDEO_CONSTRAINTS.width; + } else if (!c.height && c.width) { + c.height = Math.round(c.width / ASPECT_RATIO); + } else if (!c.width && c.height) { + c.width = Math.round(c.height * ASPECT_RATIO); + } + return c; + } + default: + throw new TypeError(`Invalid media type: ${mediaType}`); + } +} + +/** + * Utility for creating short random strings from float point values. + * We take 4 characters from the end after converting to a string. + * Conversion to string gives us some letters as we don't want just numbers. + * Should be suitable to pass for enough randomness. + * + * @return {String} 4 random characters + */ +function chr4() { + return Math.random().toString(16).slice(-4); +} + +/** + * Put together a random string in UUIDv4 format {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} + * + * @return {String} uuidv4 + */ +export function uniqueID() { + return `${chr4()}${chr4()}-${chr4()}-${chr4()}-${chr4()}-${chr4()}${chr4()}${chr4()}`; +} + +/** + * Utility for deep cloning an object. Object.assign() only does a shallow copy. + * + * @param {Object} obj - object to be cloned + * @return {Object} cloned obj + */ +export function deepClone(obj) { + return JSON.parse(JSON.stringify(obj)); +} + +/** + * Checks whether an SDP type is valid or not. + * + * @param type SDP type to check. + * @returns Whether the SDP type is valid or not. + */ +export function isSdpTypeValid(type) { + return SDP_TYPES.includes(type); +} + +/** + * Normalize options passed to createOffer(). + * + * @param options - user supplied options + * @return Normalized options + */ +export function normalizeOfferOptions(options) { + const newOptions = {}; + if (typeof options !== 'object') { + return newOptions; + } + + // Convert standard options into WebRTC internal constant names. + // See: https://github.com/jitsi/webrtc/blob/0cd6ce4de669bed94ba47b88cb71b9be0341bb81/sdk/media_constraints.cc#L113 + for (const [key, value] of Object.entries(options)) { + const newKey = STANDARD_OFFER_OPTIONS[key.toLowerCase()]; + if (newKey) { + newOptions[newKey] = String(Boolean(value)); + } + } + return newOptions; +} + +/** + * Normalize the given constraints in something we can work with. + */ +export function normalizeConstraints(constraints) { + const c = deepClone(constraints); + for (const mediaType of ['audio', 'video']) { + const mediaTypeConstraints = c[mediaType]; + const typeofMediaTypeConstraints = typeof mediaTypeConstraints; + if (typeofMediaTypeConstraints !== 'undefined') { + if (typeofMediaTypeConstraints === 'boolean') { + if (mediaTypeConstraints) { + c[mediaType] = getDefaultMediaConstraints(mediaType); + } + } else if (typeofMediaTypeConstraints === 'object') { + c[mediaType] = normalizeMediaConstraints(mediaTypeConstraints, mediaType); + } else { + throw new TypeError(`constraints.${mediaType} is neither a boolean nor a dictionary`); + } + } + } + return c; +} +//# sourceMappingURL=RTCUtil.js.map \ No newline at end of file diff --git a/lib/module/RTCUtil.js.map b/lib/module/RTCUtil.js.map new file mode 100644 index 000000000..f0f9a4428 --- /dev/null +++ b/lib/module/RTCUtil.js.map @@ -0,0 +1 @@ +{"version":3,"names":["DEFAULT_AUDIO_CONSTRAINTS","DEFAULT_VIDEO_CONSTRAINTS","facingMode","frameRate","height","width","FACING_MODES","ASPECT_RATIO","STANDARD_OFFER_OPTIONS","icerestart","offertoreceiveaudio","offertoreceivevideo","voiceactivitydetection","SDP_TYPES","getDefaultMediaConstraints","mediaType","TypeError","extractString","constraints","prop","value","type","v","extractNumber","Number","parseInt","normalizeMediaConstraints","c","deviceId","includes","Math","round","chr4","random","toString","slice","uniqueID","deepClone","obj","JSON","parse","stringify","isSdpTypeValid","normalizeOfferOptions","options","newOptions","key","Object","entries","newKey","toLowerCase","String","Boolean","normalizeConstraints","mediaTypeConstraints","typeofMediaTypeConstraints"],"sources":["RTCUtil.ts"],"sourcesContent":["\nconst DEFAULT_AUDIO_CONSTRAINTS = {};\n\nconst DEFAULT_VIDEO_CONSTRAINTS = {\n facingMode: 'user',\n frameRate: 30,\n height: 720,\n width: 1280\n};\n\nconst FACING_MODES = [ 'user', 'environment' ];\n\nconst ASPECT_RATIO = 16 / 9;\n\nexport type RTCOfferOptions = {\n iceRestart?:boolean;\n offerToReceiveAudio?: boolean;\n offerToReceiveVideo?: boolean;\n voiceActivityDetection?:boolean\n};\n\nconst STANDARD_OFFER_OPTIONS = {\n icerestart: 'IceRestart',\n offertoreceiveaudio: 'OfferToReceiveAudio',\n offertoreceivevideo: 'OfferToReceiveVideo',\n voiceactivitydetection: 'VoiceActivityDetection'\n};\n\nconst SDP_TYPES = [\n 'offer',\n 'pranswer',\n 'answer',\n 'rollback'\n];\n\nfunction getDefaultMediaConstraints(mediaType) {\n switch (mediaType) {\n case 'audio':\n return DEFAULT_AUDIO_CONSTRAINTS;\n case 'video':\n return DEFAULT_VIDEO_CONSTRAINTS;\n default:\n throw new TypeError(`Invalid media type: ${mediaType}`);\n }\n}\n\nfunction extractString(constraints, prop) {\n const value = constraints[prop];\n const type = typeof value;\n\n if (type === 'object') {\n for (const v of [ 'exact', 'ideal' ]) {\n if (value[v]) {\n return value[v];\n }\n }\n } else if (type === 'string') {\n return value;\n }\n}\n\nfunction extractNumber(constraints, prop) {\n const value = constraints[prop];\n const type = typeof value;\n\n if (type === 'number') {\n return Number.parseInt(value);\n } else if (type === 'object') {\n for (const v of [ 'exact', 'ideal', 'max', 'min' ]) {\n if (value[v]) {\n return Number.parseInt(value[v]);\n }\n }\n }\n}\n\nfunction normalizeMediaConstraints(constraints, mediaType) {\n switch (mediaType) {\n case 'audio':\n return constraints;\n\n case 'video': {\n const c = {\n deviceId: extractString(constraints, 'deviceId'),\n facingMode: extractString(constraints, 'facingMode'),\n frameRate: extractNumber(constraints, 'frameRate'),\n height: extractNumber(constraints, 'height'),\n width: extractNumber(constraints, 'width')\n };\n\n if (!c.deviceId) {\n delete c.deviceId;\n }\n\n if (!FACING_MODES.includes(c.facingMode)) {\n c.facingMode = DEFAULT_VIDEO_CONSTRAINTS.facingMode;\n }\n\n if (!c.frameRate) {\n c.frameRate = DEFAULT_VIDEO_CONSTRAINTS.frameRate;\n }\n\n if (!c.height && !c.width) {\n c.height = DEFAULT_VIDEO_CONSTRAINTS.height;\n c.width = DEFAULT_VIDEO_CONSTRAINTS.width;\n } else if (!c.height && c.width) {\n c.height = Math.round(c.width / ASPECT_RATIO);\n } else if (!c.width && c.height) {\n c.width = Math.round(c.height * ASPECT_RATIO);\n }\n\n return c;\n }\n\n default:\n throw new TypeError(`Invalid media type: ${mediaType}`);\n }\n}\n\n/**\n * Utility for creating short random strings from float point values.\n * We take 4 characters from the end after converting to a string.\n * Conversion to string gives us some letters as we don't want just numbers.\n * Should be suitable to pass for enough randomness.\n *\n * @return {String} 4 random characters\n */\nfunction chr4() {\n return Math.random().toString(16).slice(-4);\n}\n\n/**\n * Put together a random string in UUIDv4 format {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\n *\n * @return {String} uuidv4\n */\nexport function uniqueID(): string {\n return `${chr4()}${chr4()}-${chr4()}-${chr4()}-${chr4()}-${chr4()}${chr4()}${chr4()}`;\n}\n\n/**\n * Utility for deep cloning an object. Object.assign() only does a shallow copy.\n *\n * @param {Object} obj - object to be cloned\n * @return {Object} cloned obj\n */\nexport function deepClone(obj: T): T {\n return JSON.parse(JSON.stringify(obj));\n}\n\n/**\n * Checks whether an SDP type is valid or not.\n *\n * @param type SDP type to check.\n * @returns Whether the SDP type is valid or not.\n */\nexport function isSdpTypeValid(type: string): boolean {\n return SDP_TYPES.includes(type);\n}\n\n/**\n * Normalize options passed to createOffer().\n *\n * @param options - user supplied options\n * @return Normalized options\n */\nexport function normalizeOfferOptions(options?: RTCOfferOptions) {\n const newOptions: Record = {};\n\n if (typeof options !== 'object') {\n return newOptions;\n }\n\n // Convert standard options into WebRTC internal constant names.\n // See: https://github.com/jitsi/webrtc/blob/0cd6ce4de669bed94ba47b88cb71b9be0341bb81/sdk/media_constraints.cc#L113\n for (const [ key, value ] of Object.entries(options)) {\n const newKey = STANDARD_OFFER_OPTIONS[key.toLowerCase()];\n\n if (newKey) {\n newOptions[newKey] = String(Boolean(value));\n }\n }\n\n return newOptions;\n}\n\n/**\n * Normalize the given constraints in something we can work with.\n */\nexport function normalizeConstraints(constraints) {\n const c = deepClone(constraints);\n\n for (const mediaType of [ 'audio', 'video' ]) {\n const mediaTypeConstraints = c[mediaType];\n const typeofMediaTypeConstraints = typeof mediaTypeConstraints;\n\n if (typeofMediaTypeConstraints !== 'undefined') {\n if (typeofMediaTypeConstraints === 'boolean') {\n if (mediaTypeConstraints) {\n c[mediaType] = getDefaultMediaConstraints(mediaType);\n }\n } else if (typeofMediaTypeConstraints === 'object') {\n c[mediaType] = normalizeMediaConstraints(mediaTypeConstraints, mediaType);\n } else {\n throw new TypeError(`constraints.${mediaType} is neither a boolean nor a dictionary`);\n }\n }\n }\n\n return c;\n}\n"],"mappings":"AACA,MAAMA,yB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AAC,GAAGW,yBAAyB,CAAC4B,oBAAoB,EAAEvC,SAAS,CAAC;MAC7E,CAAC,MAAM;QACH,MAAM,IAAIC,SAAS,CAAE,eAAcD,SAAU,wCAAuC,CAAC;MACzF;IACJ;EACJ;EAEA,OAAOY,CAAC;AACZ"} \ No newline at end of file diff --git a/lib/module/RTCView.js b/lib/module/RTCView.js new file mode 100644 index 000000000..b9617dc6a --- /dev/null +++ b/lib/module/RTCView.js @@ -0,0 +1,11 @@ +import { requireNativeComponent } from "react-native"; + +/** + * Native prop validation was removed from RN in: + * https://github.com/facebook/react-native/commit/8dc3ba0444c94d9bbb66295b5af885bff9b9cd34 + * + * So we list them here for documentation purposes. + */ + +export default requireNativeComponent("RTCVideoView"); +//# sourceMappingURL=RTCView.js.map \ No newline at end of file diff --git a/lib/module/RTCView.js.map b/lib/module/RTCView.js.map new file mode 100644 index 000000000..c0e974988 --- /dev/null +++ b/lib/module/RTCView.js.map @@ -0,0 +1 @@ +{"version":3,"names":["requireNativeComponent"],"sources":["RTCView.ts"],"sourcesContent":["import { requireNativeComponent, ViewProps } from \"react-native\";\n\n/**\n * Native prop validation was removed from RN in:\n * https://github.com/facebook/react-native/commit/8dc3ba0444c94d9bbb66295b5af885bff9b9cd34\n *\n * So we list them here for documentation purposes.\n */\nexport interface RTCVideoViewProps extends ViewProps {\n customScale?: number;\n customTranslateX?: number; // as fraction of width (-1 to 1)\n customTranslateY?: number; // as fraction of height (-1 to 1)\n useCustomTransform?: boolean;\n /**\n * Android only. When true, uses TextureViewRenderer instead of\n * SurfaceViewRenderer. TextureView renders in the normal View hierarchy\n * and supports borderRadius, overflow:hidden, and other clipping.\n * Slightly higher GPU overhead but negligible for small views.\n *\n * Defaults to false (SurfaceView).\n */\n useTextureView?: boolean;\n /**\n * Indicates whether the video specified by {@link #streamURL} should be\n * mirrored during rendering. Commonly, applications choose to mirror the\n * user-facing camera.\n *\n * mirror: boolean\n */\n mirror?: boolean;\n\n /**\n * In the fashion of\n * https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth\n * and https://www.w3.org/TR/html5/rendering.html#video-object-fit,\n * resembles the CSS style object-fit.\n *\n * objectFit: 'contain' | 'cover'\n *\n * Defaults to 'cover'.\n */\n objectFit?: \"contain\" | \"cover\";\n\n /**\n * URL / id of the stream that should be rendered.\n *\n * streamURL: string\n */\n streamURL?: string;\n /**\n * Similarly to the CSS property z-index, specifies the z-order of this\n * RTCView in the stacking space of all RTCViews. When RTCViews overlap,\n * zOrder determines which one covers the other. An RTCView with a larger\n * zOrder generally covers an RTCView with a lower one.\n *\n * Non-overlapping RTCViews may safely share a z-order (because one does not\n * have to cover the other).\n *\n * The support for zOrder is platform-dependent and/or\n * implementation-specific. Thus, specifying a value for zOrder is to be\n * thought of as giving a hint rather than as imposing a requirement. For\n * example, video renderers such as RTCView are commonly implemented using\n * OpenGL and OpenGL views may have different numbers of layers in their\n * stacking space. Android has three: a layer bellow the window (aka\n * default), a layer bellow the window again but above the previous layer\n * (aka media overlay), and above the window. Consequently, it is advisable\n * to limit the number of utilized layers in the stacking space to the\n * minimum sufficient for the desired display. For example, a video call\n * application usually needs a maximum of two zOrder values: 0 for the\n * remote video(s) which appear in the background, and 1 for the local\n * video(s) which appear above the remote video(s).\n *\n * zOrder: number\n */\n zOrder?: number;\n\n /**\n * Picture in picture options for this view. Disabled if not supplied.\n *\n * Note: this should only be generally only used with remote video tracks,\n * as the local camera may stop while in the background.\n *\n * iOS only. Requires iOS 15.0 or above, and the PIP background mode capability.\n */\n iosPIP?: RTCIOSPIPOptions;\n\n /**\n * Callback function that is called when the dimensions of the video change.\n *\n * @param {Object} event - The event object containing the new dimensions.\n * @param {Object} event.nativeEvent - The native event data.\n * @param {number} event.nativeEvent.width - The width of the video.\n * @param {number} event.nativeEvent.height - The height of the video.\n */\n onDimensionsChange?: (event: {\n nativeEvent: { width: number; height: number };\n }) => void;\n}\n\nexport interface RTCIOSPIPOptions {\n /**\n * Whether PIP can be launched from this view.\n *\n * Defaults to true.\n */\n enabled?: boolean;\n\n /**\n * The preferred size of the PIP window.\n */\n preferredSize?: {\n width: number;\n height: number;\n };\n\n /**\n * Indicates whether Picture in Picture starts automatically\n * when the controller embeds its content inline and the app\n * transitions to the background.\n *\n * Defaults to true.\n *\n * See: AVPictureInPictureController.canStartPictureInPictureAutomaticallyFromInline\n */\n startAutomatically?: boolean;\n\n /**\n * Indicates whether Picture in Picture should stop automatically\n * when the app returns to the foreground.\n *\n * Defaults to true.\n */\n stopAutomatically?: boolean;\n}\nexport default requireNativeComponent(\"RTCVideoView\");\n"],"mappings":"AAAA,SAASA,sBAAsB,QAAmB,cAAc;;AAEhE;AACA;AACA;AACA;AACA;AACA;;AA+HA,eAAeA,sBAAsB,CAAoB,cAAc,CAAC"} \ No newline at end of file diff --git a/lib/module/ScreenCapturePickerView.js b/lib/module/ScreenCapturePickerView.js new file mode 100644 index 000000000..7e0577ce9 --- /dev/null +++ b/lib/module/ScreenCapturePickerView.js @@ -0,0 +1,3 @@ +import { requireNativeComponent } from 'react-native'; +export default requireNativeComponent('ScreenCapturePickerView'); +//# sourceMappingURL=ScreenCapturePickerView.js.map \ No newline at end of file diff --git a/lib/module/ScreenCapturePickerView.js.map b/lib/module/ScreenCapturePickerView.js.map new file mode 100644 index 000000000..818f31260 --- /dev/null +++ b/lib/module/ScreenCapturePickerView.js.map @@ -0,0 +1 @@ +{"version":3,"names":["requireNativeComponent"],"sources":["ScreenCapturePickerView.ts"],"sourcesContent":["\nimport { requireNativeComponent } from 'react-native';\n\nexport default requireNativeComponent('ScreenCapturePickerView');\n"],"mappings":"AACA,SAASA,sBAAsB,QAAQ,cAAc;AAErD,eAAeA,sBAAsB,CAAC,yBAAyB,CAAC"} \ No newline at end of file diff --git a/lib/module/getDisplayMedia.js b/lib/module/getDisplayMedia.js new file mode 100644 index 000000000..4286157e8 --- /dev/null +++ b/lib/module/getDisplayMedia.js @@ -0,0 +1,26 @@ +import { NativeModules } from 'react-native'; +import MediaStream from './MediaStream'; +import MediaStreamError from './MediaStreamError'; +const { + WebRTCModule +} = NativeModules; +export default function getDisplayMedia() { + return new Promise((resolve, reject) => { + WebRTCModule.getDisplayMedia().then(data => { + const { + streamId, + track + } = data; + const info = { + streamId: streamId, + streamReactTag: streamId, + tracks: [track] + }; + const stream = new MediaStream(info); + resolve(stream); + }, error => { + reject(new MediaStreamError(error)); + }); + }); +} +//# sourceMappingURL=getDisplayMedia.js.map \ No newline at end of file diff --git a/lib/module/getDisplayMedia.js.map b/lib/module/getDisplayMedia.js.map new file mode 100644 index 000000000..96f9cf608 --- /dev/null +++ b/lib/module/getDisplayMedia.js.map @@ -0,0 +1 @@ +{"version":3,"names":["NativeModules","MediaStream","MediaStreamError","WebRTCModule","getDisplayMedia","Promise","resolve","reject","then","data","streamId","track","info","streamReactTag","tracks","stream","error"],"sources":["getDisplayMedia.ts"],"sourcesContent":["\nimport { NativeModules } from 'react-native';\n\nimport MediaStream from './MediaStream';\nimport MediaStreamError from './MediaStreamError';\n\nconst { WebRTCModule } = NativeModules;\n\nexport default function getDisplayMedia(): Promise {\n return new Promise((resolve, reject) => {\n WebRTCModule.getDisplayMedia().then(\n data => {\n const { streamId, track } = data;\n\n const info = {\n streamId: streamId,\n streamReactTag: streamId,\n tracks: [ track ]\n };\n\n const stream = new MediaStream(info);\n\n resolve(stream);\n },\n error => {\n reject(new MediaStreamError(error));\n }\n );\n });\n}\n"],"mappings":"AACA,SAASA,aAAa,QAAQ,cAAc;AAE5C,OAAOC,WAAW,MAAM,eAAe;AACvC,OAAOC,gBAAgB,MAAM,oBAAoB;AAEjD,MAAM;EAAEC;AAAa,CAAC,GAAGH,aAAa;AAEtC,eAAe,SAASI,eAAeA,CAAA,EAAyB;EAC5D,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACpCJ,YAAY,CAACC,eAAe,CAAC,CAAC,CAACI,IAAI,CAC/BC,IAAI,IAAI;MACJ,MAAM;QAAEC,QAAQ;QAAEC;MAAM,CAAC,GAAGF,IAAI;MAEhC,MAAMG,IAAI,GAAG;QACTF,QAAQ,EAAEA,QAAQ;QAClBG,cAAc,EAAEH,QAAQ;QACxBI,MAAM,EAAE,CAAEH,KAAK;MACnB,CAAC;MAED,MAAMI,MAAM,GAAG,IAAId,WAAW,CAACW,IAAI,CAAC;MAEpCN,OAAO,CAACS,MAAM,CAAC;IACnB,CAAC,EACDC,KAAK,IAAI;MACLT,MAAM,CAAC,IAAIL,gBAAgB,CAACc,KAAK,CAAC,CAAC;IACvC,CACJ,CAAC;EACL,CAAC,CAAC;AACN"} \ No newline at end of file diff --git a/lib/module/getUserMedia.js b/lib/module/getUserMedia.js new file mode 100644 index 000000000..65c755f6e --- /dev/null +++ b/lib/module/getUserMedia.js @@ -0,0 +1,92 @@ +import { NativeModules } from 'react-native'; +import MediaStream from './MediaStream'; +import MediaStreamError from './MediaStreamError'; +import permissions from './Permissions'; +import * as RTCUtil from './RTCUtil'; +const { + WebRTCModule +} = NativeModules; +export default function getUserMedia() { + let constraints = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + // According to + // https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia, + // the constraints argument is a dictionary of type MediaStreamConstraints. + if (typeof constraints !== 'object') { + return Promise.reject(new TypeError('constraints is not a dictionary')); + } + if ((typeof constraints.audio === 'undefined' || !constraints.audio) && (typeof constraints.video === 'undefined' || !constraints.video)) { + return Promise.reject(new TypeError('audio and/or video is required')); + } + + // Normalize constraints. + constraints = RTCUtil.normalizeConstraints(constraints); + + // Request required permissions + const reqPermissions = []; + if (constraints.audio) { + reqPermissions.push(permissions.request({ + name: 'microphone' + })); + } else { + reqPermissions.push(Promise.resolve(false)); + } + if (constraints.video) { + reqPermissions.push(permissions.request({ + name: 'camera' + })); + } else { + reqPermissions.push(Promise.resolve(false)); + } + return new Promise((resolve, reject) => { + Promise.all(reqPermissions).then(results => { + const [audioPerm, videoPerm] = results; + + // Check permission results and remove unneeded permissions. + + if (!audioPerm && !videoPerm) { + // https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia + // step 4 + const error = { + message: 'Permission denied.', + name: 'SecurityError' + }; + reject(new MediaStreamError(error)); + return; + } + audioPerm || delete constraints.audio; + videoPerm || delete constraints.video; + const success = (id, tracks) => { + // Store initial constraints. + for (const trackInfo of tracks) { + const c = constraints[trackInfo.kind]; + if (typeof c === 'object') { + trackInfo.constraints = RTCUtil.deepClone(c); + } + } + const info = { + streamId: id, + streamReactTag: id, + tracks + }; + resolve(new MediaStream(info)); + }; + const failure = (type, message) => { + let error; + switch (type) { + case 'TypeError': + error = new TypeError(message); + break; + } + if (!error) { + error = new MediaStreamError({ + message, + name: type + }); + } + reject(error); + }; + WebRTCModule.getUserMedia(constraints, success, failure); + }); + }); +} +//# sourceMappingURL=getUserMedia.js.map \ No newline at end of file diff --git a/lib/module/getUserMedia.js.map b/lib/module/getUserMedia.js.map new file mode 100644 index 000000000..5d0e8ff7c --- /dev/null +++ b/lib/module/getUserMedia.js.map @@ -0,0 +1 @@ +{"version":3,"names":["NativeModules","MediaStream","MediaStreamError","permissions","RTCUtil","WebRTCModule","getUserMedia","constraints","arguments","length","undefined","Promise","reject","TypeError","audio","video","normalizeConstraints","reqPermissions","push","request","name","resolve","all","then","results","audioPerm","videoPerm","error","message","success","id","tracks","trackInfo","c","kind","deepClone","info","streamId","streamReactTag","failure","type"],"sources":["getUserMedia.ts"],"sourcesContent":["\nimport { NativeModules } from 'react-native';\n\n\nimport { MediaTrackConstraints } from './Constraints';\nimport MediaStream from './MediaStream';\nimport MediaStreamError from './MediaStreamError';\nimport permissions from './Permissions';\nimport * as RTCUtil from './RTCUtil';\n\nconst { WebRTCModule } = NativeModules;\n\nexport interface Constraints {\n audio?: boolean | MediaTrackConstraints;\n video?: boolean | MediaTrackConstraints;\n}\n\nexport default function getUserMedia(constraints: Constraints = {}): Promise {\n // According to\n // https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia,\n // the constraints argument is a dictionary of type MediaStreamConstraints.\n if (typeof constraints !== 'object') {\n return Promise.reject(new TypeError('constraints is not a dictionary'));\n }\n\n if (\n (typeof constraints.audio === 'undefined' || !constraints.audio) &&\n (typeof constraints.video === 'undefined' || !constraints.video)\n ) {\n return Promise.reject(new TypeError('audio and/or video is required'));\n }\n\n // Normalize constraints.\n constraints = RTCUtil.normalizeConstraints(constraints);\n\n // Request required permissions\n const reqPermissions: Promise[] = [];\n\n if (constraints.audio) {\n reqPermissions.push(permissions.request({ name: 'microphone' }));\n } else {\n reqPermissions.push(Promise.resolve(false));\n }\n\n if (constraints.video) {\n reqPermissions.push(permissions.request({ name: 'camera' }));\n } else {\n reqPermissions.push(Promise.resolve(false));\n }\n\n return new Promise((resolve, reject) => {\n Promise.all(reqPermissions).then(results => {\n const [ audioPerm, videoPerm ] = results;\n\n // Check permission results and remove unneeded permissions.\n\n if (!audioPerm && !videoPerm) {\n // https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia\n // step 4\n const error = {\n message: 'Permission denied.',\n name: 'SecurityError'\n };\n\n reject(new MediaStreamError(error));\n\n return;\n }\n\n audioPerm || delete constraints.audio;\n videoPerm || delete constraints.video;\n\n const success = (id, tracks) => {\n // Store initial constraints.\n for (const trackInfo of tracks) {\n const c = constraints[trackInfo.kind];\n\n if (typeof c === 'object') {\n trackInfo.constraints = RTCUtil.deepClone(c);\n }\n }\n\n const info = {\n streamId: id,\n streamReactTag: id,\n tracks\n };\n\n resolve(new MediaStream(info));\n };\n\n const failure = (type, message) => {\n let error;\n\n switch (type) {\n case 'TypeError':\n error = new TypeError(message);\n break;\n }\n\n if (!error) {\n error = new MediaStreamError({ message, name: type });\n }\n\n reject(error);\n };\n\n WebRTCModule.getUserMedia(constraints, success, failure);\n });\n });\n}\n"],"mappings":"AACA,SAASA,aAAa,QAAQ,cAAc;AAI5C,OAAOC,WAAW,MAAM,eAAe;AACvC,OAAOC,gBAAgB,MAAM,oBAAoB;AACjD,OA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ER,IAAI,EAAEoB;UAAK,CAAC,CAAC;QACzD;QAEA5B,MAAM,CAACe,KAAK,CAAC;MACjB,CAAC;MAEDtB,YAAY,CAACC,YAAY,CAACC,WAAW,EAAEsB,OAAO,EAAEU,OAAO,CAAC;IAC5D,CAAC,CAAC;EACN,CAAC,CAAC;AACN"} \ No newline at end of file diff --git a/lib/module/index.js b/lib/module/index.js new file mode 100644 index 000000000..e845c6245 --- /dev/null +++ b/lib/module/index.js @@ -0,0 +1,58 @@ +import { NativeModules, Platform } from 'react-native'; +const { + WebRTCModule +} = NativeModules; +if (WebRTCModule === null) { + throw new Error(`WebRTC native module not found.\n${Platform.OS === 'ios' ? 'Try executing the "pod install" command inside your projects ios folder.' : 'Try executing the "npm install" command inside your projects folder.'}`); +} +import { setupNativeEvents } from './EventEmitter'; +import Logger from './Logger'; +import mediaDevices from './MediaDevices'; +import MediaStream from './MediaStream'; +import MediaStreamTrack from './MediaStreamTrack'; +import MediaStreamTrackEvent from './MediaStreamTrackEvent'; +import permissions from './Permissions'; +import RTCAudioSession from './RTCAudioSession'; +import RTCErrorEvent from './RTCErrorEvent'; +import RTCFrameCryptor, { RTCFrameCryptorState } from './RTCFrameCryptor'; +import RTCFrameCryptorFactory, { RTCFrameCryptorAlgorithm, RTCKeyProviderOptions } from './RTCFrameCryptorFactory'; +import RTCIceCandidate from './RTCIceCandidate'; +import RTCKeyProvider from './RTCKeyProvider'; +import RTCPIPView, { startIOSPIP, stopIOSPIP } from './RTCPIPView'; +import RTCPeerConnection from './RTCPeerConnection'; +import RTCRtpReceiver from './RTCRtpReceiver'; +import RTCRtpSender from './RTCRtpSender'; +import RTCRtpTransceiver from './RTCRtpTransceiver'; +import RTCSessionDescription from './RTCSessionDescription'; +import RTCView from './RTCView'; +import ScreenCapturePickerView from './ScreenCapturePickerView'; +Logger.enable(`${Logger.ROOT_PREFIX}:*`); + +// Add listeners for the native events early, since they are added asynchronously. +setupNativeEvents(); +export { RTCIceCandidate, RTCPeerConnection, RTCSessionDescription, RTCView, RTCPIPView, ScreenCapturePickerView, RTCRtpTransceiver, RTCRtpReceiver, RTCRtpSender, RTCErrorEvent, RTCAudioSession, RTCFrameCryptor, RTCFrameCryptorAlgorithm, RTCFrameCryptorState, RTCFrameCryptorFactory, RTCKeyProvider, RTCKeyProviderOptions, MediaStream, MediaStreamTrack, mediaDevices, permissions, registerGlobals, startIOSPIP, stopIOSPIP }; +function registerGlobals() { + // Should not happen. React Native has a global navigator object. + if (typeof global.navigator !== 'object') { + throw new Error('navigator is not an object'); + } + if (!global.navigator.mediaDevices) { + global.navigator.mediaDevices = {}; + } + global.navigator.mediaDevices.getUserMedia = mediaDevices.getUserMedia.bind(mediaDevices); + global.navigator.mediaDevices.getDisplayMedia = mediaDevices.getDisplayMedia.bind(mediaDevices); + global.navigator.mediaDevices.enumerateDevices = mediaDevices.enumerateDevices.bind(mediaDevices); + global.RTCIceCandidate = RTCIceCandidate; + global.RTCPeerConnection = RTCPeerConnection; + global.RTCRtpReceiver = RTCRtpReceiver; + global.RTCRtpSender = RTCRtpReceiver; + global.RTCSessionDescription = RTCSessionDescription; + global.MediaStream = MediaStream; + global.MediaStreamTrack = MediaStreamTrack; + global.MediaStreamTrackEvent = MediaStreamTrackEvent; + global.RTCRtpTransceiver = RTCRtpTransceiver; + global.RTCRtpReceiver = RTCRtpReceiver; + global.RTCRtpSender = RTCRtpSender; + global.RTCErrorEvent = RTCErrorEvent; +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/module/index.js.map b/lib/module/index.js.map new file mode 100644 index 000000000..ab3653c40 --- /dev/null +++ b/lib/module/index.js.map @@ -0,0 +1 @@ +{"version":3,"names":["NativeModules","Platform","WebRTCModule","Error","OS","setupNativeEvents","Logger","mediaDevices","MediaStream","MediaStreamTrack","MediaStreamTrackEvent","permissions","RTCAudioSession","RTCErrorEvent","RTCFrameCryptor","RTCFrameCryptorState","RTCFrameCryptorFactory","RTCFrameCryptorAlgorithm","RTCKeyProviderOptions","RTCIceCandidate","RTCKeyProvider","RTCPIPView","startIOSPIP","stopIOSPIP","RTCPeerConnection","RTCRtpReceiver","RTCRtpSender","RTCRtpTransceiver","RTCSessionDescription","RTCView","ScreenCapturePickerView","enable","ROOT_PREFIX","registerGlobals","global","navigator","getUserMedia","bind","getDisplayMedia","enumerateDevices"],"sources":["index.ts"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\nconst { WebRTCModule } = NativeModules;\n\nif (WebRTCModule === null) {\n throw new Error(`WebRTC native module not found.\\n${Platform.OS === 'ios' ?\n 'Try executing the \"pod install\" command inside your projects ios folder.' :\n 'Try executing the \"npm install\" command inside your projects folder.'\n }`);\n}\n\nimport { setupNativeEvents } from './EventEmitter';\nimport Logger from './Logger';\nimport mediaDevices from './MediaDevices';\nimport MediaStream from './MediaStream';\nimport MediaStreamTrack, { type MediaTrackSettings } from './MediaStreamTrack';\nimport MediaStreamTrackEvent from './MediaStreamTrackEvent';\nimport permissions from './Permissions';\nimport RTCAudioSession from './RTCAudioSession';\nimport RTCErrorEvent from './RTCErrorEvent';\nimport RTCFrameCryptor, { RTCFrameCryptorState } from './RTCFrameCryptor';\nimport RTCFrameCryptorFactory, { RTCFrameCryptorAlgorithm, RTCKeyProviderOptions } from './RTCFrameCryptorFactory';\nimport RTCIceCandidate from './RTCIceCandidate';\nimport RTCKeyProvider from './RTCKeyProvider';\nimport RTCPIPView, { startIOSPIP, stopIOSPIP } from './RTCPIPView';\nimport RTCPeerConnection from './RTCPeerConnection';\nimport RTCRtpReceiver from './RTCRtpReceiver';\nimport RTCRtpSender from './RTCRtpSender';\nimport RTCRtpTransceiver from './RTCRtpTransceiver';\nimport RTCSessionDescription from './RTCSessionDescription';\nimport RTCView, { type RTCVideoViewProps, type RTCIOSPIPOptions } from './RTCView';\nimport ScreenCapturePickerView from './ScreenCapturePickerView';\n\nLogger.enable(`${Logger.ROOT_PREFIX}:*`);\n\n// Add listeners for the native events early, since they are added asynchronously.\nsetupNativeEvents();\n\nexport {\n RTCIceCandidate,\n RTCPeerConnection,\n RTCSessionDescription,\n RTCView,\n RTCPIPView,\n ScreenCapturePickerView,\n RTCRtpTransceiver,\n RTCRtpReceiver,\n RTCRtpSender,\n RTCErrorEvent,\n RTCAudioSession,\n RTCFrameCryptor,\n RTCFrameCryptorAlgorithm,\n RTCFrameCryptorState,\n RTCFrameCryptorFactory,\n RTCKeyProvider,\n RTCKeyProviderOptions,\n MediaStream,\n MediaStreamTrack,\n type MediaTrackSettings,\n type RTCVideoViewProps,\n type RTCIOSPIPOptions,\n mediaDevices,\n permissions,\n registerGlobals,\n startIOSPIP,\n stopIOSPIP,\n};\n\ndeclare const global: any;\n\nfunction registerGlobals(): void {\n // Should not happen. React Native has a global navigator object.\n if (typeof global.navigator !== 'object') {\n throw new Error('navigator is not an object');\n }\n\n if (!global.navigator.mediaDevices) {\n global.navigator.mediaDevices = {};\n }\n\n global.navigator.mediaDevices.getUserMedia = mediaDevices.getUserMedia.bind(mediaDevices);\n global.navigator.mediaDevices.getDisplayMedia = mediaDevices.getDisplayMedia.bind(mediaDevices);\n global.navigator.mediaDevices.enumerateDevices = mediaDevices.enumerateDevices.bind(mediaDevices);\n\n global.RTCIceCandidate = RTCIceCandidate;\n global.RTCPeerConnection = RTCPeerConnection;\n global.RTCRtpReceiver = RTCRtpReceiver;\n global.RTCRtpSender = RTCRtpReceiver;\n global.RTCSessionDescription = RTCSessionDescription;\n global.MediaStream = MediaStream;\n global.MediaStreamTrack = MediaStreamTrack;\n global.MediaStreamTrackEvent = MediaStreamTrackEvent;\n global.RTCRtpTransceiver = RTCRtpTransceiver;\n global.RTCRtpReceiver = RTCRtpReceiver;\n global.RTCRtpSender = RTCRtpSender;\n global.RTCErrorEvent = RTCErrorEvent;\n}\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AACtD,MAAM;EAAEC;AAAa,CAAC,GAAGF,aAAa;AAEtC,IAAIE,YAAY,KAAK,IAAI,EAAE;EACvB,MAA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Aa,GAAGA,aAAa;AACxC"} \ No newline at end of file diff --git a/lib/typescript/Constraints.d.ts b/lib/typescript/Constraints.d.ts new file mode 100644 index 000000000..1010e3875 --- /dev/null +++ b/lib/typescript/Constraints.d.ts @@ -0,0 +1,19 @@ +export declare type MediaTrackConstraints = { + width?: ConstrainNumber; + height?: ConstrainNumber; + frameRate?: ConstrainNumber; + facingMode?: ConstrainString; + deviceId?: ConstrainString; + groupId?: ConstrainString; +}; +declare type ConstrainNumber = number | { + exact?: number; + ideal?: number; + max?: number; + min?: number; +}; +declare type ConstrainString = string | { + exact?: string; + ideal?: string; +}; +export {}; diff --git a/lib/typescript/EventEmitter.d.ts b/lib/typescript/EventEmitter.d.ts new file mode 100644 index 000000000..f4cd8ddde --- /dev/null +++ b/lib/typescript/EventEmitter.d.ts @@ -0,0 +1,6 @@ +export declare function setupNativeEvents(): void; +declare type EventHandler = (event: unknown) => void; +declare type Listener = unknown; +export declare function addListener(listener: Listener, eventName: string, eventHandler: EventHandler): void; +export declare function removeListener(listener: Listener): void; +export {}; diff --git a/lib/typescript/Logger.d.ts b/lib/typescript/Logger.d.ts new file mode 100644 index 000000000..9cd469c88 --- /dev/null +++ b/lib/typescript/Logger.d.ts @@ -0,0 +1,13 @@ +export default class Logger { + static ROOT_PREFIX: string; + private _debug; + private _info; + private _warn; + private _error; + static enable(ns: string): void; + constructor(prefix: string); + debug(msg: string): void; + info(msg: string): void; + warn(msg: string): void; + error(msg: string, err?: Error): void; +} diff --git a/lib/typescript/MediaDevices.d.ts b/lib/typescript/MediaDevices.d.ts new file mode 100644 index 000000000..eac4e7322 --- /dev/null +++ b/lib/typescript/MediaDevices.d.ts @@ -0,0 +1,30 @@ +import { EventTarget, Event } from 'event-target-shim/index'; +import { Constraints } from './getUserMedia'; +declare type MediaDevicesEventMap = { + devicechange: Event<'devicechange'>; +}; +declare class MediaDevices extends EventTarget { + /** + * W3C "Media Capture and Streams" compatible {@code enumerateDevices} + * implementation. + */ + enumerateDevices(): Promise; + /** + * W3C "Screen Capture" compatible {@code getDisplayMedia} implementation. + * See: https://w3c.github.io/mediacapture-screen-share/ + * + * @returns {Promise} + */ + getDisplayMedia(): Promise; + /** + * W3C "Media Capture and Streams" compatible {@code getUserMedia} + * implementation. + * See: https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-enumeratedevices + * + * @param {*} constraints + * @returns {Promise} + */ + getUserMedia(constraints: Constraints): Promise; +} +declare const _default: MediaDevices; +export default _default; diff --git a/lib/typescript/MediaStream.d.ts b/lib/typescript/MediaStream.d.ts new file mode 100644 index 000000000..1a3c0c45b --- /dev/null +++ b/lib/typescript/MediaStream.d.ts @@ -0,0 +1,48 @@ +import { EventTarget } from 'event-target-shim/index'; +import MediaStreamTrack, { MediaStreamTrackInfo } from './MediaStreamTrack'; +import MediaStreamTrackEvent from './MediaStreamTrackEvent'; +declare type MediaStreamEventMap = { + addtrack: MediaStreamTrackEvent<'addtrack'>; + removetrack: MediaStreamTrackEvent<'removetrack'>; +}; +export default class MediaStream extends EventTarget { + _tracks: MediaStreamTrack[]; + _id: string; + /** + * The identifier of this MediaStream unique within the associated + * WebRTCModule instance. As the id of a remote MediaStream instance is unique + * only within the associated RTCPeerConnection, it is not sufficiently unique + * to identify this MediaStream across multiple RTCPeerConnections and to + * unambiguously differentiate it from a local MediaStream instance not added + * to an RTCPeerConnection. + */ + _reactTag: string; + /** + * A MediaStream can be constructed in several ways, depending on the parameters + * that are passed here. + * + * - undefined: just a new stream, with no tracks. + * - MediaStream instance: a new stream, with a copy of the tracks of the passed stream. + * - Array of MediaStreamTrack: a new stream with a copy of the tracks in the array. + * - object: a new stream instance, represented by the passed info object, this is always + * done internally, when the stream is first created in native and the JS wrapper is + * built afterwards. + */ + constructor(arg?: MediaStream | MediaStreamTrack[] | { + streamId: string; + streamReactTag: string; + tracks: MediaStreamTrackInfo[]; + }); + get id(): string; + get active(): boolean; + addTrack(track: MediaStreamTrack): void; + removeTrack(track: MediaStreamTrack): void; + getTracks(): MediaStreamTrack[]; + getTrackById(trackId: any): MediaStreamTrack | undefined; + getAudioTracks(): MediaStreamTrack[]; + getVideoTracks(): MediaStreamTrack[]; + clone(): never; + toURL(): string; + release(releaseTracks?: boolean): void; +} +export {}; diff --git a/lib/typescript/MediaStreamError.d.ts b/lib/typescript/MediaStreamError.d.ts new file mode 100644 index 000000000..6893922ec --- /dev/null +++ b/lib/typescript/MediaStreamError.d.ts @@ -0,0 +1,6 @@ +export default class MediaStreamError { + name: string; + message?: string; + constraintName?: string; + constructor(error: any); +} diff --git a/lib/typescript/MediaStreamErrorEvent.d.ts b/lib/typescript/MediaStreamErrorEvent.d.ts new file mode 100644 index 000000000..79e687fea --- /dev/null +++ b/lib/typescript/MediaStreamErrorEvent.d.ts @@ -0,0 +1,6 @@ +import type MediaStreamError from './MediaStreamError'; +export default class MediaStreamErrorEvent { + type: string; + error?: MediaStreamError; + constructor(type: any, eventInitDict: any); +} diff --git a/lib/typescript/MediaStreamTrack.d.ts b/lib/typescript/MediaStreamTrack.d.ts new file mode 100644 index 000000000..cc1f6521a --- /dev/null +++ b/lib/typescript/MediaStreamTrack.d.ts @@ -0,0 +1,87 @@ +import { EventTarget, Event } from 'event-target-shim/index'; +import { MediaTrackConstraints } from './Constraints'; +declare type MediaStreamTrackState = 'live' | 'ended'; +export declare type MediaStreamTrackInfo = { + id: string; + kind: string; + remote: boolean; + constraints: object; + enabled: boolean; + settings: object; + peerConnectionId: number; + readyState: MediaStreamTrackState; +}; +export declare type MediaTrackSettings = { + width?: number; + height?: number; + frameRate?: number; + facingMode?: string; + deviceId?: string; + groupId?: string; +}; +declare type MediaStreamTrackEventMap = { + ended: Event<'ended'>; + mute: Event<'mute'>; + unmute: Event<'unmute'>; +}; +export default class MediaStreamTrack extends EventTarget { + _constraints: MediaTrackConstraints; + _enabled: boolean; + _settings: MediaTrackSettings; + _muted: boolean; + _peerConnectionId: number; + _readyState: MediaStreamTrackState; + readonly id: string; + readonly kind: string; + readonly label: string; + readonly remote: boolean; + constructor(info: MediaStreamTrackInfo); + get enabled(): boolean; + set enabled(enabled: boolean); + get muted(): boolean; + get readyState(): string; + stop(): void; + /** + * Private / custom API for switching the cameras on the fly, without the + * need for adding / removing tracks or doing any SDP renegotiation. + * + * This is how the reference application (AppRTCMobile) implements camera + * switching. + * + * @deprecated Use applyConstraints instead. + */ + _switchCamera(): void; + _setVideoEffects(names: string[]): void; + _setVideoEffect(name: string): void; + /** + * Internal function which is used to set the muted state on remote tracks and + * emit the mute / unmute event. + * + * @param muted Whether the track should be marked as muted / unmuted. + */ + _setMutedInternal(muted: boolean): void; + /** + * Custom API for setting the volume on an individual audio track. + * + * @param volume a gain value in the range of 0-10. defaults to 1.0 + */ + _setVolume(volume: number): void; + /** + * Applies a new set of constraints to the track. + * + * @param constraints An object listing the constraints + * to apply to the track's constrainable properties; any existing + * constraints are replaced with the new values specified, and any + * constrainable properties not included are restored to their default + * constraints. If this parameter is omitted, all currently set custom + * constraints are cleared. + */ + applyConstraints(constraints?: MediaTrackConstraints): Promise; + clone(): never; + getCapabilities(): never; + getConstraints(): MediaTrackConstraints; + getSettings(): MediaTrackSettings; + _registerEvents(): void; + release(): void; +} +export {}; diff --git a/lib/typescript/MediaStreamTrackEvent.d.ts b/lib/typescript/MediaStreamTrackEvent.d.ts new file mode 100644 index 000000000..18da83f51 --- /dev/null +++ b/lib/typescript/MediaStreamTrackEvent.d.ts @@ -0,0 +1,19 @@ +import { Event } from 'event-target-shim/index'; +import type MediaStreamTrack from './MediaStreamTrack'; +declare type MEDIA_STREAM_EVENTS = 'addtrack' | 'removetrack'; +interface IMediaStreamTrackEventInitDict extends Event.EventInit { + track: MediaStreamTrack; +} +/** + * @eventClass + * This event is fired whenever the MediaStreamTrack has changed in any way. + * @param {MEDIA_STREAM_EVENTS} type - The type of event. + * @param {IMediaStreamTrackEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaStream#events MDN} for details. + */ +export default class MediaStreamTrackEvent extends Event { + /** @eventProperty */ + track: MediaStreamTrack; + constructor(type: TEventType, eventInitDict: IMediaStreamTrackEventInitDict); +} +export {}; diff --git a/lib/typescript/MessageEvent.d.ts b/lib/typescript/MessageEvent.d.ts new file mode 100644 index 000000000..aa0f6be95 --- /dev/null +++ b/lib/typescript/MessageEvent.d.ts @@ -0,0 +1,21 @@ +/// +import { Event } from 'event-target-shim/index'; +export declare type MessageEventData = string | ArrayBuffer | Blob; +declare type MESSAGE_EVENTS = 'message' | 'messageerror'; +interface IMessageEventInitDict extends Event.EventInit { + data: MessageEventData; +} +/** + * @eventClass + * This event is fired whenever the RTCDataChannel send message. + * @param {MESSAGE_EVENTS} type - The type of event. + * @param {IMessageEventInitDict} eventInitDict - The event init properties. + * @see + * {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/message_event#event_type MDN} for details. + */ +export default class MessageEvent extends Event { + /** @eventProperty */ + data: MessageEventData; + constructor(type: TEventType, eventInitDict: IMessageEventInitDict); +} +export {}; diff --git a/lib/typescript/Permissions.d.ts b/lib/typescript/Permissions.d.ts new file mode 100644 index 000000000..1dc9bd8ad --- /dev/null +++ b/lib/typescript/Permissions.d.ts @@ -0,0 +1,55 @@ +import { Permission } from 'react-native'; +/** + * Type declaration for a permissions descriptor. + */ +declare type PermissionDescriptor = { + name: string; +}; +/** + * Class implementing a subset of W3C's Permissions API as defined by: + * https://www.w3.org/TR/permissions/ + */ +declare class Permissions { + /** + * Possible result values for {@link query}, in accordance with: + * https://www.w3.org/TR/permissions/#status-of-a-permission + */ + RESULT: { + DENIED: string; + GRANTED: string; + PROMPT: string; + }; + /** + * This implementation only supports requesting these permissions, a subset + * of: https://www.w3.org/TR/permissions/#permission-registry + */ + VALID_PERMISSIONS: string[]; + _lastReq: Promise; + /** + * Helper for requesting Android permissions. On Android only one permission + * can be requested at a time (unless the multi-permission API is used, + * but we are not using that for symmetry with the W3C API for querying) + * so we'll queue them up. + * + * @param perm - The requested permission from + * {@link PermissionsAndroid.PERMISSIONS} + * https://facebook.github.io/react-native/docs/permissionsandroid#permissions-that-require-prompting-the-user + */ + _requestPermissionAndroid(perm: Permission): Promise; + /** + * Validates the given permission descriptor. + */ + _validatePermissionDescriptior(permissionDesc: any): void; + /** + * Method for querying the status of a permission, according to: + * https://www.w3.org/TR/permissions/#permissions-interface + */ + query(permissionDesc: PermissionDescriptor): any; + /** + * Custom method NOT defined by W3C's permissions API, which allows the + * caller to request a permission. + */ + request(permissionDesc: PermissionDescriptor): any; +} +declare const _default: Permissions; +export default _default; diff --git a/lib/typescript/RTCAudioSession.d.ts b/lib/typescript/RTCAudioSession.d.ts new file mode 100644 index 000000000..38acc3b0d --- /dev/null +++ b/lib/typescript/RTCAudioSession.d.ts @@ -0,0 +1,10 @@ +export default class RTCAudioSession { + /** + * To be called when CallKit activates the audio session. + */ + static audioSessionDidActivate(): void; + /** + * To be called when CallKit deactivates the audio session. + */ + static audioSessionDidDeactivate(): void; +} diff --git a/lib/typescript/RTCDataChannel.d.ts b/lib/typescript/RTCDataChannel.d.ts new file mode 100644 index 000000000..82addbe2f --- /dev/null +++ b/lib/typescript/RTCDataChannel.d.ts @@ -0,0 +1,43 @@ +import { EventTarget } from 'event-target-shim/index'; +import MessageEvent from './MessageEvent'; +import RTCDataChannelEvent from './RTCDataChannelEvent'; +declare type RTCDataChannelState = 'connecting' | 'open' | 'closing' | 'closed'; +declare type DataChannelEventMap = { + bufferedamountlow: RTCDataChannelEvent<'bufferedamountlow'>; + close: RTCDataChannelEvent<'close'>; + closing: RTCDataChannelEvent<'closing'>; + error: RTCDataChannelEvent<'error'>; + message: MessageEvent<'message'>; + open: RTCDataChannelEvent<'open'>; +}; +export default class RTCDataChannel extends EventTarget { + _peerConnectionId: number; + _reactTag: string; + _bufferedAmount: number; + _id: number; + _label: string; + _maxPacketLifeTime?: number; + _maxRetransmits?: number; + _negotiated: boolean; + _ordered: boolean; + _protocol: string; + _readyState: RTCDataChannelState; + binaryType: string; + bufferedAmountLowThreshold: number; + constructor(info: any); + get bufferedAmount(): number; + get label(): string; + get id(): number; + get ordered(): boolean; + get maxPacketLifeTime(): number | undefined; + get maxRetransmits(): number | undefined; + get protocol(): string; + get negotiated(): boolean; + get readyState(): string; + send(data: string): void; + send(data: ArrayBuffer): void; + send(data: ArrayBufferView): void; + close(): void; + _registerEvents(): void; +} +export {}; diff --git a/lib/typescript/RTCDataChannelEvent.d.ts b/lib/typescript/RTCDataChannelEvent.d.ts new file mode 100644 index 000000000..5612c63e2 --- /dev/null +++ b/lib/typescript/RTCDataChannelEvent.d.ts @@ -0,0 +1,19 @@ +import { Event } from 'event-target-shim/index'; +import type RTCDataChannel from './RTCDataChannel'; +declare type DATA_CHANNEL_EVENTS = 'open' | 'message' | 'bufferedamountlow' | 'closing' | 'close' | 'error' | 'datachannel'; +interface IRTCDataChannelEventInitDict extends Event.EventInit { + channel: RTCDataChannel; +} +/** + * @eventClass + * This event is fired whenever the RTCDataChannel has changed in any way. + * @param {DATA_CHANNEL_EVENTS} type - The type of event. + * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel#events MDN} for details. + */ +export default class RTCDataChannelEvent extends Event { + /** @eventProperty */ + channel: RTCDataChannel; + constructor(type: TEventType, eventInitDict: IRTCDataChannelEventInitDict); +} +export {}; diff --git a/lib/typescript/RTCErrorEvent.d.ts b/lib/typescript/RTCErrorEvent.d.ts new file mode 100644 index 000000000..e52d54407 --- /dev/null +++ b/lib/typescript/RTCErrorEvent.d.ts @@ -0,0 +1,12 @@ +import { Event } from 'event-target-shim/index'; +declare type RTCPeerConnectionErrorFunc = 'addTransceiver' | 'getTransceivers' | 'addTrack' | 'removeTrack'; +/** + * @brief This class Represents internal error happening on the native side as + * part of asynchronous invocations to synchronous web APIs. + */ +export default class RTCErrorEvent extends Event { + readonly func: RTCPeerConnectionErrorFunc; + readonly message: string; + constructor(type: TEventType, func: RTCPeerConnectionErrorFunc, message: string); +} +export {}; diff --git a/lib/typescript/RTCFrameCryptor.d.ts b/lib/typescript/RTCFrameCryptor.d.ts new file mode 100644 index 000000000..9f492b0ef --- /dev/null +++ b/lib/typescript/RTCFrameCryptor.d.ts @@ -0,0 +1,47 @@ +import { Event, EventTarget } from 'event-target-shim/index'; +declare type FRAME_CRYPTOR_EVENTS = 'onframecryptorstatechanged'; +interface IRTCDataChannelEventInitDict extends Event.EventInit { + frameCryptor: RTCFrameCryptor; + state: RTCFrameCryptorState; +} +/** + * @eventClass + * This event is fired whenever the RTCDataChannel has changed in any way. + * @param {FRAME_CRYPTOR_EVENTS} type - The type of event. + * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel#events MDN} for details. + */ +export declare class RTCFrameCryptorStateEvent extends Event { + /** @eventProperty */ + frameCryptor: RTCFrameCryptor; + /** @eventProperty */ + state: RTCFrameCryptorState; + constructor(type: TEventType, eventInitDict: IRTCDataChannelEventInitDict); +} +declare type RTCFrameCryptorEventMap = { + onframecryptorstatechanged: RTCFrameCryptorStateEvent<'onframecryptorstatechanged'>; +}; +export declare enum RTCFrameCryptorState { + FrameCryptorStateNew = 0, + FrameCryptorStateOk = 1, + FrameCryptorStateEncryptionFailed = 2, + FrameCryptorStateDecryptionFailed = 3, + FrameCryptorStateMissingKey = 4, + FrameCryptorStateKeyRatcheted = 5, + FrameCryptorStateInternalError = 6 +} +export default class RTCFrameCryptor extends EventTarget { + private _frameCryptorId; + private _participantId; + constructor(frameCryptorId: string, participantId: string); + get id(): string; + get participantId(): string; + _cryptorStateFromString(str: string): RTCFrameCryptorState; + setKeyIndex(keyIndex: number): Promise; + getKeyIndex(): Promise; + setEnabled(enabled: boolean): Promise; + getEnabled(): Promise; + dispose(): Promise; + _registerEvents(): void; +} +export {}; diff --git a/lib/typescript/RTCFrameCryptorFactory.d.ts b/lib/typescript/RTCFrameCryptorFactory.d.ts new file mode 100644 index 000000000..e5ae31244 --- /dev/null +++ b/lib/typescript/RTCFrameCryptorFactory.d.ts @@ -0,0 +1,21 @@ +import RTCFrameCryptor from './RTCFrameCryptor'; +import RTCKeyProvider from './RTCKeyProvider'; +import RTCRtpReceiver from './RTCRtpReceiver'; +import RTCRtpSender from './RTCRtpSender'; +export declare enum RTCFrameCryptorAlgorithm { + kAesGcm = 0 +} +export declare type RTCKeyProviderOptions = { + sharedKey: boolean; + ratchetSalt: string | Uint8Array; + ratchetWindowSize: number; + uncryptedMagicBytes?: Uint8Array; + failureTolerance?: number; + keyRingSize?: number; + discardFrameWhenCryptorNotReady?: boolean; +}; +export default class RTCFrameCryptorFactory { + static createFrameCryptorForRtpSender(participantId: string, sender: RTCRtpSender, algorithm: RTCFrameCryptorAlgorithm, keyProvider: RTCKeyProvider): RTCFrameCryptor; + static createFrameCryptorForRtpReceiver(participantId: string, receiver: RTCRtpReceiver, algorithm: RTCFrameCryptorAlgorithm, keyProvider: RTCKeyProvider): RTCFrameCryptor; + static createDefaultKeyProvider(options: RTCKeyProviderOptions): RTCKeyProvider; +} diff --git a/lib/typescript/RTCIceCandidate.d.ts b/lib/typescript/RTCIceCandidate.d.ts new file mode 100644 index 000000000..f4b3a0b4a --- /dev/null +++ b/lib/typescript/RTCIceCandidate.d.ts @@ -0,0 +1,17 @@ +interface RTCIceCandidateInfo { + candidate?: string; + sdpMLineIndex?: number | null; + sdpMid?: string | null; +} +export default class RTCIceCandidate { + candidate: string; + sdpMLineIndex?: number | null; + sdpMid?: string | null; + constructor({ candidate, sdpMLineIndex, sdpMid }: RTCIceCandidateInfo); + toJSON(): { + candidate: string; + sdpMLineIndex: number | null | undefined; + sdpMid: string | null | undefined; + }; +} +export {}; diff --git a/lib/typescript/RTCIceCandidateEvent.d.ts b/lib/typescript/RTCIceCandidateEvent.d.ts new file mode 100644 index 000000000..518cbd563 --- /dev/null +++ b/lib/typescript/RTCIceCandidateEvent.d.ts @@ -0,0 +1,20 @@ +import { Event } from 'event-target-shim/index'; +import type RTCIceCandidate from './RTCIceCandidate'; +declare type RTC_ICECANDIDATE_EVENTS = 'icecandidate' | 'icecandidateerror'; +interface IRTCDataChannelEventInitDict extends Event.EventInit { + candidate: RTCIceCandidate | null; +} +/** + * @eventClass + * This event is fired whenever the icecandidate related RTC_EVENTS changed. + * @type {RTCIceCandidateEvent} for icecandidate related. + * @param {RTC_ICECANDIDATE_EVENTS} type - The type of event. + * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection#events MDN} for details. + */ +export default class RTCIceCandidateEvent extends Event { + /** @eventProperty */ + candidate: RTCIceCandidate | null; + constructor(type: TEventType, eventInitDict: IRTCDataChannelEventInitDict); +} +export {}; diff --git a/lib/typescript/RTCKeyProvider.d.ts b/lib/typescript/RTCKeyProvider.d.ts new file mode 100644 index 000000000..78badcca3 --- /dev/null +++ b/lib/typescript/RTCKeyProvider.d.ts @@ -0,0 +1,21 @@ +export declare enum FrameCryptorState { + FrameCryptorStateNew = 0, + FrameCryptorStateOk = 1, + FrameCryptorStateEncryptionFailed = 2, + FrameCryptorStateDecryptionFailed = 3, + FrameCryptorStateMissingKey = 4, + FrameCryptorStateKeyRatcheted = 5, + FrameCryptorStateInternalError = 6 +} +export default class RTCKeyProvider { + _id: string; + constructor(keyProviderId: string); + setSharedKey(key: string | Uint8Array, keyIndex?: number): Promise; + ratchetSharedKey(keyIndex?: number): Promise; + exportSharedKey(keyIndex?: number): Promise; + setKey(participantId: string, key: string | Uint8Array, keyIndex?: number): Promise; + ratchetKey(participantId: string, keyIndex?: number): Promise; + exportKey(participantId: string, keyIndex?: number): Promise; + setSifTrailer(trailer: Uint8Array): Promise; + dispose(): Promise; +} diff --git a/lib/typescript/RTCPIPView.d.ts b/lib/typescript/RTCPIPView.d.ts new file mode 100644 index 000000000..0ea9d683a --- /dev/null +++ b/lib/typescript/RTCPIPView.d.ts @@ -0,0 +1,15 @@ +import { Component } from 'react'; +import ReactNative from 'react-native'; +import { RTCIOSPIPOptions, RTCVideoViewProps } from './RTCView'; +export interface RTCPIPViewProps extends RTCVideoViewProps { + iosPIP?: RTCIOSPIPOptions & { + fallbackView?: Component; + }; +} +/** + * A convenience wrapper around RTCView to handle the fallback view as a prop. + */ +declare const RTCPIPView: import("react").ForwardRefExoticComponent & Readonly>>; +export declare function startIOSPIP(ref: any): void; +export declare function stopIOSPIP(ref: any): void; +export default RTCPIPView; diff --git a/lib/typescript/RTCPeerConnection.d.ts b/lib/typescript/RTCPeerConnection.d.ts new file mode 100644 index 000000000..c20fdba14 --- /dev/null +++ b/lib/typescript/RTCPeerConnection.d.ts @@ -0,0 +1,117 @@ +import { EventTarget, Event } from 'event-target-shim/index'; +import MediaStream from './MediaStream'; +import MediaStreamTrack from './MediaStreamTrack'; +import RTCDataChannel from './RTCDataChannel'; +import RTCDataChannelEvent from './RTCDataChannelEvent'; +import RTCIceCandidateEvent from './RTCIceCandidateEvent'; +import RTCRtpReceiver from './RTCRtpReceiver'; +import RTCRtpSender from './RTCRtpSender'; +import RTCRtpTransceiver from './RTCRtpTransceiver'; +import RTCSessionDescription, { RTCSessionDescriptionInit } from './RTCSessionDescription'; +import RTCTrackEvent from './RTCTrackEvent'; +import { RTCOfferOptions } from './RTCUtil'; +declare type RTCSignalingState = 'stable' | 'have-local-offer' | 'have-remote-offer' | 'have-local-pranswer' | 'have-remote-pranswer' | 'closed'; +declare type RTCIceGatheringState = 'new' | 'gathering' | 'complete'; +declare type RTCPeerConnectionState = 'new' | 'connecting' | 'connected' | 'disconnected' | 'failed' | 'closed'; +declare type RTCIceConnectionState = 'new' | 'checking' | 'connected' | 'completed' | 'failed' | 'disconnected' | 'closed'; +declare type RTCDataChannelInit = { + ordered?: boolean; + maxPacketLifeTime?: number; + maxRetransmits?: number; + protocol?: string; + negotiated?: boolean; + id?: number; +}; +declare type RTCIceServer = { + credential?: string; + url?: string; + urls?: string | string[]; + username?: string; +}; +declare type RTCConfiguration = { + bundlePolicy?: 'balanced' | 'max-compat' | 'max-bundle'; + iceCandidatePoolSize?: number; + iceServers?: RTCIceServer[]; + iceTransportPolicy?: 'all' | 'relay'; + rtcpMuxPolicy?: 'negotiate' | 'require'; +}; +declare type RTCPeerConnectionEventMap = { + connectionstatechange: Event<'connectionstatechange'>; + icecandidate: RTCIceCandidateEvent<'icecandidate'>; + icecandidateerror: RTCIceCandidateEvent<'icecandidateerror'>; + iceconnectionstatechange: Event<'iceconnectionstatechange'>; + icegatheringstatechange: Event<'icegatheringstatechange'>; + negotiationneeded: Event<'negotiationneeded'>; + signalingstatechange: Event<'signalingstatechange'>; + datachannel: RTCDataChannelEvent<'datachannel'>; + track: RTCTrackEvent<'track'>; + error: Event<'error'>; +}; +export default class RTCPeerConnection extends EventTarget { + localDescription: RTCSessionDescription | null; + remoteDescription: RTCSessionDescription | null; + signalingState: RTCSignalingState; + iceGatheringState: RTCIceGatheringState; + connectionState: RTCPeerConnectionState; + iceConnectionState: RTCIceConnectionState; + _pcId: number; + _transceivers: { + order: number; + transceiver: RTCRtpTransceiver; + }[]; + _remoteStreams: Map; + _pendingTrackEvents: any[]; + constructor(configuration?: RTCConfiguration); + createOffer(options?: RTCOfferOptions): Promise; + createAnswer(): Promise; + setConfiguration(configuration: any): void; + setLocalDescription(sessionDescription?: RTCSessionDescription | RTCSessionDescriptionInit): Promise; + setRemoteDescription(sessionDescription: RTCSessionDescription | RTCSessionDescriptionInit): Promise; + addIceCandidate(candidate: any): Promise; + /** + * @brief Adds a new track to the {@link RTCPeerConnection}, + * and indicates that it is contained in the specified {@link MediaStream}s. + * This method has to be synchronous as the W3C API expects a track to be returned + * @param {MediaStreamTrack} track The track to be added + * @param {...MediaStream} streams One or more {@link MediaStream}s the track needs to be added to + * https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack + */ + addTrack(track: MediaStreamTrack, ...streams: MediaStream[]): RTCRtpSender; + addTransceiver(source: 'audio' | 'video' | MediaStreamTrack, init: any): RTCRtpTransceiver; + removeTrack(sender: RTCRtpSender): void; + getStats(selector?: MediaStreamTrack): Promise; + getTransceivers(): RTCRtpTransceiver[]; + getSenders(): RTCRtpSender[]; + getReceivers(): RTCRtpReceiver[]; + close(): void; + restartIce(): void; + _registerEvents(): void; + /** + * Creates a new RTCDataChannel object with the given label. The + * RTCDataChannelInit dictionary can be used to configure properties of the + * underlying channel such as data reliability. + * + * @param {string} label - the value with which the label attribute of the new + * instance is to be initialized + * @param {RTCDataChannelInit} dataChannelDict - an optional dictionary of + * values with which to initialize corresponding attributes of the new + * instance such as id + */ + createDataChannel(label: string, dataChannelDict?: RTCDataChannelInit): RTCDataChannel; + /** + * Check whether a media stream track exists already in a sender. + * See https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack for more information + */ + _trackExists(track: MediaStreamTrack): boolean; + /** + * Updates transceivers after offer/answer updates if necessary. + */ + _updateTransceivers(transceiverUpdates: any, removeStopped?: boolean): void; + /** + * Inserts transceiver into the transceiver array in the order they are created (timestamp). + * @param order an index that refers to when it it was created relatively. + * @param transceiver the transceiver object to be inserted. + */ + _insertTransceiverSorted(order: number, transceiver: RTCRtpTransceiver): void; +} +export {}; diff --git a/lib/typescript/RTCRtcpParameters.d.ts b/lib/typescript/RTCRtcpParameters.d.ts new file mode 100644 index 000000000..af00051fe --- /dev/null +++ b/lib/typescript/RTCRtcpParameters.d.ts @@ -0,0 +1,10 @@ +export interface RTCRtcpParametersInit { + cname: string; + reducedSize: boolean; +} +export default class RTCRtcpParameters { + readonly cname: string; + readonly reducedSize: boolean; + constructor(init: RTCRtcpParametersInit); + toJSON(): RTCRtcpParametersInit; +} diff --git a/lib/typescript/RTCRtpCapabilities.d.ts b/lib/typescript/RTCRtpCapabilities.d.ts new file mode 100644 index 000000000..17b799fcd --- /dev/null +++ b/lib/typescript/RTCRtpCapabilities.d.ts @@ -0,0 +1,9 @@ +import RTCRtpCodecCapability from './RTCRtpCodecCapability'; +/** + * @brief represents codec capabilities for senders and receivers. + */ +export default class RTCRtpCapabilities { + _codecs: RTCRtpCodecCapability[]; + constructor(codecs: RTCRtpCodecCapability[]); + get codecs(): RTCRtpCodecCapability[]; +} diff --git a/lib/typescript/RTCRtpCodecCapability.d.ts b/lib/typescript/RTCRtpCodecCapability.d.ts new file mode 100644 index 000000000..8953e1238 --- /dev/null +++ b/lib/typescript/RTCRtpCodecCapability.d.ts @@ -0,0 +1,7 @@ +export default class RTCRtpCodecCapability { + _mimeType: string; + constructor(init: { + mimeType: string; + }); + get mimeType(): string; +} diff --git a/lib/typescript/RTCRtpCodecParameters.d.ts b/lib/typescript/RTCRtpCodecParameters.d.ts new file mode 100644 index 000000000..7e48c46a9 --- /dev/null +++ b/lib/typescript/RTCRtpCodecParameters.d.ts @@ -0,0 +1,16 @@ +export interface RTCRtpCodecParametersInit { + payloadType: number; + clockRate: number; + mimeType: string; + channels?: number; + sdpFmtpLine?: string; +} +export default class RTCRtpCodecParameters { + readonly payloadType: number; + readonly clockRate: number; + readonly mimeType: string; + readonly channels: number | null; + readonly sdpFmtpLine: string | null; + constructor(init: RTCRtpCodecParametersInit); + toJSON(): RTCRtpCodecParametersInit; +} diff --git a/lib/typescript/RTCRtpEncodingParameters.d.ts b/lib/typescript/RTCRtpEncodingParameters.d.ts new file mode 100644 index 000000000..234b3a067 --- /dev/null +++ b/lib/typescript/RTCRtpEncodingParameters.d.ts @@ -0,0 +1,23 @@ +export interface RTCRtpEncodingParametersInit { + active: boolean; + rid?: string; + maxFramerate?: number; + maxBitrate?: number; + scaleResolutionDownBy?: number; +} +export default class RTCRtpEncodingParameters { + active: boolean; + _rid: string | null; + _maxFramerate: number | null; + _maxBitrate: number | null; + _scaleResolutionDownBy: number | null; + constructor(init: RTCRtpEncodingParametersInit); + get rid(): string | null; + get maxFramerate(): number | null; + set maxFramerate(framerate: number | null); + get maxBitrate(): number | null; + set maxBitrate(bitrate: number | null); + get scaleResolutionDownBy(): number | null; + set scaleResolutionDownBy(resolutionScale: number | null); + toJSON(): RTCRtpEncodingParametersInit; +} diff --git a/lib/typescript/RTCRtpHeaderExtension.d.ts b/lib/typescript/RTCRtpHeaderExtension.d.ts new file mode 100644 index 000000000..1ad064a1f --- /dev/null +++ b/lib/typescript/RTCRtpHeaderExtension.d.ts @@ -0,0 +1,12 @@ +export interface RTCRtpHeaderExtensionInit { + id: number; + uri: string; + encrypted: boolean; +} +export default class RTCRtpHeaderExtension { + readonly id: number; + readonly uri: string; + readonly encrypted: boolean; + constructor(init: RTCRtpHeaderExtensionInit); + toJSON(): RTCRtpHeaderExtensionInit; +} diff --git a/lib/typescript/RTCRtpParameters.d.ts b/lib/typescript/RTCRtpParameters.d.ts new file mode 100644 index 000000000..112d1e43e --- /dev/null +++ b/lib/typescript/RTCRtpParameters.d.ts @@ -0,0 +1,19 @@ +import RTCRtcpParameters, { RTCRtcpParametersInit } from './RTCRtcpParameters'; +import RTCRtpCodecParameters, { RTCRtpCodecParametersInit } from './RTCRtpCodecParameters'; +import RTCRtpHeaderExtension, { RTCRtpHeaderExtensionInit } from './RTCRtpHeaderExtension'; +export interface RTCRtpParametersInit { + codecs: RTCRtpCodecParametersInit[]; + headerExtensions: RTCRtpHeaderExtensionInit[]; + rtcp: RTCRtcpParametersInit; +} +export default class RTCRtpParameters { + codecs: (RTCRtpCodecParameters | RTCRtpCodecParametersInit)[]; + readonly headerExtensions: RTCRtpHeaderExtension[]; + readonly rtcp: RTCRtcpParameters; + constructor(init: RTCRtpParametersInit); + toJSON(): { + codecs: (RTCRtpCodecParametersInit | RTCRtpCodecParameters)[]; + headerExtensions: RTCRtpHeaderExtension[]; + rtcp: RTCRtcpParameters; + }; +} diff --git a/lib/typescript/RTCRtpReceiveParameters.d.ts b/lib/typescript/RTCRtpReceiveParameters.d.ts new file mode 100644 index 000000000..81c1e8d1a --- /dev/null +++ b/lib/typescript/RTCRtpReceiveParameters.d.ts @@ -0,0 +1,4 @@ +import RTCRtpParameters, { RTCRtpParametersInit } from './RTCRtpParameters'; +export default class RTCRtpReceiveParameters extends RTCRtpParameters { + constructor(init: RTCRtpParametersInit); +} diff --git a/lib/typescript/RTCRtpReceiver.d.ts b/lib/typescript/RTCRtpReceiver.d.ts new file mode 100644 index 000000000..41fb95378 --- /dev/null +++ b/lib/typescript/RTCRtpReceiver.d.ts @@ -0,0 +1,21 @@ +import MediaStreamTrack from './MediaStreamTrack'; +import RTCRtpCapabilities from './RTCRtpCapabilities'; +import { RTCRtpParametersInit } from './RTCRtpParameters'; +import RTCRtpReceiveParameters from './RTCRtpReceiveParameters'; +export default class RTCRtpReceiver { + _id: string; + _peerConnectionId: number; + _track: MediaStreamTrack | null; + _rtpParameters: RTCRtpReceiveParameters; + constructor(info: { + peerConnectionId: number; + id: string; + track?: MediaStreamTrack; + rtpParameters: RTCRtpParametersInit; + }); + static getCapabilities(kind: 'audio' | 'video'): RTCRtpCapabilities; + getStats(): any; + getParameters(): RTCRtpReceiveParameters; + get id(): string; + get track(): MediaStreamTrack | null; +} diff --git a/lib/typescript/RTCRtpSendParameters.d.ts b/lib/typescript/RTCRtpSendParameters.d.ts new file mode 100644 index 000000000..dc27b24bf --- /dev/null +++ b/lib/typescript/RTCRtpSendParameters.d.ts @@ -0,0 +1,20 @@ +import RTCRtpEncodingParameters, { RTCRtpEncodingParametersInit } from './RTCRtpEncodingParameters'; +import RTCRtpParameters, { RTCRtpParametersInit } from './RTCRtpParameters'; +declare type DegradationPreferenceType = 'maintain-framerate' | 'maintain-resolution' | 'balanced' | 'disabled'; +export interface RTCRtpSendParametersInit extends RTCRtpParametersInit { + transactionId: string; + encodings: RTCRtpEncodingParametersInit[]; + degradationPreference?: string; +} +export default class RTCRtpSendParameters extends RTCRtpParameters { + readonly transactionId: string; + encodings: (RTCRtpEncodingParameters | RTCRtpEncodingParametersInit)[]; + degradationPreference: DegradationPreferenceType | null; + constructor(init: RTCRtpSendParametersInit); + toJSON(): { + codecs: (import("./RTCRtpCodecParameters").RTCRtpCodecParametersInit | import("./RTCRtpCodecParameters").default)[]; + headerExtensions: import("./RTCRtpHeaderExtension").default[]; + rtcp: import("./RTCRtcpParameters").default; + }; +} +export {}; diff --git a/lib/typescript/RTCRtpSender.d.ts b/lib/typescript/RTCRtpSender.d.ts new file mode 100644 index 000000000..64def3ee5 --- /dev/null +++ b/lib/typescript/RTCRtpSender.d.ts @@ -0,0 +1,22 @@ +import MediaStreamTrack from './MediaStreamTrack'; +import RTCRtpCapabilities from './RTCRtpCapabilities'; +import RTCRtpSendParameters, { RTCRtpSendParametersInit } from './RTCRtpSendParameters'; +export default class RTCRtpSender { + _id: string; + _track: MediaStreamTrack | null; + _peerConnectionId: number; + _rtpParameters: RTCRtpSendParameters; + constructor(info: { + peerConnectionId: number; + id: string; + track?: MediaStreamTrack; + rtpParameters: RTCRtpSendParametersInit; + }); + replaceTrack(track: MediaStreamTrack | null): Promise; + static getCapabilities(kind: 'audio' | 'video'): RTCRtpCapabilities; + getParameters(): RTCRtpSendParameters; + setParameters(parameters: RTCRtpSendParameters): Promise; + getStats(): any; + get track(): MediaStreamTrack | null; + get id(): string; +} diff --git a/lib/typescript/RTCRtpTransceiver.d.ts b/lib/typescript/RTCRtpTransceiver.d.ts new file mode 100644 index 000000000..5656cf925 --- /dev/null +++ b/lib/typescript/RTCRtpTransceiver.d.ts @@ -0,0 +1,31 @@ +import RTCRtpCodecCapability from './RTCRtpCodecCapability'; +import RTCRtpReceiver from './RTCRtpReceiver'; +import RTCRtpSender from './RTCRtpSender'; +export default class RTCRtpTransceiver { + _peerConnectionId: number; + _sender: RTCRtpSender; + _receiver: RTCRtpReceiver; + _mid: string | null; + _direction: string; + _currentDirection: string; + _stopped: boolean; + constructor(args: { + peerConnectionId: number; + isStopped: boolean; + direction: string; + currentDirection: string; + mid?: string; + sender: RTCRtpSender; + receiver: RTCRtpReceiver; + }); + get mid(): string | null; + get stopped(): boolean; + get direction(): string; + set direction(val: string); + get currentDirection(): string; + get sender(): RTCRtpSender; + get receiver(): RTCRtpReceiver; + stop(): void; + setCodecPreferences(codecs: RTCRtpCodecCapability[]): void; + _setStopped(): void; +} diff --git a/lib/typescript/RTCSessionDescription.d.ts b/lib/typescript/RTCSessionDescription.d.ts new file mode 100644 index 000000000..c834fb926 --- /dev/null +++ b/lib/typescript/RTCSessionDescription.d.ts @@ -0,0 +1,12 @@ +export interface RTCSessionDescriptionInit { + sdp: string; + type: string | null; +} +export default class RTCSessionDescription { + _sdp: string; + _type: string | null; + constructor(info?: RTCSessionDescriptionInit); + get sdp(): string; + get type(): string | null; + toJSON(): RTCSessionDescriptionInit; +} diff --git a/lib/typescript/RTCTrackEvent.d.ts b/lib/typescript/RTCTrackEvent.d.ts new file mode 100644 index 000000000..b87c7ae36 --- /dev/null +++ b/lib/typescript/RTCTrackEvent.d.ts @@ -0,0 +1,29 @@ +import { Event } from 'event-target-shim/index'; +import MediaStream from './MediaStream'; +import type MediaStreamTrack from './MediaStreamTrack'; +import RTCRtpReceiver from './RTCRtpReceiver'; +import RTCRtpTransceiver from './RTCRtpTransceiver'; +declare type TRACK_EVENTS = 'track'; +interface IRTCTrackEventInitDict extends Event.EventInit { + streams: MediaStream[]; + transceiver: RTCRtpTransceiver; +} +/** + * @eventClass + * This event is fired whenever the Track is changed in PeerConnection. + * @param {TRACK_EVENTS} type - The type of event. + * @param {IRTCTrackEventInitDict} eventInitDict - The event init properties. + * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/track_event MDN} for details. + */ +export default class RTCTrackEvent extends Event { + /** @eventProperty */ + readonly streams: MediaStream[]; + /** @eventProperty */ + readonly transceiver: RTCRtpTransceiver; + /** @eventProperty */ + readonly receiver: RTCRtpReceiver | null; + /** @eventProperty */ + readonly track: MediaStreamTrack | null; + constructor(type: TEventType, eventInitDict: IRTCTrackEventInitDict); +} +export {}; diff --git a/lib/typescript/RTCUtil.d.ts b/lib/typescript/RTCUtil.d.ts new file mode 100644 index 000000000..6b960484a --- /dev/null +++ b/lib/typescript/RTCUtil.d.ts @@ -0,0 +1,37 @@ +export declare type RTCOfferOptions = { + iceRestart?: boolean; + offerToReceiveAudio?: boolean; + offerToReceiveVideo?: boolean; + voiceActivityDetection?: boolean; +}; +/** + * Put together a random string in UUIDv4 format {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} + * + * @return {String} uuidv4 + */ +export declare function uniqueID(): string; +/** + * Utility for deep cloning an object. Object.assign() only does a shallow copy. + * + * @param {Object} obj - object to be cloned + * @return {Object} cloned obj + */ +export declare function deepClone(obj: T): T; +/** + * Checks whether an SDP type is valid or not. + * + * @param type SDP type to check. + * @returns Whether the SDP type is valid or not. + */ +export declare function isSdpTypeValid(type: string): boolean; +/** + * Normalize options passed to createOffer(). + * + * @param options - user supplied options + * @return Normalized options + */ +export declare function normalizeOfferOptions(options?: RTCOfferOptions): Record; +/** + * Normalize the given constraints in something we can work with. + */ +export declare function normalizeConstraints(constraints: any): any; diff --git a/lib/typescript/RTCView.d.ts b/lib/typescript/RTCView.d.ts new file mode 100644 index 000000000..5e2b7e48e --- /dev/null +++ b/lib/typescript/RTCView.d.ts @@ -0,0 +1,130 @@ +import { ViewProps } from "react-native"; +/** + * Native prop validation was removed from RN in: + * https://github.com/facebook/react-native/commit/8dc3ba0444c94d9bbb66295b5af885bff9b9cd34 + * + * So we list them here for documentation purposes. + */ +export interface RTCVideoViewProps extends ViewProps { + customScale?: number; + customTranslateX?: number; + customTranslateY?: number; + useCustomTransform?: boolean; + /** + * Android only. When true, uses TextureViewRenderer instead of + * SurfaceViewRenderer. TextureView renders in the normal View hierarchy + * and supports borderRadius, overflow:hidden, and other clipping. + * Slightly higher GPU overhead but negligible for small views. + * + * Defaults to false (SurfaceView). + */ + useTextureView?: boolean; + /** + * Indicates whether the video specified by {@link #streamURL} should be + * mirrored during rendering. Commonly, applications choose to mirror the + * user-facing camera. + * + * mirror: boolean + */ + mirror?: boolean; + /** + * In the fashion of + * https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth + * and https://www.w3.org/TR/html5/rendering.html#video-object-fit, + * resembles the CSS style object-fit. + * + * objectFit: 'contain' | 'cover' + * + * Defaults to 'cover'. + */ + objectFit?: "contain" | "cover"; + /** + * URL / id of the stream that should be rendered. + * + * streamURL: string + */ + streamURL?: string; + /** + * Similarly to the CSS property z-index, specifies the z-order of this + * RTCView in the stacking space of all RTCViews. When RTCViews overlap, + * zOrder determines which one covers the other. An RTCView with a larger + * zOrder generally covers an RTCView with a lower one. + * + * Non-overlapping RTCViews may safely share a z-order (because one does not + * have to cover the other). + * + * The support for zOrder is platform-dependent and/or + * implementation-specific. Thus, specifying a value for zOrder is to be + * thought of as giving a hint rather than as imposing a requirement. For + * example, video renderers such as RTCView are commonly implemented using + * OpenGL and OpenGL views may have different numbers of layers in their + * stacking space. Android has three: a layer bellow the window (aka + * default), a layer bellow the window again but above the previous layer + * (aka media overlay), and above the window. Consequently, it is advisable + * to limit the number of utilized layers in the stacking space to the + * minimum sufficient for the desired display. For example, a video call + * application usually needs a maximum of two zOrder values: 0 for the + * remote video(s) which appear in the background, and 1 for the local + * video(s) which appear above the remote video(s). + * + * zOrder: number + */ + zOrder?: number; + /** + * Picture in picture options for this view. Disabled if not supplied. + * + * Note: this should only be generally only used with remote video tracks, + * as the local camera may stop while in the background. + * + * iOS only. Requires iOS 15.0 or above, and the PIP background mode capability. + */ + iosPIP?: RTCIOSPIPOptions; + /** + * Callback function that is called when the dimensions of the video change. + * + * @param {Object} event - The event object containing the new dimensions. + * @param {Object} event.nativeEvent - The native event data. + * @param {number} event.nativeEvent.width - The width of the video. + * @param {number} event.nativeEvent.height - The height of the video. + */ + onDimensionsChange?: (event: { + nativeEvent: { + width: number; + height: number; + }; + }) => void; +} +export interface RTCIOSPIPOptions { + /** + * Whether PIP can be launched from this view. + * + * Defaults to true. + */ + enabled?: boolean; + /** + * The preferred size of the PIP window. + */ + preferredSize?: { + width: number; + height: number; + }; + /** + * Indicates whether Picture in Picture starts automatically + * when the controller embeds its content inline and the app + * transitions to the background. + * + * Defaults to true. + * + * See: AVPictureInPictureController.canStartPictureInPictureAutomaticallyFromInline + */ + startAutomatically?: boolean; + /** + * Indicates whether Picture in Picture should stop automatically + * when the app returns to the foreground. + * + * Defaults to true. + */ + stopAutomatically?: boolean; +} +declare const _default: import("react-native").HostComponent; +export default _default; diff --git a/lib/typescript/ScreenCapturePickerView.d.ts b/lib/typescript/ScreenCapturePickerView.d.ts new file mode 100644 index 000000000..d39c29e1b --- /dev/null +++ b/lib/typescript/ScreenCapturePickerView.d.ts @@ -0,0 +1,2 @@ +declare const _default: import("react-native").HostComponent; +export default _default; diff --git a/lib/typescript/getDisplayMedia.d.ts b/lib/typescript/getDisplayMedia.d.ts new file mode 100644 index 000000000..099643b31 --- /dev/null +++ b/lib/typescript/getDisplayMedia.d.ts @@ -0,0 +1,2 @@ +import MediaStream from './MediaStream'; +export default function getDisplayMedia(): Promise; diff --git a/lib/typescript/getUserMedia.d.ts b/lib/typescript/getUserMedia.d.ts new file mode 100644 index 000000000..98bebafaf --- /dev/null +++ b/lib/typescript/getUserMedia.d.ts @@ -0,0 +1,7 @@ +import { MediaTrackConstraints } from './Constraints'; +import MediaStream from './MediaStream'; +export interface Constraints { + audio?: boolean | MediaTrackConstraints; + video?: boolean | MediaTrackConstraints; +} +export default function getUserMedia(constraints?: Constraints): Promise; diff --git a/lib/typescript/index.d.ts b/lib/typescript/index.d.ts new file mode 100644 index 000000000..a9a54e925 --- /dev/null +++ b/lib/typescript/index.d.ts @@ -0,0 +1,20 @@ +import mediaDevices from './MediaDevices'; +import MediaStream from './MediaStream'; +import MediaStreamTrack, { type MediaTrackSettings } from './MediaStreamTrack'; +import permissions from './Permissions'; +import RTCAudioSession from './RTCAudioSession'; +import RTCErrorEvent from './RTCErrorEvent'; +import RTCFrameCryptor, { RTCFrameCryptorState } from './RTCFrameCryptor'; +import RTCFrameCryptorFactory, { RTCFrameCryptorAlgorithm, RTCKeyProviderOptions } from './RTCFrameCryptorFactory'; +import RTCIceCandidate from './RTCIceCandidate'; +import RTCKeyProvider from './RTCKeyProvider'; +import RTCPIPView, { startIOSPIP, stopIOSPIP } from './RTCPIPView'; +import RTCPeerConnection from './RTCPeerConnection'; +import RTCRtpReceiver from './RTCRtpReceiver'; +import RTCRtpSender from './RTCRtpSender'; +import RTCRtpTransceiver from './RTCRtpTransceiver'; +import RTCSessionDescription from './RTCSessionDescription'; +import RTCView, { type RTCVideoViewProps, type RTCIOSPIPOptions } from './RTCView'; +import ScreenCapturePickerView from './ScreenCapturePickerView'; +export { RTCIceCandidate, RTCPeerConnection, RTCSessionDescription, RTCView, RTCPIPView, ScreenCapturePickerView, RTCRtpTransceiver, RTCRtpReceiver, RTCRtpSender, RTCErrorEvent, RTCAudioSession, RTCFrameCryptor, RTCFrameCryptorAlgorithm, RTCFrameCryptorState, RTCFrameCryptorFactory, RTCKeyProvider, RTCKeyProviderOptions, MediaStream, MediaStreamTrack, type MediaTrackSettings, type RTCVideoViewProps, type RTCIOSPIPOptions, mediaDevices, permissions, registerGlobals, startIOSPIP, stopIOSPIP, }; +declare function registerGlobals(): void; diff --git a/src/RTCView.ts b/src/RTCView.ts index ea97a430f..8a16c13a4 100644 --- a/src/RTCView.ts +++ b/src/RTCView.ts @@ -1,4 +1,4 @@ -import { requireNativeComponent, ViewProps } from 'react-native'; +import { requireNativeComponent, ViewProps } from "react-native"; /** * Native prop validation was removed from RN in: @@ -7,6 +7,19 @@ import { requireNativeComponent, ViewProps } from 'react-native'; * So we list them here for documentation purposes. */ export interface RTCVideoViewProps extends ViewProps { + customScale?: number; + customTranslateX?: number; // as fraction of width (-1 to 1) + customTranslateY?: number; // as fraction of height (-1 to 1) + useCustomTransform?: boolean; + /** + * Android only. When true, uses TextureViewRenderer instead of + * SurfaceViewRenderer. TextureView renders in the normal View hierarchy + * and supports borderRadius, overflow:hidden, and other clipping. + * Slightly higher GPU overhead but negligible for small views. + * + * Defaults to false (SurfaceView). + */ + useTextureView?: boolean; /** * Indicates whether the video specified by {@link #streamURL} should be * mirrored during rendering. Commonly, applications choose to mirror the @@ -26,7 +39,7 @@ export interface RTCVideoViewProps extends ViewProps { * * Defaults to 'cover'. */ - objectFit?: 'contain' | 'cover'; + objectFit?: "contain" | "cover"; /** * URL / id of the stream that should be rendered. @@ -61,7 +74,6 @@ export interface RTCVideoViewProps extends ViewProps { */ zOrder?: number; - /** * Picture in picture options for this view. Disabled if not supplied. * @@ -80,11 +92,12 @@ export interface RTCVideoViewProps extends ViewProps { * @param {number} event.nativeEvent.width - The width of the video. * @param {number} event.nativeEvent.height - The height of the video. */ - onDimensionsChange?: (event: { nativeEvent: { width: number; height: number } }) => void; + onDimensionsChange?: (event: { + nativeEvent: { width: number; height: number }; + }) => void; } export interface RTCIOSPIPOptions { - /** * Whether PIP can be launched from this view. * @@ -98,7 +111,7 @@ export interface RTCIOSPIPOptions { preferredSize?: { width: number; height: number; - }, + }; /** * Indicates whether Picture in Picture starts automatically @@ -119,4 +132,4 @@ export interface RTCIOSPIPOptions { */ stopAutomatically?: boolean; } -export default requireNativeComponent('RTCVideoView'); +export default requireNativeComponent("RTCVideoView");