Giter Site home page Giter Site logo

crossbario / autobahn-js Goto Github PK

View Code? Open in Web Editor NEW
1.4K 56.0 228.0 5.79 MB

WAMP in JavaScript for Browsers and NodeJS

Home Page: http://crossbar.io/autobahn

License: MIT License

Makefile 3.91% Python 1.79% JavaScript 88.20% HTML 5.53% Dockerfile 0.29% Shell 0.27%
javascript websocket real-time wamp rpc pubsub autobahn nodejs html5

autobahn-js's People

Contributors

0xflotus avatar 2roy999 avatar adamchainz avatar agronholm avatar andremiras avatar arnoschn avatar cnlpete avatar dandv avatar dynalon avatar goeddea avatar gruns avatar hugohenrique avatar igorw avatar ilmiali avatar jameshilliard avatar johannwagner avatar johngeorgewright avatar justintarthur avatar markope avatar meejah avatar oberstet avatar om26er avatar rafzi avatar ryanhope avatar samson84 avatar simlgce avatar svvac avatar thomashornschuh avatar tmhannes avatar wangjia184 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autobahn-js's Issues

Getting all subscriptions (PubSub)

Hi,

I'm wondering if there is any method to get all subscriptions from a current session? I'm facing a situation where I want to unsubscribe from all channels, but I can't get it. I would suggest a getSubscriptions and an unsubscribeAllSubscriptions method. For example I'm connected to "/event/push/order/13" and I would disconnect from all channels like "/event/push/order/*"

Currently I'm doing it this way:
https://gist.github.com/jbbrunsveld/f6c6b35581720fbf80a5

Add option to not send subprotocol headers

Hello, I'm making a WAMP module for the Play Framework. Unfortunately, their WebSocket handler rejects all requests with the protocol header set...

If I override the _construct method with:

         ab._construct = function (url, protocols) {
            if ("WebSocket" in window) {
               // Chrome, MSIE, newer Firefox
               return new WebSocket(url);
            } else if ("MozWebSocket" in window) {
               // older versions of Firefox prefix the WebSocket object
               return new MozWebSocket(url);
            } else {
               return null;
            }
         };

everything works as expected. Can we get an option to leave out the protocol header?

Thanks!

not all details logged in default 'onhangup' handler

On connection closed/lost, Autobahn passes three arguments to the 'onhangup' handler: code, reason and detail.
If no 'onhangup' handler is passed to ab.connect, then the default is to log to the console.
This currently only logs one argument, 'reason'. (line 1048)

ab.log on IE

"Das Objekt unterstützt die Eigenschaft oder Methode "group" nicht"

getting remote ip - rookie question

looking at ws.upgradeReq.headers I see the following, but how can I get the remote IP?

{ upgrade: 'websocket',
connection: 'Upgrade',
host: 'localhost:8080',
origin: 'http://localhost',
pragma: 'no-cache',
'cache-control': 'no-cache',
'sec-websocket-key': '03zgRif7kl80v7JM+rDg7w==',
'sec-websocket-version': '13',
'sec-websocket-extensions': 'x-webkit-deflate-frame',
'user-agent': 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/31.0.1650.63 Chrome/31.0.1650.63 Safari/537.36' }

Multiple handlers for subscriptions

Attaching multiple client-side event handlers to one and the same subscription:

function handler1(args, kwargs, details) { ... }
function handler2(args, kwargs, details) { ... }

session.subscribe('com.myapp.topic1').then(
   function (subscription) {
      subscription.watch(handler1);
      subscription.watch(handler2);
   }
);

Essentially, the following 2 would be equivalent

session.subscribe('com.myapp.topic1', handler1);

and

session.subscribe('com.myapp.topic1').then(
   function (subscription) {
      subscription.watch(handler1);
   }
);

The difference is: the latter form allows to attach multiple event handlers to one and the same subscription.

AMD support

Is there any chance in getting AMD support? I don't use ExtJS, so it would be nice to have other formats supported.

I could supply a PR if it's something you'd accept. I don't know your workflow, but the AMD wrapper could be automated with a build script (doesn't look like your scons script does that with the ExtJS port).

It would also be nice to have CommonJS support.

Forward call result detail info in `Result`

Currently, call result detail does not yet contain a lot useful info. There is progress flag, but this is processed by AutobahnJS internally.

We could however forward call result detail from WAMP message in attributes of wrapped results (instances of Result).

wrong exception when subscribing second time

The second time you try to subscribe the client always throws 'already subscribed for topic' even though the server could reject the first subscription -

for example i'm using AutobahnPython -

@exportSub("subscribe", True)
  def subscribe(self,topicUriPrefix,topicUriSuffix):
      return False

Client-side timeout of RPCs

Provide variant 1 of the following 3 in AutobahnJS:

  1. timeout/reject the promise client-side without telling the server, and should the server respond later, silently ignore the response (which might be a success or error response)
  2. timeout/reject the promise client-side and actively cancel the call
  3. call server with timeout communicated. timeout call execution on server-side, and return error ("call timeout")

Better WS connect error detection/reporting

Detect problems like:

407 Proxy Authentication Required
TLS certificate invalid / denied
WS host unreachable
..

Make that always logged.
Make that shown in UI.

We need to have that to track down probs of corporate users ..

'exclude_me' not working (?)

Try the following in two browser tab consoles with established WAMP session to the same router:

Tab 1:

var testreceive = function(args, kwargs, details) { console.log("testreceive", args, kwargs, details); }; sess.subscribe("com.myapp.hello", testreceive);

sess.publish('com.myapp.hello', ['Hello, world!'], {}, {exclude_me: false});

--> no received event

Tab 2:

sess.publish('com.myapp.hello', ['Hello, world!']);

--> event in Tab 1 received

subscriptionObject.unsubscribe() vs. session.unsubscribe(subscriptionID)

Presently a subscription is canceled by doing 'subscriptionObject.unsubscribe()'.

To me it would feel more natural to do 'session.unsubscribe(subscriptionID)'

In the latter case, all interactions regarding subscriptions etc. are via the session object.
In the present state of things, unsubscribe and unregister break this pattern.

Using a javascript loader(such as requirejs) to load autobahnjs

Hi!

First of all, great library! 👍

I'm using requirejs to load dependencies. Whenjs, is AMD compliant, but sadly AutobahnJS is not (I've read the issue: #20)

I'm loading the autobahn.js directly from the cloned repository and not the bundle file(which includes whenjs - https://autobahn.s3.amazonaws.com/js/autobahn.js) as I'd rather keep autobahn and when separate.

Whenjs loads perfectly fine. However, when loading autobahns, I always get the error that when is undefined. I have also tried loading the bundled version to see if that works....but no luck.

I've posted a question on SO: http://stackoverflow.com/questions/19408177/getting-dependencies-to-load-correctly-in-requirejs-autobahn-and-whenjs

If you have any pointers how I could solve this problem or if you could point me in the right direction that would be great :-)

Once again, great library. Keep up the good work :-)

Option to receive all call results as `Result` objects

Currently, a call result is wrapped into Result if and only if the result has more than one positional result and/or a keyword result.

Consequently, user code expecting to receive complex results (or mixed simple and complex results) will need to test for type of result.

We might add a global option that will make all results (simple or not) wrapped in Result.

Provide callback executed when maxRetries is exceeded

As best I can tell this feature does not exist, but it would be quite handy to have a callback I can provide to ab.connect either in the options or as an argument.

Here's what that might look like from an API point of view:

ab.connect(
   wsuri,
   function (session) {/* ...*/},
   function (code, reason, detail) {/* ...*/},
   // The session options
   {
      'maxRetries': 60,
      'retryDelay': 2000,
      'retryExceededCallback': function(){
          SomeTransport.SwitchToAjaxCalls();
      }
   }
);

web browsers compatibility bug

autobahn.js has a tiny bug in obsoleted web browsers like IE7, which leads to failure of reconnect.

There are two appearances of the following line in source code
window.setTimeout(ab._connect, peer.options.retryDelay, peer);

It should be modified to
var fun = (function (p) { return function () { ab._connect(p); } })(peer);
window.setTimeout(fun, peer.options.retryDelay);

For more information, please refer to https://groups.google.com/forum/#!topic/autobahnws/MCgGYj1brWI

Connection loss: reject outstanding RPC

When a caller initiates a RPC, it might want to specify that the promise returned should be automatically rejected when the connection is lost.

The main problem is API .. see #24

Running AutobahnJS without a browser

I have been experimenting with writing some test cases in JS using Mocha however when I run it I get error messages about AutobahnJS window not being defined. Is there a way around this without needing to use AutobahnPython?

Pub or Sub with prefix sends incorrect topic name in request

I am not sure but current behavior is weird and seems to be a bug.

If I create a prefix, let's say

sess.prefix("test", "http://example.org/test#");

and then use it like this

sess.subscribe('test:foobar');

The real call is made with "test:foobar" instead of http://example.org/test#foobar
The tutorial http://autobahn.ws/js/tutorials/pubsub in "Topic URIs" section says:

Calling the 'prefix' method (line 9) has now established 'event' as shorthand for

http://example.com/events/myevent/

By using the prefix, we can write

event:firstevent

instead of

http://example.com/events/myevent/firstevent

So the real behavior differs from the documentation.

Check these lines:
https://github.com/tavendo/AutobahnJS/blob/master/autobahn/autobahn.js#L712
https://github.com/tavendo/AutobahnJS/blob/master/autobahn/autobahn.js#L767

A msg which is sent contains "topicuri" var instead of "rtopicuri".

Support ES6 Promises

Probably we want to support ES6 Promises: http://www.html5rocks.com/en/tutorials/es6/promises/

However, those have a weird API:

var promise = new Promise(function(resolve, reject) {
  // do a thing, possibly async, then…

  if (/* everything turned out fine */) {
    resolve("Stuff worked!");
  }
  else {
    reject(Error("It broke"));
  }
});

which we could probably wrap up like this:

var p = {};
p.promise = new Promise(function (resolve, reject) {
    p.resolve = resolve;
    p.reject = reject;
});

Require.js loading issue

When loading autobahn as an AMD module I get the following error
Uncaught ReferenceError: ab is not defined with the following sample :

<!DOCTYPE html>
<html>
<body>
<script src="//requirejs.org/docs/release/2.1.11/minified/require.js"></script>
<script>
    require.config({
        baseUrl: ".",
        paths: {
            "autobahn": "//autobahn.s3.amazonaws.com/js/autobahn",
            "when": "//cdnjs.cloudflare.com/ajax/libs/when/2.7.1/when"
        },
        shim: {
            "autobahn": {
                deps: ["when"]
            }
        }
    });
    require(["autobahn"], function(autobahn) {
        console.log(autobahn);
    });
</script>
</body>
</html>

Am I doing something wrong or is this a bug ? I've looking for previous PR and it seems #49 should have corrected this problem according to @hugohenrique who related the same issue in #35 .

Automatic reestablishment of prefixes and subscriptions upon reconnect

The lifetime of topic subscription with AutobahnJS starts with subscribe() and ends with unsubscribe() or at latest with the end of the session.

An application may want to resubscribe all topics upon a reconnect of session automatically.

API-wise, the only thing needed would be an option to activate this behavior.

Internally, the subscription table with all event handler should be saved when the session is lost, and all subscription reactivated upon reconnect.

next-gen support matrix

Support Matrix for next AutobahnJS:

  • Promise type (ECMA6 Promise, when, jQuery Deferred)
  • Module system (AMD, RequireJS, ..)
  • Browser deployment (UI thread, dedicated/shared worker)
  • NodeJS deployment (which WS library?)
  • PostgreSQL deployment (PL/V89

[enhancement] Add missing bower.json.

Hey, maintainer(s) of tavendo/AutobahnJS!

We at VersionEye are working hard to keep up the quality of the bower's registry.

We just finished our initial analysis of the quality of the Bower.io registry:

7530 - registered packages, 224 of them doesnt exists anymore;

We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).

Sadly, your library tavendo/AutobahnJS is one of them.

Can you spare 15 minutes to help us to make Bower better?

Just add a new file bower.json and change attributes.

{
  "name": "tavendo/AutobahnJS",
  "version": "1.0.0",
  "main": "path/to/main.css",
  "description": "please add it",
  "license": "Eclipse",
  "ignore": [
    ".jshintrc",
    "**/*.txt"
  ],
  "dependencies": {
    "<dependency_name>": "<semantic_version>",
    "<dependency_name>": "<Local_folder>",
    "<dependency_name>": "<package>"
  },
  "devDependencies": {
    "<test-framework-name>": "<version>"
  }
}

Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.

NB! Please validate your bower.json with jsonlint before commiting your updates.

Thank you!

Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!

check arguments for publishes

Presently, when doing a publish with incorrect arguments, this results in a closing of the session without any error feedback in the client

Example:

session.publish("com.myapp.topic1", "foobar");

There should be some checking and JS-side error feedback.

ID generation improvement?

I'm not 100% of the requirements around IDs, but looking at the lines from the code:

https://github.com/tavendo/AutobahnJS/blob/master/autobahn/autobahn.js#L177

ab._idchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
ab._idlen = 16;
ab._newid = function () {
   var id = "";
   for (var i = 0; i < ab._idlen; i += 1) {
      id += ab._idchars.charAt(Math.floor(Math.random() * ab._idchars.length));
   }
   return id;
};

It might be more useful to generate IDs as:

ab._entropySize = _32;
ab._newid = function () {
    return (Math.floor(Math.random() * ab._entropySize)).toString(36)
}

This removes dependencies on things like the long string, needing to run a for loop and build the string char by char, so the final impact is it's faster and less code. The downside is we don't have 16 chars each time.

Just a thought for an improvement. If it makes sense I'll do a pull request, but I figured I would ask here if it breaks something else before that.

No handling of connections suspended by a proxy

Sometimes a proxy server that doesn't mange websockets correctly will be used (sometimes on the client's network somewhere also), and when this happens the request can be forever in a state of pending, saying the "connection is established" on my server but the client will never reach the onOpen callback.

This is kind of tricky because there's no clear way to test for it.

One such proxy that has this behavior is pound: http://www.apsis.ch/pound/

To be more clear here's what happens step-by-step:

  1. Client requests upgrade connection via ab
  2. Request is passed through proxy to WebSocketServer
  3. Upgrade response is sent back to proxy
  4. Proxy suspends all socket traffic because it can't deal with it.
  5. connection.onOpen is never called while pending

session.log

Add log function to session object: logs within a group that is named with a (optional) user settable session name and WAMP session ID

Autobahn.Connection should mirror readyState

I want to be able to write code like
if(connection.isOpen) { setTimeout(askForPolygon, 3000); }

I can ask for connetion._websocket.readyState, but ._websocket doesn't always exist and that doesn't tell me anything about the WAMP-level connection.

Localize the message from Autobahn JS

Hi,

I was wondering if I can localize and customize the messages like "Connection lost - scheduled 1th reconnect to occur in 5 second(s)." by passing the init setting to Autobahn JS?

Another question, can we have callback when lost connection and retry happen? I hope we can have event callback when something happen in background.

Thanks

Single SubProtocol

In the case where the connect method is used to include sub-protocol information, there is a comma-blank being added to the end of the text.

current: Sec-WebSocket-Protocol: gabbo, \r\n

desired: Sec-WebSocket-Protocol: gabbo\r\n

Some websocket servers don't like this, and will refuse the websocket upgrade.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.