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

TypeError: Cannot read property 'addRule' of undefined #34

Closed
xo1988 opened this issue Jan 21, 2016 · 29 comments
Closed

TypeError: Cannot read property 'addRule' of undefined #34

xo1988 opened this issue Jan 21, 2016 · 29 comments

Comments

@xo1988
Copy link

xo1988 commented Jan 21, 2016

Using macx64, nwjs, wcjs-player, and I want to open child windows using var gui = require("nw.gui"); and gui.Window.open('player.html');
when child window onload i will init the wcjs-player to play video

@jaruba
Copy link
Owner

jaruba commented Jan 21, 2016

Your pages need to at least have <style></style> in the header, otherwise wcjs-player can't inject it's styles into the page.

@xo1988
Copy link
Author

xo1988 commented Jan 21, 2016

sorry, I add the body of the question late...

@xo1988
Copy link
Author

xo1988 commented Jan 21, 2016

it seem that wcjs-player just can get element located at main html, at child html cannot get the element define in it, and if I am not define the <style></style> in main html, will report TypeError: Cannot read property 'addRule' of undefined, and if I do it, and define

in child html, will report "Uncaught TypeError: Cannot read property 'firstChild' of null".
Do you have demo about using wcjs-player with nwjs play video in child html?

@jaruba
Copy link
Owner

jaruba commented Jan 21, 2016

I think that's a NW.js bug, it's possible that when you call window in the child window, it actually returns the window of the parent instead of the child window.

I've seen NW.js doing this a few times in other circumstances.

@jaruba
Copy link
Owner

jaruba commented Jan 21, 2016

Try setting a timeout on require('wcjs-player')

@jaruba
Copy link
Owner

jaruba commented Jan 21, 2016

Also try loading it after the document is ready...

@xo1988
Copy link
Author

xo1988 commented Jan 21, 2016

I try like below:

            $(document).ready(function () {
                setTimeout(function () {
                    var wjs = require("wcjs-player");
                    var player = new wjs("#player").addPlayer({ autoplay: true});
                    var playerUrl = "http://**.mp4";
                    player.addPlaylist(playerUrl);
                },1000);
            })

but it still report "Uncaught TypeError: Cannot read property 'firstChild' of null".

@xo1988
Copy link
Author

xo1988 commented Jan 21, 2016

and I try with JQuery, test like below in child window. it works.

                $("#player").append(
                        "got you"
                );

do you have any route to avoid this circumstances?

@jaruba
Copy link
Owner

jaruba commented Jan 21, 2016

try console.log(window.document.getElementById('player'))

@xo1988
Copy link
Author

xo1988 commented Jan 21, 2016

define div in child html like below:

                    <div id="player" class="pp"></div>

then console.log(window.document.getElementById('player').className) got "pp"
it seem window work well, but when using

                    var wjs = require("wcjs-player");
                    var player = new wjs("#player").addPlayer({ autoplay: true});
                    var playerUrl = "http://**.mp4";
                    player.addPlaylist(playerUrl);

report

[3941:0121/215101:ERROR:nw_shell.cc(336)] TypeError: Cannot read property 'firstChild' of null
    at new wjs (/Users/wangyu/test/video/node_modules/wcjs-player/index.js:75:70)

@jaruba
Copy link
Owner

jaruba commented Jan 21, 2016

That makes no sense.. if you look at line 75:
https://github.com/jaruba/wcjs-player/blob/master/index.js#L75

You will see:

if (window.document.getElementById(this.context.substring(1)).firstChild) {

in your case, this results to:

if (window.document.getElementById('player').firstChild) {

and the error says that:

window.document.getElementById('player')

is null.

@jaruba
Copy link
Owner

jaruba commented Jan 21, 2016

Are you by any chance doing require('wcjs-player') in the parent window too?

@xo1988
Copy link
Author

xo1988 commented Jan 21, 2016

code like below:
index.html

<html>
<head><style></style></head>
    <body>
        <script>
            var gui = require("nw.gui");
            gui.Window.open('player.html');
        </script>
    </body>
</html>

player.html

<html>
<head>
    <style>
        body,html{ width: 100%; height: 100%; padding: 0px; margin:0px }
        #player { width: 100%; height: 100% }
    </style>
</head>
    <body>
        <div id="player"></div>
        <script>
            var wjs = require("wcjs-player");
            var player = new wjs("#player").addPlayer({ autoplay: true});
            var playerUrl = "http://**.mp4";
            player.addPlaylist(playerUrl);
        </script>
    </body>
</html>

@jaruba
Copy link
Owner

jaruba commented Jan 21, 2016

So you have 2 players? One in your parent window and one in a child window?

@xo1988
Copy link
Author

xo1988 commented Jan 22, 2016

just have one player in player.html

@xo1988
Copy link
Author

xo1988 commented Feb 5, 2016

using electron work well...

@xo1988 xo1988 closed this as completed Feb 5, 2016
@OancaAndrei
Copy link

Hi, I had the same issues when using version 0.13.0-beta4 of nwjs. So I decided to downgrade to 0.12.3 and everything seems to work now.
Hope this helps somebody.

@RSATom
Copy link
Contributor

RSATom commented Feb 6, 2016

@OancaAndrei, any reason to use beta instead of stable?

@OancaAndrei
Copy link

No reason at all actually, I simply wanted to have the latest build. I didn't expect it to not work and because the issue wasn't really solved I thought to share my (let's say) solution.

@jaruba
Copy link
Owner

jaruba commented Feb 6, 2016

@OancaAndrei did you build wcjs yourself in the npm install process? or did you use wcjs-prebuilt?

@jaruba
Copy link
Owner

jaruba commented Feb 6, 2016

It's possible that NW.js 0.13.0 didn't work for you because you built wcjs by default for NW.js 0.12.3

@OancaAndrei
Copy link

I used the prebuilt one and I might had forgot to change the version when recompiling... I remember changing it when compiling for electron but not for nwjs. I'll check it now.

@OancaAndrei
Copy link

I tried recompiling webchimera.js for nwjs v0.13.0-beta4 but unfortunately it doesn't work. The linker complains about some not found links.

Here's the log:

JsVlcPlayer.obj : error LNK2019: unresolved external symbol "void __cdecl node::AtExit(void (__cdecl*)(void *),void *)" (?AtExit@node@@YAXP6AXPAX@Z0@Z) referenced in function "public: static void __cdecl JsVlcPlayer::initJsApi(class v8::Local<class v8::Object> const &)" (?initJsApi@JsVlcPlayer@@SAXABV?$Local@VObject@v8@@@v8@@@Z) [path\webchimera.js\build\WebChimera.js.vcxproj]
JsVlcPlayer.obj : error LNK2019: unresolved external symbol _uv_default_loop referenced in function "private: __thiscall JsVlcPlayer::JsVlcPlayer(class v8::Local<class v8::Object> &,class v8::Local<class v8::Array> const &)" (??0JsVlcPlayer@@AAE@AAV?$Local@VObject@v8@@@v8@@ABV?$Local@VArray@v8@@@2@@Z) [path\webchimera.js\build\WebChimera.js.vcxproj]
VlcVideoOutput.obj : error LNK2001: external symbol _uv_default_loop unresolved [path\webchimera.js\build\WebChimera.js.vcxproj]
JsVlcPlayer.obj : error LNK2019: unresolved external symbol _uv_close referenced in function "public: void __thiscall JsVlcPlayer::close(void)" (?close@JsVlcPlayer@@QAEXXZ) [path\webchimera.js\build\WebChimera.js.vcxproj]
VlcVideoOutput.obj : error LNK2001: external symbol _uv_close unresolved [path\webchimera.js\build\WebChimera.js.vcxproj]
JsVlcPlayer.obj : error LNK2019: unresolved external symbol _uv_async_init referenced in function "private: __thiscall JsVlcPlayer::JsVlcPlayer(class v8::Local<class v8::Object> &,class v8::Local<class v8::Array> const &)" (??0JsVlcPlayer@@AAE@AAV?$Local@VObject@v8@@@v8@@ABV?$Local@VArray@v8@@@2@@Z) [path\webchimera.js\build\WebChimera.js.vcxproj]
VlcVideoOutput.obj : error LNK2001: external symbol _uv_async_init unresolved [path\webchimera.js\build\WebChimera.js.vcxproj]
JsVlcPlayer.obj : error LNK2019: unresolved external symbol _uv_async_send referenced in function "private: virtual void __thiscall JsVlcPlayer::media_player_event(struct libvlc_event_t const *)" (?media_player_event@JsVlcPlayer@@EAEXPBUlibvlc_event_t@@@Z) [path\webchimera.js\build\WebChimera.js.vcxproj]
VlcVideoOutput.obj : error LNK2001: external symbol _uv_async_send unresolved [path\webchimera.js\build\WebChimera.js.vcxproj]
JsVlcPlayer.obj : error LNK2019: unresolved external symbol _uv_timer_init referenced in function "private: __thiscall JsVlcPlayer::JsVlcPlayer(class v8::Local<class v8::Object> &,class v8::Local<class v8::Array> const &)" (??0JsVlcPlayer@@AAE@AAV?$Local@VObject@v8@@@v8@@ABV?$Local@VArray@v8@@@2@@Z) [path\webchimera.js\build\WebChimera.js.vcxproj]
JsVlcPlayer.obj : error LNK2019: unresolved external symbol _uv_timer_start referenced in function "private: void __thiscall JsVlcPlayer::handleLibvlcEvent(struct libvlc_event_t const &)" (?handleLibvlcEvent@JsVlcPlayer@@AAEXABUlibvlc_event_t@@@Z) [path\webchimera.js\build\WebChimera.js.vcxproj]
JsVlcPlayer.obj : error LNK2019: unresolved external symbol _uv_timer_stop referenced in function "public: void __thiscall JsVlcPlayer::close(void)" (?close@JsVlcPlayer@@QAEXXZ) [path\webchimera.js\build\WebChimera.js.vcxproj]
WebChimera.obj : error LNK2019: unresolved external symbol _node_module_register referenced in function __register_WebChimera [path\webchimera.js\build\WebChimera.js.vcxproj]

Am I missing something?

Earlier with prebuilt I meant that I was using the prebuilt distribution of NW.js. So yes, I was compiling nwjs myself.

@jaruba
Copy link
Owner

jaruba commented Feb 6, 2016

@RSATom do you think these errors from nw.js 0.13 are also related to the vmem issue?

@RSATom
Copy link
Contributor

RSATom commented Feb 7, 2016

No. I think it's cmake-js issue.

@RSATom
Copy link
Contributor

RSATom commented Feb 7, 2016

@OancaAndrei, are you really need NW.js beta? tbh, I'm a little bit limited in free time, so don't know when will be able look at it. If you really need it, please create issue at https://github.com/RSATom/WebChimera.js/issues

@OancaAndrei
Copy link

Oh, don't worry about it. I won't use the 0.13 version until it gets out from beta stage.
Because facing the same problems, I thought that also @xo1988 might have downloaded the beta version of NW.js so I just wanted to point that out (the issue wasn't really closed in my opinion :) ).

BTW, thanks for your great work, both of you, @RSATom and @jaruba.

@RSATom
Copy link
Contributor

RSATom commented Feb 7, 2016

@OancaAndrei, good, thank you.

@jaruba
Copy link
Owner

jaruba commented Mar 20, 2016

@xo1988 Related to the issue of using NW.js with wcjs-player in a second window, we now have a hack for it.

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