Comments (5)
This is my python bias speaking, but There Should On Be One Way To Do It. The first form is more intuitive, and keeps the code shorter (I don't understand why I care about a subscription; that should be an internal object).
What I want is the behaviour of jQuery: .subscribe() should append handlers to a list, and you should have an .unsubscribe() which optionally takes the (previously subscribed) function to unsubscribe.
My use case is this: I have a stream of numbers coming from my server, and I want to feed them to d3 plots, to a simulated robot on a plot, and to the console for debugging. Maybe the debug prints can sit in one or the other handler, but it would be awkward (and cut across js files) to have both viewing features in one function. If Autobahn doesn't do multiplexing, I'll need the function I pass to .subscribe() be a multiplexer instead of directly being handlers I actually care about.
from autobahn-js.
Subscriptions are objects since for unsubscribing at the WAMP message level, you need to know the subscription ID - which is stored inside the JS subscription object returned.
Not sure if I get you: do you want attaching multiple handlers like this?
session.subscribe('com.myapp.topic1', handler1);
session.subscribe('com.myapp.topic1', handler2);
If so: this was the API of WAMP v1. Internally, subscriptions would be a dictionary indexed by topic. With WAMP v2 and pattern based subscriptions, this naive view of "topic ~ subscription" no longer holds true. Now, the subscription ID is returned asynchronously from the broker upon subscribing.
from autobahn-js.
Removing a handler from the list would work as "unwatching":
session.subscribe('com.myapp.topic1').then(
function (subscription) {
subscription.watch(handler1);
// stuff
subscription.unwatch(handler1);
}
);
Calling session.subscribe
multiple times returns the same subscription object.
For this we need to either use a broker to detect a duplicate subscription and return the existing subscription ID. Or, have a client-side map that uses key material from topic
and Options
.
from autobahn-js.
Agree with kousu that I shouldn't have to care where in my code I subscribe to a topic, and how often this happens.
My suggestion:
- Allow multiple, separate subscriptions using the simple syntax of
session.subscribe('com.myapp.topic1', handler1);
- These all return separate subscription objects / IDs, and can be unsubscribed individually.
- The library creates these objects, but only uses a single subscription under the hood
from autobahn-js.
Hi,
I had many subscription done on same topic name in different angular 2 component.
// in component 1
session.subscribe('com.myapp.topic1', handlerComponent1)
// in component 2
session.subscribe('com.myapp.topic1', handlerComponent2)
I need to unsubscribe them.
var subscriptions = session.subscriptions;
for (var index in subscriptions) {
let subs = subscriptions[index];
for (let sub_index in subs) {
let sub = subscriptions[index][sub_index];
let topic = sub.topic;
sub.unsubscribe().then(res => {
console.log(topic, 'unsubscribe', res);
});
}
}
And this now than troubles come.
I had all the time one subscription witch is not unsubscribe.
Any idea ?
UPDATE
I found a way !
Subscriptions as grouped in different arrays.
So i concat all of them and loop on each subscription in this single new array and this work.
Some unsubscribe Subscription promise return false but they are not anymore activated so i don't catch anymore handler on unsubscribed topic.
var subscriptions = [];
for (let index in session.subscriptions)
subscriptions = subscriptions.concat(session.subscriptions[index]);
for (let index in subscriptions) {
let subscription = subscriptions[index];
let topic = subscription.topic;
session.unsubscribe(subscription).then(res => {
console.log("unsubscribe", topic, res);
});
}
from autobahn-js.
Related Issues (20)
- Subprotocol error when creating connection with [email protected] HOT 9
- Connections failed on SSL HOT 2
- Is there any way to send a blob? HOT 1
- autobahn.Error should contain the "details" parameter HOT 1
- Add a HarmonyOS-supported polyfill
- uncaught referenceerror: cr is not defined at <anonymous>:2:3
- Implement Payload Passthru Mode HOT 1
- Release 22.10.1 HOT 3
- autobahn js => es6 ? HOT 3
- cbor: problem sending payload larger than 16kb HOT 2
- Release v22.11.1
- Support latest ws 8.x
- Wrapping/unwrapping invocation results HOT 7
- How disconnect or close connection? HOT 1
- Subscribe does not fire when something is published
- Session detached after new session attached, resulting in `wamp.error.procedure_already_exists` HOT 5
- can you make a rpc call outside of onopen ? so you dont have to make parrallel connections everytime you want to make a call ?
- Support call cancelling via AbortController
- WebSocket connection to 'wss://site.com/socket/' failed
- Correct copyright holder HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autobahn-js.