Long-Poll as fallback for older browsers (Android Webkit in this case). Problems with 'Access-Control-Allow-Origin' header.

#1

Hello,

I’m currently using Crossbar for a WAMP application mainly designed for devices. There’s a known fact that Android 4.3 and below doesn’t support websockets and I was looking to use long-polling as a fallback solution. I can’t use the flash sockets solution since there’s no flash support in the android browser.

The thing is the WAMP server doesn’t set or dissallows the Access-Control-Allow-Origin by default. Tried searching for a solution on this but couldn’t find anything useful. Are there some options to set in config.json to enable access on some origins? Any other advice on how to resolve this?

Thanks for your time.

The error I’m getting is as follows:

XMLHttpRequest cannot load http://my_local_server.dev:5050/lp/open. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://my_local_client.dev’ is therefore not allowed access. The response
had HTTP status code 501

``

My config.json:

{

“controller”: {

},

“workers”: [

  {

     "type": "router",

     "options": {

        "pythonpath": [".."]

     },

     "realms": [

        {

           "name": "realm.unlock.notify",

           "roles": [

              {

                 "name": "anonymous",

                 "permissions": [

                    {

                       "uri": "*",

                       "publish": true,

                       "subscribe": true,

                       "call": false,

                       "register": false

                    }

                 ]

              }

           ]

        }

     ],

     "transports": [

        {

           "type": "web",

           "endpoint": {

              "type": "tcp",

              "port": 5050

           },

           "paths": {

              "/": {

                 "type": "static",

                 "directory": "../unlock/static"

              },

              "ws": {

                 "type": "websocket"

              },

              **"lp": {**

"type": “longpoll”,

"options": {

"debug": true,

"session_timeout": 30

}

}

           }

        }

     ]

  },

  {

     "type": "container",

     "options": {

        "pythonpath": [".."]

     },

     "components": [

        {

           "type": "class",

           "classname": "unlock.session.AppSession",

           "realm": "realm.unlock.notify",

           "transport": {

              "type": "websocket",

              "endpoint": {

                 "type": "tcp",

                 "host": "127.0.0.1",

                 "port": 5050

              },

              "url": "ws://127.0.0.1:5050/ws"

           }

        }

     ]

  }

]

}

``

0 Likes

#2

Stelian,

The thing is the WAMP server doesn't set or dissallows the
Access-Control-Allow-Origin by default. Tried searching for a solution

It's a know bug that needs fixing in AutobahnPython

https://github.com/tavendo/AutobahnPython/issues/284

No hard to do though.

Cheers,
/Tobias

0 Likes

#3

Thanks for answering!

Any ETA on a possible fix? Is it a matter of weeks or months? I know you’re pretty busy and stuff, just want to pass an answer to the client and decide if we’re going to implement something else as a fallback or delay.

···

On Wednesday, January 28, 2015 at 6:04:24 PM UTC+2, Stelian Dima wrote:

Hello,

I’m currently using Crossbar for a WAMP application mainly designed for devices. There’s a known fact that Android 4.3 and below doesn’t support websockets and I was looking to use long-polling as a fallback solution. I can’t use the flash sockets solution since there’s no flash support in the android browser.

The thing is the WAMP server doesn’t set or dissallows the Access-Control-Allow-Origin by default. Tried searching for a solution on this but couldn’t find anything useful. Are there some options to set in config.json to enable access on some origins? Any other advice on how to resolve this?

Thanks for your time.

The error I’m getting is as follows:

XMLHttpRequest cannot load http://my_local_server.dev:5050/lp/open. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://my_local_client.dev’ is therefore not allowed access. The response
had HTTP status code 501

``

My config.json:

{

“controller”: {

},

“workers”: [

  {
     "type": "router",
     "options": {
        "pythonpath": [".."]
     },
     "realms": [
        {
           "name": "realm.unlock.notify",
           "roles": [
              {
                 "name": "anonymous",
                 "permissions": [
                    {
                       "uri": "*",
                       "publish": true,
                       "subscribe": true,
                       "call": false,
                       "register": false
                    }
                 ]
              }
           ]
        }
     ],
     "transports": [
        {
           "type": "web",
           "endpoint": {
              "type": "tcp",
              "port": 5050
           },
           "paths": {
              "/": {
                 "type": "static",
                 "directory": "../unlock/static"
              },
              "ws": {
                 "type": "websocket"
              },
              **"lp": {**

"type": “longpoll”,

"options": {

"debug": true,

"session_timeout": 30

}

}

           }
        }
     ]
  },
  {
     "type": "container",
     "options": {
        "pythonpath": [".."]
     },
     "components": [
        {
           "type": "class",
           "classname": "unlock.session.AppSession",
           "realm": "realm.unlock.notify",
           "transport": {
              "type": "websocket",
              "endpoint": {
                 "type": "tcp",
                 "host": "127.0.0.1",
                 "port": 5050
              },
              "url": "ws://[127.0.0.1:5050/ws](http://127.0.0.1:5050/ws)"
           }
        }
     ]
  }

]

}

``

0 Likes