GithubHelp home page GithubHelp logo

Comments (5)

kelindar avatar kelindar commented on May 26, 2024

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.

kelindar avatar kelindar commented on May 26, 2024

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.

  1. [client] with QoS=1, the client generates a MessageID which goes into the MQTT header
  2. [client] adds the callback with MessageID key into a map and waits for a response or an error
  3. [broker] receives the Publish, gets the MessageID and adds it into as a req into the JSON
  4. [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.

postacik avatar postacik commented on May 26, 2024

@Florimond ,

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.

image

Any ideas?

from javascript.

postacik avatar postacik commented on May 26, 2024

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.

postacik avatar postacik commented on May 26, 2024

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)

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.