question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I call without a MediaStream?

See original GitHub issue

I have a use-case where:

  • there are two people, Presenter and Viewer
  • Presenter opens the page and gets a peer ID
  • Presenter sends that peer ID to Viewer
  • Viewer uses that peer ID to call Presenter
  • Presenter sends his shared screen to the viewer

For this use-case I need, for the Viewer side:

var call = peer.call(presenterPeerID, null);
call.on('stream', function(theirWebcamStream) {
  showWebcamStream(theirWebcamStream);
});

This does not work, because peer.call(presenterPeerID, null) returns undefined.

How do I call without sending a MediaStream?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
afrokickcommented, Mar 27, 2019

You can create empty stream with any track, or with both:

export const createEmptyAudioTrack = () => {
  const ctx = new AudioContext();
  const oscillator = ctx.createOscillator();
  const dst = oscillator.connect(ctx.createMediaStreamDestination());
  oscillator.start();
  const track = dst.stream.getAudioTracks()[0];
  return Object.assign(track, { enabled: false });
};

export const createEmptyVideoTrack = ({ width, height }) => {
  const canvas = Object.assign(document.createElement('canvas'), { width, height });
  canvas.getContext('2d').fillRect(0, 0, width, height);

  const stream = canvas.captureStream();
  const track = stream.getVideoTracks()[0];

  return Object.assign(track, { enabled: false });
};

...

const audioTrack = createEmptyAudioTrack();
const videoTrack = createEmptyVideoTrack({ width:640, height:480 });
const mediaStream = new MediaStream([audioTrack, videoTrack]);

peer.call('id', mediaStream);
0reactions
mahmed0715commented, Oct 24, 2016

+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

webrtc and peerjs: how to play a stream without starting his ...
We first create a function variable named getUserMedia which will be mapped to native webrtc method provided by browser (for example in case ......
Read more >
MediaStream - Web APIs - MDN Web Docs - Mozilla
Chrome Edge MediaStream Full support. Chrome55. more. Toggle history Full support. Edge... MediaStream() constructor Full support. Chrome55. more. Toggle history Full support. Edge... active Full support....
Read more >
AddTrack to MediaStream not working - Google Groups
Hi, I am using twilio and get the MediaStream via the Twilio getLocalStream function. If I alter this I should be able to...
Read more >
dom MediaStream - CodeProject Reference
Returns a list of all MediaStreamTrack objects stored in the MediaStream object, regardless of the value of the kind attribute. The order is...
Read more >
Media Capture and Streams - W3C
A getCapabilities () call on a track returns the same underlying ... A MediaStream that does not have any tracks or only has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found