peerjs icon indicating copy to clipboard operation
peerjs copied to clipboard

Video not appear on cordova/ios

Open webcodepl opened this issue 5 years ago • 8 comments

I wrote simple one-to-one video chat for test purpose (code/links below). When launching under desktop browsers, cordova/android or safari/ios, works ok. Problem is under cordova on ios. After connection established, there is no video both on caller and receiver side. I can only hear sound. I don't think this is because there is no turn server. Both caller/receiver are in the same local network. I noticed, that ontrack handler from negotiator.ts (line 145) is not called. Maybe it has to do with this problem.

Does anyone have an idea how to deal with it ?

My configuration: ios: 12.4.1 macOS: 10.14.6 Xcode: 10.3 cordova: 9.0.0 cordova-ios: 5.0.1

config.xml:

...
<platform name="ios">
   <allow-intent href="itms:*" />
   <allow-intent href="itms-apps:*" />
   <config-file parent="NSCameraUsageDescription" platform="ios" target="*-Info.plist">
      <string>Use camera for video calling</string>
   </config-file>
   <config-file parent="NSMicrophoneUsageDescription" platform="ios" target="*-Info.plist">
      <string>Use microphone for video calling</string>
   </config-file>
</platform>
<plugin name="cordova-plugin-whitelist" spec="^1.3.4" />
<plugin name="cordova-custom-config" spec="^5.1.0" />
<plugin name="cordova-plugin-iosrtc" spec="~5.0.0" />
<plugin name="cordova-plugin-device" spec="~2.0.3" />
...

Caller(Cordova):

index.html:

...
<video id="camera" width="300" height="300" autoplay="autoplay" playsinline></video>
<button id="call-to-remote-peer-btn">Call to remote peer</button>
<script type="text/javascript" src="cordova.js"></script>
<script src="js/peerjs.js"></script>
<script src="js/script.js"></script>
...

script.js:

document.addEventListener('deviceready', function(event) {

    if (window.device.platform === 'iOS') {
        cordova.plugins.iosrtc.registerGlobals();
    }

    function updatedVideoFrames(){
	if (window.device.platform === 'iOS') {
		cordova.plugins.iosrtc.refreshVideos();
	}
    }
	
    window.addEventListener('orientationchange', updatedVideoFrames);
    window.addEventListener('scroll', updatedVideoFrames);

    let localPeerId = 'MyRemoteTestPeer123';
    let remotePeerId = 'MyLocalTestPeer123';

    function handleError(err) {
        alert(err);
        console.error(err);
    }

    document.getElementById("call-to-remote-peer-btn").addEventListener("click", () => {

      let peer = new Peer(localPeerId, {
        debug: 3,
        config: {
          'iceServers': [
            { url: 'stun:stun1.l.google.com:19302' }
          ]
        }           
      });

      peer.on('error', handleError);

      peer.on('open', () => {

        navigator.mediaDevices.getUserMedia({ audio: true, video: true })
          .then((stream) => {

			peer.connect(remotePeerId);

			call = peer.call(remotePeerId, stream);

			call.on('stream', (stream) => {
			  document.getElementById('camera').srcObject = stream;
			});

			call.on('close', () => alert("The videocall has finished"));

        })
          .catch(handleError);

      });

    }, false);
	
    }, false);

Caller: https://jsfiddle.net/c1vbdt9m/

Receiver: https://jsfiddle.net/0znrj87a/

webcodepl avatar Oct 01 '19 08:10 webcodepl

Unfortunately webrtc isn't supported by the ios embedded webview that cordova uses (it works in safari but not in the webview for an app).

So if you need it to work in cordova ios then you'll need to use a plugin like cordova-plugin-iosrtc

dwheaton avatar Nov 08 '19 11:11 dwheaton

If you look at a section of my confg.xml and script.js, you may notice that I use cordova-plugin-iosrtc. So the problem is not related to its absence.

webcodepl avatar Nov 08 '19 11:11 webcodepl

Ah okay sorry I missed that.

How about trying adapter.js? Looks like it is not included in cordova-plugin-iosrtc and may be helpful for compatibility).

dwheaton avatar Nov 09 '19 21:11 dwheaton

I finally used apirtc Works perfect.

webcodepl avatar Nov 10 '19 19:11 webcodepl

I had the same issue today, I noticed that the library of iosrtc doesn't call on('stream') event, I figured out a way to get the event of new remotestream doing this:

 call.peerConnection.addEventListener('addstream', (e: any) => {
        document.getElementById('camera').srcObject = e.stream;
  });

alysonfreitas avatar May 08 '20 23:05 alysonfreitas

hello, i 'm working with peerjs and iosrtc plugin aswell and i have got the same problem on reception with ios, this method is never fired. call.on('stream', (stream) => { document.getElementById('camera').srcObject = stream; }); And this event neither: call.peerConnection.addEventListener('addstream', (e: any) => { document.getElementById('camera').srcObject = e.stream; }); Can you help me ?

iometrine avatar Mar 16 '21 11:03 iometrine

I had the same issue today, I noticed that the library of iosrtc doesn't call on('stream') event, I figured out a way to get the event of new remotestream doing this:

 call.peerConnection.addEventListener('addstream', (e: any) => {
        document.getElementById('camera').srcObject = e.stream;
  });

I will double check but we do support ontrack unless addStream is used instead of Transceiver.

hthetiot avatar Mar 18 '21 23:03 hthetiot

@afrokick you may close this issue the issue has moved on iosrtc repository now.

  • https://github.com/cordova-rtc/cordova-plugin-iosrtc/issues/657#issuecomment-802085276

hthetiot avatar Mar 18 '21 23:03 hthetiot