Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Returning a Media Stream from a Native Module #674

Open
p8952 opened this issue Feb 26, 2019 · 4 comments
Open

Returning a Media Stream from a Native Module #674

p8952 opened this issue Feb 26, 2019 · 4 comments

Comments

@p8952
Copy link

p8952 commented Feb 26, 2019

Description

When defining a Native Module that calls getUserMedia, I am unable to pass the resulting Media Stream back to index.js.

Expected behavior

When the Promise in my Native Module resolves with a Media Stream, that Media Stream will be available in index.js.

Actual behavior

When the Promise in my Native Module resolves with a Media Stream, that Media Stream is not available in index.js, instead it is an empty object.

Reproduction

Native Module:

  $getUserMedia(resolveID, rejectID) {
    navigator.mediaDevices
      .getUserMedia({ audio: true, video: true })
      .then((mediaStream) => {
        console.log(mediaStream);
        this._ctx.invokeCallback(resolveID, [mediaStream]);
      })
      .catch((error) => {
        this._ctx.invokeCallback(rejectID, [error]);
      });
  }

Logs: MediaStream {id: "Efr55Nh1C0n9H5heZTk5NMi1CaEYnbSPsFYQ", active: true, onaddtrack: null, onremovetrack: null, onactive: null, …}

index.js:

    WebRTCNativeModule.getUserMedia().then((mediaStream) => {
      console.log(mediaStream);
    });

Logs: {}

Additional Information

  • 'react-360' package version: react-360@1.1.0
  • 'react-360-web' package version: react-360-web@1.1.0
  • Operating System: Linux (Fedora 27)
  • Browser: Chrome 72 (Desktop)
  • VR Device: N/A - In Chrome (Desktop)
@larrylin28
Copy link
Contributor

You can not do this. The index.js is running in a web worker, and all messages sent via NativeModule to it is JSON stringed and sent via postMessage, a mediaStream is not able to stringify to a JSON.
Despite from that, why would you want to send a media stream to react side(index.js)?
If you want some information about the stream to be used by react code, please extract those properties out and send them instead.
If you want to play the media, you can't directly play the media on react side(index.js). You should do it on client side(client.js). E.g, save the media stream in your native module, and then use native module function call from react side to trigger the playing or other controls that runs in native module.

@p8952
Copy link
Author

p8952 commented Feb 26, 2019

Thanks @larrylin28, fair enough if it's a postMessage and can only send JSON.

I have a couple of further questions regarding videos, surfaces, screens. Do you have a Slack channel or anything? Or can I ask here?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@p8952 @larrylin28 and others