cordova-rtc / cordova-plugin-iosrtc

Cordova iOS plugin exposing the WebRTC W3C API
MIT License
687 stars 340 forks source link

cordova-plugin-iosrtc with sip.js 0.11 IOS APP #347

Closed ghost closed 4 years ago

ghost commented 5 years ago

Hi!!

I need your help please!! Urgent!!

I am developing a webrtc call/videocall app bases on ionic/Angular JS technologies. The app works with sip.js for call actions over PBX server. For IOS integration with WebRtc, app works with cordova-plugin-iosrtc. When I try connect with PBX to call or received call, app throws errors on two possible use mode of cordova-plugin-iosrtc with sip.js

A) When i am try to use cordova-plugin-iosrtc working on peer connection ios plugin mode ....

telephoneService.js (Angular JS)

var pc = new cordova.plugins.iosrtc.RTCPeerConnection({
    iceServers: []
});

cordova.plugins.iosrtc.getUserMedia(
  // constraints
  { audio: true, video: true },
  // success callback
  function (stream) {
    console.log('got local MediaStream: ', stream);
    pc.addStream(stream);
  },
  // failure callback
  function (error) {
    console.error('getUserMedia failed: ', error);
  }
);

var sessionDescriptionHandlerOptions = {

                constraints: {
                    audio: audioId,
                    video: videoId
                },

                media: {
                    local: {
                      audio: document.getElementById('localAudio')
                    },
                    remote: {
                      audio: document.getElementById('remoteAudio')
                    }
                },

            extraHeaders: extraHeaders

            }

}

userAgent.invite('sipusertocall', sessionDescriptionHandlerOptions);

receive the next error:

undefined is not a objetc evaluating 'environment.navigator.mediaDevices.getUserMedia' (sip.js lib)

B) cordova.plugins.iosrtc.registerGlobals(); use iosrtc plugin with webrtc native api (navigator.mediaDevice.getUserMedia(), ....)

navigator.mediaDevices.getUserMedia(
 function (stream) {
    console.log('got local MediaStream: ', stream);

    window.stream = stream;
  },
  // failure callback
  function (error) {
    console.error('getUserMedia failed: ', error);
  }
)

var sessionDescriptionHandlerOptions = {

                constraints: {
                    audio: audioId,
                    video: videoId
                },

                media: {
                    local: {
                      audio: document.getElementById('localAudio')
                    },
                    remote: {
                      audio: document.getElementById('remoteAudio')
                    }
                },

            extraHeaders: extraHeaders

        }

userAgent.invite('sipusertocall', sessionDescriptionHandlerOptions);

App receive from sip.js next error from PBX: Failed:WebRTC Error

Client show next error at same time: "setLocalDescription() must be called with a RTCSessionDescription instance as first argument"

Thank's a lot!!

menelike commented 5 years ago

undefined is not a objetc evaluating 'environment.navigator.mediaDevices.getUserMedia' (sip.js lib)

see https://github.com/BasqueVoIPMafia/cordova-plugin-iosrtc/blob/master/docs/iosrtc.md#iosrtcregisterglobals

Still not sure if that fits your case, I don't know where environment is coming from

"setLocalDescription() must be called with a RTCSessionDescription instance as first argument"

your jsep must be an instance of RTCSessionDescription e.g. new RTCSessionDescription(jsep), a similar issue is discussed here https://github.com/meetecho/janus-gateway/issues/1422

Bobisback commented 5 years ago

@franShila I am trying to build a audio based peer to peer app with ionic and angular. Any chance I could pick your brain on how you guys did it, and what is the current state of your project?

WesUnwin commented 5 years ago

Hi guys, I ended up writing a custom SDH which allowed me to use SIP.js 0.12.0 with a set of cordova based mobile apps.

It allowed me to fix this issue:

"setLocalDescription() must be called with a RTCSessionDescription instance as first argument" caused by the default Web SDH of SIP.js passing in an object that is similar but not quite a RTCSessionDescription object into pc.setLocationDescription()/setRemoteDescription().

Have created an npm package for it: https://github.com/iotum/cordova-ios-session-description-handler

Hope this helps anyone, or at least provides a useful example of how to write a session description handler if anyone is interested.

taufpate commented 5 years ago

Hi guys, I ended up writing a custom SDH which allowed me to use SIP.js 0.12.0 with a set of cordova based mobile apps.

It allowed me to fix this issue:

"setLocalDescription() must be called with a RTCSessionDescription instance as first argument" caused by the default Web SDH of SIP.js passing in an object that is similar but not quite a RTCSessionDescription object into pc.setLocationDescription()/setRemoteDescription().

Have created an npm package for it: https://github.com/iotum/cordova-ios-session-description-handler

Hope this helps anyone, or at least provides a useful example of how to write a session description handler if anyone is interested.

Hi @WesUnwin do you have a guide, an example app or how to? i use sipjs 0.12 too with ionic 3 and i cant make it work :(

WesUnwin commented 5 years ago

@taufpate there is a quick quide/example on the README, simply use the custom SDH by setting the sessionDescriptionHandlerFactory UA configuration property, before constructing the SIP.js user agent:

const CordovaIOSSDH = require('cordova-ios-session-description-handler');

const config = {};

... config.sessionDescriptionHandlerFactory = CordovaIOSSDH.factory; ...

const UA = new SIP.UA(config);

valentinyaroshinsky commented 5 years ago

@WesUnwin Dear Wesley, can you share the full cordova example with your SDH for iOS?

WesUnwin commented 5 years ago

I wish I could, unfortunately all of the full examples I've helped developed using this are incorporated into commercial, closed source applications (Such as the freeconference.com iOS application).

WesUnwin commented 5 years ago

One thing I wanted to mention (which is sort of mentioned above), is this is not at all an issue with SIP.js, it's really due to certain environments like cordova-plugins-iortc having slightly different or outdated webrtc implementations (and missing things like getReceivers(), and requiring RTCPeerConnection getLocalStream/setRemoteStream to be passed a RTCSessionDescription and not anything else even though other things like RTCSessionDescriptionInit should have been accepted).

SIP.js, especially the newer versions of the library do a good job of separating the SIP signalling from the media handling, due to the unevenness of webrtc across various environments.

valentinyaroshinsky commented 5 years ago

@WesUnwin Wesley, it looks like we added your SDH , but we have an issue with getting media device: User doesn't approve access to media devices. cordova.js:1509

Can you assist?

log details:

[Log] Wed Jun 19 2019 17:01:00 GMT+0300 (EEST) | sip.invitecontext.sessionDescriptionHandler | net39vgplu31bneo322us4b0vdgf4l | SessionDescriptionHandlerOptions: {"constraints":{},"peerConnectionOptions":{}} (cordova.js, line 1509) [Log] Wed Jun 19 2019 17:01:00 GMT+0300 (EEST) | sip.invitecontext.sessionDescriptionHandler | net39vgplu31bneo322us4b0vdgf4l | initPeerConnection (cordova.js, line 1509) [Log] Wed Jun 19 2019 17:01:00 GMT+0300 (EEST) | sip.invitecontext.sessionDescriptionHandler | net39vgplu31bneo322us4b0vdgf4l | New peer connection created (cordova.js, line 1509) [Warning] Wed Jun 19 2019 17:01:00 GMT+0300 (EEST) | sip.invitecontext.sessionDescriptionHandler | net39vgplu31bneo322us4b0vdgf4l | Using onaddstream which is deprecated (cordova.js, line 1509) [Log] Wed Jun 19 2019 17:01:00 GMT+0300 (EEST) | sip.invitecontext.sessionDescriptionHandler | net39vgplu31bneo322us4b0vdgf4l | acquiring local media (cordova.js, line 1509) [Log] User doesn't approve access to media devices. (cordova.js, line 1509) [Error] Wed Jun 19 2019 17:01:00 GMT+0300 (EEST) | sip.invitecontext.sessionDescriptionHandler | net39vgplu31bneo322us4b0vdgf4l | unable to acquire streams (anonymous function) (cordova.js:1509) print (nova.webcall.min.js:1:25005) (anonymous function) (nova.webcall.min.js:1:25205) (anonymous function) (nova.webcall.min.js:1:25094) (anonymous function) (nova.webcall.min.js:1:12113) promiseReactionJob [Error] TypeError: t.getReceivers is not a function. (In 't.getReceivers()', 't.getReceivers' is undefined) — nova.webcall.min.js:0 (anonymous function) (cordova.js:1509) print (nova.webcall.min.js:1:25005) (anonymous function) (nova.webcall.min.js:1:25205) (anonymous function) (nova.webcall.min.js:1:25094) (anonymous function) (nova.webcall.min.js:1:12139) promiseReactionJob [Log] Wed Jun 19 2019 17:01:00 GMT+0300 (EEST) | sip.inviteclientcontext | unable to acquire streams (cordova.js, line 1509) [Log] TypeError: t.getReceivers is not a function. (In 't.getReceivers()', 't.getReceivers' is undefined) — nova.webcall.min.js:0 (cordova.js, line 1509) [Log] Wed Jun 19 2019 17:01:00 GMT+0300 (EEST) | sip.inviteclientcontext | closing INVITE session net39vgplu31bneo322us4b0vdgf4l (cordova.js, line 1509) [Log] Wed Jun 19 2019 17:01:00 GMT+0300 (EEST) | sip.invitecontext.sessionDescriptionHandler | net39vgplu31bneo322us4b0vdgf4l | closing PeerConnection (cordova.js, line 1509) [Warning] Wed Jun 19 2019 17:01:00 GMT+0300 (EEST) | sip.invitecontext.sessionDescriptionHandler | net39vgplu31bneo322us4b0vdgf4l | Using getLocalStreams which is deprecated (cordova.js, line 1509) [Warning] Wed Jun 19 2019 17:01:00 GMT+0300 (EEST) | sip.invitecontext.sessionDescriptionHandler | net39vgplu31bneo322us4b0vdgf4l | Using getRemoteStreams which is deprecated (cordova.js, line 1509) [Log] Wed Jun 19 2019 17:01:00 GMT+0300 (EEST) | sip.invitecontext.sessionDescriptionHandler | net39vgplu31bneo322us4b0vdgf4l | resetIceGatheringComplete (cordova.js, line 1509) [Log] Hanging up current uaSession (cordova.js, line 1509) [Log] Hanging up current ua (cordova.js, line 1509)

WesUnwin commented 5 years ago

Not sure where your getting "cordova.js" from, put the error message is telling you its calling getReceivers() which is a WebRTC RTCPeerConnection function not supported on cordova iosrtc. If you look at the custom SDH, it actually avoids( in all places) calling getReceivers when its undefined like so:

`

if (this.peerConnection.getReceivers) { this.peerConnection.getReceivers().forEach(receiver => { if (receiver.track) { receiver.track.stop(); } }); } else { this.logger.warn('Using getRemoteStreams which is deprecated'); this.peerConnection.getRemoteStreams().forEach(stream => { stream.getTracks().forEach(track => { track.stop(); }); }); } `

I would recommend the above approach of falling back to using getRemoteStreams(). You could also try to fix the peerConnection object by giving it a getReceivers() function similar to how a polyfill would fill it in.

hthetiot commented 4 years ago

JsSIp@3.3.7 works for me using webrtc-adapter@7.2.9 i do not recommend sip.js "fork"

Skorpeo commented 4 years ago

Please see Pull Request #381 and issue #380 . Tested with jssip and adapter730-ios.js in pull request.

hthetiot commented 4 years ago

@Skorpeo not totally the same issue here, the PR for fix is more this one.

However as said using JsSIp@3.3.7 in favor or sip.js (fork of JSsip) does not cause the getReceivers issues for me so fare.

It's mostly ready for getReceivers| getSenders but more internal changes will be needed for AddTrack|RemoveTrack due custom MediaStream creation failing.

Skorpeo commented 4 years ago

@hthetiot ok understood. I haven't looked at the references you show, but w/r/t MediaStream creation check out my comment re: MediaStream constructor in my pr if it helps...

hthetiot commented 4 years ago

Should be fixed by #373 with getReceivers|getSenders SHIM and addTrack|removeTrack SHIM