PageSourceSearch

https://peerjs.com/assets/js/c579e538.0014ad41.js

js peerjs.com collected 2026-10-02 05:41:06 UTC 6,328 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkdocumentation=self.webpackChunkdocumentation||[]).push([["109"],{8355(e,n,i){i.r(n),i.d(n,{metadata:()=>o,default:()=>h,frontMatter:()=>r,contentTitle:()=>s,toc:()=>a,assets:()=>d});var o=JSON.parse('{"id":"client/api/media-connection","title":"MediaConnection","description":"MediaConnection API Reference","source":"@site/docs/client/api/media-connection.md","sourceDirName":"client/api","slug":"/client/api/media-connection","permalink":"/client/api/media-connection","draft":false,"unlisted":false,"tags":[],"version":"current","sidebarPosition":3,"frontMatter":{"sidebar_position":3,"title":"MediaConnection","description":"MediaConnection API Reference"},"sidebar":"clientSidebar","previous":{"title":"DataConnection","permalink":"/client/api/data-connection"},"next":{"title":"util","permalink":"/client/api/util"}}'),c=i(2615),t=i(416);let r={sidebar_position:3,title:"MediaConnection",description:"MediaConnection API Reference"},s="MediaConnection",d={},a=[{value:"<code>.answer</code>",id:"answer",level:2},{value:"<code>[stream]</code> (MediaStream)",id:"stream-mediastream",level:3},{value:"<code>[options]</code> (object)",id:"options-object",level:3},{value:"<code>.close</code>
1",id:"close",level:2},{value:"<code>.on</code>",id:"on",level:2},{value:"<code>&#39;stream&#39;</code>",id:"stream",level:3},{value:"<code>&#39;close&#39;</code>",id:"close-1",level:3},{value:"<code>&#39;error&#39;</code>",id:"error",level:3},{value:"<code>.open</code> (boolean)",id:"open-boolean",level:2},{value:"<code>.metadata</code>",id:"metadata",level:2},{value:"<code>.peer</code> (string)",id:"peer-string",level:2},{value:"<code>.type</code> (string)",id:"type-string",level:2}];function l(e){let n={code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,t.R)(),...e.components};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(n.header,{children:(0,c.jsx)(n.h1,{id:"mediaconnection",children:"MediaConnection"})}),"\n",(0,c.jsxs)(n.p,{children:["Wraps WebRTC's media streams. To get one, use ",(0,c.jsx)(n.code,{children:"peer.call"})," or listen for the ",(0,c.jsx)(n.code,{children:"call"})," event."]}),"\n",(0,c.jsx)(n.h2,{id:"answer",children:(0,c.jsx)(n.code,{children:".answer"})}),"\n",(0,c.jsx)(n.pre,{children:(0,c.jsx)(n.code,{className:"language-javascript",children:"mediaConnection.answer([stream], [options]);\n"})}),"\n",(0,c.jsxs)(n.p,{children:["When receiving a ",(0,c.jsx)(n.code,{children:"call"})," event on a peer, you can call ",(0,c.jsx)(n.code,{children:".answer"})," on the media connection provided by the callback to accept the call and optionally send your own media stream."]}),"\n",(0,c.jsxs)(n.h3,{id:"stream-mediastream",children:[(0,c.jsx)(n.code,{children:"[stream]"})," (MediaStream)"]}),"\n",(0,c.jsxs)(n.p,{children:["A WebRTC media stream from ",(0,c.jsx)(n.code,{children:"getUserMedia"}),"."]}),"\n",(0,c.jsxs)(n.h3,{id:"options-object",children:[(0,c.jsx)(n.code,{children:"[options]"})," (object)"]}),"\n",(0,c.jsxs)(n.ul,{children:["\n",(0,c.jsxs)(n.li,{children:[(0,c.jsxs)(n.strong,{children:[(0,c.jsx)(n.code,{children:"sdpTransform"})," (method):"]})," Function which runs before create answer to modify sdp answer message."]}),"\n"]}),"\n",(0,c.jsx)(n.hr,{}),"\n",(0,c.jsx)(n.h2,{id:"close",children:(0,c.jsx)(n.code,{children:".close"})}),"\n",(0,c.jsx)(n.pre,{children:(0,c.jsx)(n.code,{className:"language-javascript",children:"mediaConnection.close();\n"})}),"\n",(0,c.jsx)(n.p,{children:"Closes the media connection."}),"\n",(0,c.jsx)(n.hr,{}),"\n",(0,c.jsx)(n.h2,{id:"on",children:(0,c.jsx)(n.code,{children:".on"})}),"\n",(0,c.jsx)(n.pre,{children:(0,c.jsx)(n.code,{className:"language-javascript",children:"mediaConnection.on(event, callback);\n"})}),"\n",(0,c.jsx)(n.p,{children:"Set listeners for media connection events."}),"\n",(0,c.jsx)(n.h3,{id:"stream",children:(0,c.jsx)(n.code,{children:"'stream'"})}),"\n",(0,c.jsx)(n.pre,{children:(0,c.jsx)(n.code,{className:"language-javascript",children:"mediaConnection.on('stream', function(stream) { ... });\n"})}),"\n",(0,c.jsxs)(n.p,{children:["Emitted when a remote peer adds a ",(0,c.jsx)(n.code,{children:"stream"}),"."]}),"\n",(0,c.jsx)(n.h3,{id:"close-1",children:(0,c.jsx)(n.code,{children:"'close'"})}),"\n",(0,c.jsx)(n.pre,{children:(0,c.jsx)(n.code,{className:"language-javascript",children:"mediaConnection.on('close', function() { ... });\n"})}),"\n",(0,c.jsx)(n.p,{children:"Emitted when either you or the remote peer closes the media connection."}),"\n",(0,c.jsx)(n.h3,{id:"error",children:(0,c.jsx)(n.code,{children:"'error'"})}),"\n",(0,c.jsx)(n.pre,{children:(0,c.jsx)(n.code,{className:"language-javascript",children:"mediaConnection.on('error', function(err) { ... });\n"})}),"\n",(0,c.jsx)(n.hr,{}),"\n",(0,c.jsxs)(n.h2,{id:"open-boolean",children:[(0,c.jsx)(n.code,{children:".open"})," (boolean)"]}),"\n",(0,c.jsx)(n.p,{children:"Whether the media connection is active (e.g. your call has been answered). You can check this if you want to set a maximum wait time for a one-sided call."}),"\n",(0,c.jsx)(n.hr,{}),"\n",(0,c.jsx)(n.h2,{id:"metadata",children:(0,c.jsx)(n.code,{children:".metadata"})}),"\n",(0,c.jsx)(n.p,{children:"Any type of metadata associated with the connection, passed in by whoever initiated the connection."}),"\n",(0,c.jsx)(n.hr,{}),"\n",(0,c.jsxs)(n.h2,{id:"peer-string",children:[(0,c.jsx)(n.code,{children:".peer"})," (string)"]}),"\n",(0,c.jsx)(n.p,{children:"The ID of the peer on the other end of this connection."}),"\n",(0,c.jsx)(n.hr,{}),"\n",(0,c.jsxs)(n.h2,{id:"type-string",children:[(0,c.jsx)(n.code,{children:".type"})," (string)"]}),"\n",(0,c.jsxs)(n.p,{children:["For media connections, this is always ",(0,c.jsx)(n.code,{children:"'media'"}),"."]})]})}function h(e={}){let{wrapper:n}={...(0,t.R)(),...e.components};return n?(0,c.jsx)(n,{...e,children:(0,c.jsx)(l,{...e})}):l(e)}},416(e,n,i){i.d(n,{R:()=>r,x:()=>s});var o=i(9471);let c={},t=o.createContext(c);function r(e){let n=o.useContext(t);return o.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function s(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(c):e.components||c:r(e.components),o.createElement(t.Provider,{value:n},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.