Comments (5)
Should be possible indeed, we did something similar in the new Go client. I've used a map to dispatch the responses back: https://github.com/emitter-io/go/blob/master/v2/emitter.go#L400-L417
Feel free to contribute back!
from javascript.
Here's what happens in Go library to make this work. I need to highlight that for this to work you'd need to send presence/keygen/me publish messages with QoS = 1.
- [client] with
QoS=1
, the client generates aMessageID
which goes into the MQTT header - [client] adds the callback with
MessageID
key into a map and waits for a response or an error - [broker] receives the Publish, gets the
MessageID
and adds it into as areq
into the JSON - [client] receives the Publish (reponse or error) and looks for a
req
key in the JSON response, if present invokes the appropriate callback
from javascript.
I applied @kelindar 's instructions to the C# GenerateKey function.
I used QoS = 1 calling the Publish1 function.
public ushort GenerateKey(string secretKey, string channel, SecurityAccess securityAccess, int ttl, KeygenHandler handler)
{
// Prepare the request
var request = new KeygenRequest();
request.Key = secretKey;
request.Channel = channel;
request.Type = securityAccess;
request.Ttl = ttl;
// Register the handler
this.KeygenHandlers[channel] = handler;
// Serialize and publish the request
return this.Publish1("emitter/", "keygen/", Encoding.UTF8.GetBytes(request.ToJson()));
}
public ushort Publish1(string key, string channel, byte[] message)
{
return this.Client.Publish(FormatChannel(key, channel), message, MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE, false);
}
But in the OnMqttMsgPublishReceived event handler, messageId always equals to zero.
Any ideas?
from javascript.
I also tried with my Dart library to see if the problem was with the C# mqtt library.
In the Dart library I send keygen message with QoS = 1.
keygen(String key, String channel, String type, int ttl) {
var request = {"key": key, "channel": channel, "type": type, "ttl": ttl};
_mqtt.publishMessage(
"emitter/keygen/", MqttQos.atLeastOnce, _payload(jsonEncode(request)));
return this;
}
However the response to the keygen message has a message id = 0 just like with the C# library.
PS: I made the Dart tests with Emitter cloud.
from javascript.
Ok, I figured it out.
I was looking for a message id in the mqtt message because I did not read @kelindar 's instructions carefully.
Instead, I have to match the message id of the publish request with the req
value in the JSON response.
@Florimond , is it possible to implement this in the Javascript and C# libraries?
Thanks :)
from javascript.
Related Issues (9)
- How to modify and rebuild? HOT 3
- Unable to connect using the free account HOT 3
- is that okay to expose channel key in frontend? HOT 2
- Recent updates are not released HOT 2
- keygen Example HOT 1
- Using in React HOT 4
- HTTPS CDN HOT 1
- Does not auto-reconnect 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 javascript.