Skip to main content

MediaConnection

Wraps WebRTC's media streams. To get one, use peer.call or listen for the call event.

.answer​

mediaConnection.answer([stream], [options]);

When receiving a call event on a peer, you can call .answer on the media connection provided by the callback to accept the call and optionally send your own media stream.

[stream] (MediaStream)​

A WebRTC media stream from getUserMedia.

[options] (object)​

  • sdpTransform (method): Function which runs before create answer to modify sdp answer message.

.close​

mediaConnection.close();

Closes the media connection.


.on​

mediaConnection.on(event, callback);

Set listeners for media connection events.

'stream'​

mediaConnection.on('stream', function(stream) { ... });

Emitted when a remote peer adds a stream.

'close'​

mediaConnection.on('close', function() { ... });

Emitted when either you or the remote peer closes the media connection.

'error'​

mediaConnection.on('error', function(err) { ... });

.open (boolean)​

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.


.metadata​

Any type of metadata associated with the connection, passed in by whoever initiated the connection.


.peer (string)​

The ID of the peer on the other end of this connection.


.type (string)​

For media connections, this is always 'media'.