crossbario / autobahn-js Goto Github PK
View Code? Open in Web Editor NEWWAMP in JavaScript for Browsers and NodeJS
Home Page: http://crossbar.io/autobahn
License: MIT License
WAMP in JavaScript for Browsers and NodeJS
Home Page: http://crossbar.io/autobahn
License: MIT License
There is a Bower package for Autobahn, but the dist files are missing and the ”main” property in the bower.json is also missing. Would be a nice instead of having to build it yourself.
See: http://bower.io/#defining-a-package
add functionaltiy equal to the old 'ab.log'
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.
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
Add log function to session object: logs within a group that is named with a (optional) user settable session name and WAMP session ID
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();
}
}
);
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
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 .
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!
"Das Objekt unterstützt die Eigenschaft oder Methode "group" nicht"
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;
});
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
AutobahnPython already provides symmetric RPCs (calling a procedure on a client from a server).
https://github.com/tavendo/AutobahnPython/tree/master/examples/wamp/rpc/symmetric
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
.
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
Having the subscription URI (pattern) accessible as part of the subscription object which 'subscribe' returns would make debugging easier, since it can then be determined which subscriptions are active just by examining the objects on the console.
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:
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.
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 ..
When a connection is closed/lost, an app might want to handle RPCs outstanding (not yet returned), e.g. reject the promises, retry specific one's on connection reestablishment or inform the user.
With this code:
ab.connect(url, function(){}, function(){})
I get this error in Safari 5:
ReferenceError: Strict mode forbids implicit creation of global property 'peer'
Support Matrix for next AutobahnJS:
The build system currently uses Google Closure to optimized/minimize JS. This thing depends on Java, which sucks.
We should replace Google Closure with https://github.com/mishoo/UglifyJS. This is based on JS/Node and can be installed easily with npm.
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!
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
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?
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.
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 :-)
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
).
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.
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".
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)
Hello, this is not very important, but the link of closure has changed. They keep a zip file with the new link inside, but if it's of your interest and want to link it directly, the new direction is: http://dl.google.com/closure-compiler/compiler-latest.zip
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.
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' }
When there is a hard prob., and wont go away soon / anytime.
Stop reconnecting. Log that. Report in UI.
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
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.
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.
Provide variant 1 of the following 3 in AutobahnJS:
Upgrade CryptoJS .. there seem to be some API change from 2.5 => 3
I'm working on a dependency update
https://github.com/ExperiencePoint/AutobahnJS/commits/master
It seems to work on my side. Let me know if there's anything that should change before I make a pull request.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.