ptejada / ApePubSub

A PubSub JavaScript Framework for the APE Server
MIT License
10 stars 6 forks source link

'restored' event is not firing #24

Closed ghost closed 10 years ago

ghost commented 10 years ago
var aps = new APS(
    window.location.host, // my APE server is working on "https://([0-9]+).localhost"
    {
        restored: function() {
            console.log('Restore');
        },
        connect: function() {
            console.log('Connect');
        },
        ready: function() {
            console.log('Ready');
        }
    },
    {
        debug: true,
        secure: true
    }
);

aps.connect();

I put here some console.log()s but the execution does not reach them.

ptejada commented 10 years ago

Try joining a channel instead of using connect()

ghost commented 10 years ago
//aps.connect();
aps.sub('main', { joined: function(){ console.log('joined'); } });
ptejada commented 10 years ago

Wierd, I'll look into this.

ghost commented 10 years ago

On demo, after RESTORE, from the server is coming IDENT raw s1

But in my case this is not happening s2

lcharette commented 10 years ago

Which version of the server are you using? Did you update the server side scripts and restarted the server afterward?

Le 2014-06-08 à 13:35, moldcraft notifications@github.com a écrit :

On demo, after RESTORE, from the server is coming IDENT raw

But in my case this is not happening

— Reply to this email directly or view it on GitHub.

ghost commented 10 years ago

@lcharette I use latest version with updated server scripts.

Now I am debugging APE_Server/APScripts/framework/cmd_restore.js

When I add info.user.pipe.sendRaw('TEST_OK', {test: 'ok'}); it works s1

But when I try to access somehow info.user.channels info.user.pipe.sendRaw('TEST_OK', {channels: info.user.channels}); it does nothing s2 I think it's crashing, gives some fatal error.

In ape.log nothing appears. Is there any error.log I can look in?

I tried to run aped as root, nothing changes

ptejada commented 10 years ago

Hey,

It must be something with some custom server script. Even your initial example works as expected when tested with the server ape.ptejada.com.

http://jsfiddle.net/6sUvY/

Try unloading any custom scripts from your server.

ghost commented 10 years ago

I have no custom scripts (and I think I will not have in the near future, I use only 'inlinepush' from PHP and I think this is all my application will need)

Here is another debug I did in APE_Server/APScripts/framework/cmd_restore.js

//...
for(var name in info.user.channels){
    info.user.pipe.sendRaw('DEBUG1', {i: name});
    var channel = info.user.channels[name];
    Ape.triggerChannelEvent(channel, "restored", [info.user, channel]);
    Ape.triggerChannelEvent(channel, "pleaseWork", [info.user, channel]);
    info.user.pipe.sendRaw('DEBUG2', {i: name});
}
//...

s1

So Ape.triggerChannelEvent() is not working and not showing any errors.

ghost commented 10 years ago

Now I reinstalled everything (all my workspace is inside docker).

Nothing changes, the bug is still there

ptejada commented 10 years ago

Have you tried not using the secure flag. Also try using the long polling transport by setting the option transport: 'lp' and checking the network requests on DevTools.

It seems the server is not handling the RESTORE command at all.

Can you also provide the console output when you start the server in the foreground. On Jun 9, 2014 5:38 AM, "moldcraft" notifications@github.com wrote:

Now I reinstalled everything (all my workspace is inside docker http://www.docker.com/). Here is APE-Server compilation log http://sourcebox.io/d2b8405d57ede898d34ff21c55edc5d9. APE Server v1.1.3-DEV

Nothing changes

— Reply to this email directly or view it on GitHub https://github.com/ptejada/ApePubSub/issues/24#issuecomment-45475047.

ghost commented 10 years ago

Now I tried secure:false, moved everyting from https to http, transport:lp, nothing changed.

Console output:

[WARN] You have to run 'aped' as root to increase r_limit
   _   ___ ___ 
  /_\ | _ \ __|
 / _ \|  _/ _| 
/_/ \_\_| |___|
AJAX Push Engine

Bind on : 0.0.0.0:6969
Pid     : 529
Version : 1.1.3-DEV
Build   : Jun  9 2014 09:18:22
Author  : Weelya (contact@weelya.com)

[Module] [spidermonkey] Loading module : Javascript embedded (0.01) - Anthony Catel
[spidermonkey] : Loading script ../APScripts/framework/utils.js
[spidermonkey] : Loading script ../APScripts/framework/Request.js
[spidermonkey] : Loading script ../APScripts/framework/cmd_frame.js
[spidermonkey] : Loading script ../APScripts/framework/cmd_eventpush.js
[spidermonkey] : Loading script ../APScripts/framework/cmd_restore.js
[spidermonkey] : Loading script ../APScripts/framework/cmd_event.js
[spidermonkey] : Loading script ../APScripts/framework/cmd_inlinepush.js
[spidermonkey] : Loading script ../APScripts/framework/cmd_propupdate.js
[spidermonkey] : Loading script ../APScripts/framework/cmd_session_set.js
[spidermonkey] : Loading script ../APScripts/framework/hook_join.js
[spidermonkey] : Loading script ../APScripts/framework/hook_connect.js
[spidermonkey] : Loading script ../APScripts/framework/hook_events.js
[spidermonkey] : Loading script ../APScripts/framework/options.js
[spidermonkey] : Loading script ../APScripts/config.js

I found the problem.

I want to make my site on https, and if main https page tries to make request to http urls, the browser does not allow that.

s2

On APE I can't install ssl certificates so I use nginx in the middle.

My nginx config

server {
        listen 443;
        server_name ~^\d+\.mydomain\.dev$;

        location / {
                proxy_pass http://127.0.0.1:6969;
        }
}

When I changed transport:lp, the request for cmd:RESTORE was pending for some time, then it stoped with 502 bad gateway.

When I connected directly to APE port (without nginx in the middle)

var aps = new APS( window.location.host +':6969', ... );

Everything started to work

s1


Sorry for taking your time because that was my fault. (also sorry for my english)

But here are some questions:

(now I will try to find out maybe my nginx config is too simple and I need to put there some parameters for proxy to work properly)

ghost commented 10 years ago

I made it work by adding this to nginx config

server {
    #...

    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    #...
}

Thanks

lcharette commented 10 years ago

If you want to proxy ape on port 80 (or any one), you an also have a look at HaProxy which support websocket. There's a guide on the ape-server main wiki on GitHub.

Envoyé de mon iPhone

Le 2014-06-09 à 10:01, moldcraft notifications@github.com a écrit :

I made it to work by adding this to nginx config

server {

...

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

#...

} and using transport: 'lp' (ws does not work now, but its ok)

— Reply to this email directly or view it on GitHub.

ptejada commented 10 years ago

My host also proxies all my applications through and nginx front end server which also provides shared SSL. The websocket does work but not with the secure flag on. My guess is due to the shared SSL certificate.

Do you have a dedicated SSL certificate for your domain?

ghost commented 10 years ago

I generated a wildcard certificate (not bought), and added it to trusted certificates to Chrome.

The first page opens with warning that this certificate is untrusted, but I click "Allow" and on next page refresh it's not bothering me. This happens because my certificate is only for subdomains *.mydomain.dev , but not for mydomain.dev. I tried, but without success, to add to certificate SAN mydomain.dev

All subdomains works well and does not give warnings. So I set APE on {number}.mydomain.dev. For *.ape.mydomain.dev it doesn't work.