Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep getting readonly TypeError when trying to set up a RTCPeerConnection #123

Closed
gitlaura opened this issue Jan 20, 2016 · 14 comments
Closed

Comments

@gitlaura
Copy link

I keep getting this error logged to the console when trying to set up a RTCPeerConnection: "Error in Success callbackId: iosrtcPlugin1441625638 : TypeError: Attempted to assign to readonly property"

Do you have any ideas what could be causing this error? Would greatly appreciate help!

@ibc
Copy link
Collaborator

ibc commented Jan 20, 2016

Which iOS version? iOS >= 9 is required (not sure if iOS 8 works)...

@warrenjmcdonald
Copy link

We are using the plugin successfully on 8.1.x.

@gitlaura
Copy link
Author

Version 9.2

@gitlaura
Copy link
Author

Are there any obvious readonly properties that I might be trying to write over?

@yocontra
Copy link

@gitlaura Can you provide the code causing the issue + a stacktrace w/ line numbers?

@gitlaura
Copy link
Author

I'm building an ios app for uProxy with cordova. I don't have the code up yet and it's a but complicated to build but will try to get it up soon.

The main problem with using iosrtc plugin is that I can't registerGlobals() until the device is ready, but I have a script that loads that uses RTCPeerConnection, RTCIceCandidate, and RTCSessionDescription before 'deviceready' fires. I have been trying to set window.RTCPeerConnection (and the other two functions) = cordova.plugins.iosrtc.RTCPeerConnection in a separate script before 'deviceready' is fired. I'm pretty sure this is causing the TypeError.

Have you seen anyone successfully set these functions before 'deviceready' fires?

@yocontra
Copy link

@gitlaura I actually wrote something for this (for the temasys webrtc plugin) - it mocks the RTC objects while they are loading, then replays the actions on the real ones when they are ready.

https://github.com/contra/rtc-everywhere/blob/master/lib/temasys/MockRTC.js

You can modify that pretty easily to work with this plugin

@ibc
Copy link
Collaborator

ibc commented Jan 21, 2016

@gitlaura may you please confirm if the error you experience happens here?:

https://github.com/eface2face/cordova-plugin-iosrtc/blob/master/js/videoElementsHandler.js#L288

@ibc
Copy link
Collaborator

ibc commented Jan 21, 2016

The main problem with using iosrtc plugin is that I can't registerGlobals() until the device is ready, but I have a script that loads that uses RTCPeerConnection, RTCIceCandidate, and RTCSessionDescription before 'deviceready' fires. I have been trying to set window.RTCPeerConnection (and the other two functions) = cordova.plugins.iosrtc.RTCPeerConnection in a separate script before 'deviceready' is fired. I'm pretty sure this is causing the TypeError.

This is how Cordova works, nothing to do here. Your JS app needs to be adapted to the Cordova design.

A very hard hack is the following (assuming somewebrtcsignalinglib.js if your JS script requiring window.RTCPeerConnection to exist on load time):

<script type="text/javascript">
    window.addEventListener('load', function()
    {
        console.log('DOM loaded');

        document.addEventListener('deviceready', function()
        {
            var script = document.createElement('script');

            script.type = 'text/javascript';
            script.src = 'libs/somewebrtcsignalinglib.js';
            script.async = false;  // IMPORTANT
            document.getElementsByTagName('head')[0].appendChild(script);
        });
    });
</script>

This <script> stuff must be added into your main index.html.

@gitlaura
Copy link
Author

Okay, thanks for your help. Working on waiting to load the scripts until after 'deviceready'.

@ibc
Copy link
Collaborator

ibc commented Jan 22, 2016

@gitlaura that should work (I mean: it works for me)

@gitlaura
Copy link
Author

After more debugging, I discovered that I'm getting 'TypeError: Attempted to assign to readonly property' due to line 3343 in cordova-plugin-iosrtc.js:

event.cancelable = true;

This appears to be a readonly property that can't be changed after the event is initialized. Has anyone else run into this problem? I can only get my application to work after commenting this line out.

@gitlaura gitlaura reopened this Jan 27, 2016
@ibc
Copy link
Collaborator

ibc commented Jan 28, 2016

@gitlaura it seems to be an issue in the yaeti module (which implementes the DOM EventTarget interface). Since the given event is a real DOM Event object we should not try to set its cancelable property (which is read only according to the spec).

Will fix it and release a new version of the plugin with an updated version of the yaeti dependency.

@ibc ibc closed this as completed in 51869ac Jan 28, 2016
@gitlaura
Copy link
Author

Thank you!

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

No branches or pull requests

4 participants