浏览代码

add sdpTransform to answer method

afrokick 6 年之前
父节点
当前提交
2c314e6cfc
共有 5 个文件被更改,包括 44 次插入10 次删除
  1. 0 0
      dist/peerjs.min.js
  2. 0 0
      dist/peerjs.min.js.map
  3. 26 7
      docs/api.json
  4. 11 2
      index.d.ts
  5. 7 1
      lib/mediaconnection.ts

文件差异内容过多而无法显示
+ 0 - 0
dist/peerjs.min.js


文件差异内容过多而无法显示
+ 0 - 0
dist/peerjs.min.js.map


+ 26 - 7
docs/api.json

@@ -145,6 +145,11 @@
           {
             "name": "metadata",
             "description": "Metadata associated with the connection, passed in by whoever initiated the connection. Can be accessed with <a href='#dataconnection-metadata'><code>dataConnection.metadata</code></a>. Can be any serializable type."
+          },
+          {
+            "name": "sdpTransform",
+            "type": "method",
+            "description": "Function which runs before create offer to modify sdp offer message."
           }
         ]
       }
@@ -435,14 +440,28 @@
       {
         "name": ".answer",
         "type": "method",
-        "snippet": "mediaConnection.answer([stream]);",
+        "snippet": "mediaConnection.answer([stream],[options]);",
         "description": "When recieving a <a href='#peeron-call'><code>call</code></a> event on a peer, you can call <code>.answer</code> on the media connection provided by the callback to accept the call and optionally send your own media stream.",
-        "children": {
-          "name": "stream",
-          "optional": true,
-          "type": "MediaStream",
-          "description": "A WebRTC media stream from <a href='https://developer.mozilla.org/en-US/docs/Web/API/Navigator.getUserMedia'><code>getUserMedia</code></a>."
-        }
+        "children": [
+          {
+            "name": "stream",
+            "optional": true,
+            "type": "MediaStream",
+            "description": "A WebRTC media stream from <a href='https://developer.mozilla.org/en-US/docs/Web/API/Navigator.getUserMedia'><code>getUserMedia</code></a>."
+          },
+          {
+            "name": "options",
+            "optional": true,
+            "type": "object",
+            "children": [
+              {
+                "name": "sdpTransform",
+                "type": "method",
+                "description": "Function which runs before create answer to modify sdp answer message."
+              }
+            ]
+          }
+        ]
       },
       {
         "name": ".close",

+ 11 - 2
index.d.ts

@@ -33,7 +33,7 @@ declare class Peer {
    * @param stream The caller's media stream
    * @param options Metadata associated with the connection, passed in by whoever initiated the connection.
    */
-  call(id: string, stream: MediaStream, options?: any): Peer.MediaConnection;
+  call(id: string, stream: MediaStream, options?: Peer.CallOption): Peer.MediaConnection;
   /**
    * Calls the remote peer specified by id and returns a media connection.
    * @param event Event name
@@ -147,6 +147,15 @@ declare namespace Peer {
     reliable?: boolean;
   }
 
+  interface CallOption {
+    metadata?: any;
+    sdpTransform?: Function;
+  }
+
+  interface AnswerOption {
+    sdpTransform?: Function;
+  }
+
   interface DataConnection {
     send(data: any): void;
     close(): void;
@@ -169,7 +178,7 @@ declare namespace Peer {
   }
 
   interface MediaConnection {
-    answer(stream?: MediaStream): void;
+    answer(stream?: MediaStream, options?: AnswerOption): void;
     close(): void;
     on(event: string, cb: () => void): void;
     on(event: "stream", cb: (stream: MediaStream) => void): void;

+ 7 - 1
lib/mediaconnection.ts

@@ -5,6 +5,7 @@ import { ConnectionType, ConnectionEventType, ServerMessageType } from "./enums"
 import { Peer } from "./peer";
 import { BaseConnection } from "./baseconnection";
 import { ServerMessage } from "./servermessage";
+import { AnswerOption } from "..";
 
 /**
  * Wraps the streaming interface between two Peers.
@@ -67,7 +68,7 @@ export class MediaConnection extends BaseConnection {
     }
   }
 
-  answer(stream: MediaStream): void {
+  answer(stream: MediaStream, options: AnswerOption = {}): void {
     if (this._localStream) {
       logger.warn(
         "Local stream already exists on this MediaConnection. Are you answering a call twice?"
@@ -76,6 +77,11 @@ export class MediaConnection extends BaseConnection {
     }
 
     this._localStream = stream;
+
+    if (options && options.sdpTransform) {
+      this.options.sdpTransform = options.sdpTransform;
+    }
+
     this._negotiator.startConnection({ ...this.options._payload, _stream: stream });
     // Retrieve lost messages stored because PeerConnection not set up.
     const messages = this.provider._getMessages(this.connectionId);

部分文件因为文件数量过多而无法显示