From 4885600ecc369aa2e30a65de8dd7a410f13c34df Mon Sep 17 00:00:00 2001
From: heyujie <516346543@qq.com>
Date: 星期一, 24 五月 2021 11:25:04 +0800
Subject: [PATCH] 解决app通信问题

---
 node_modules/mqtt/test/server.js |   32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/node_modules/mqtt/test/server.js b/node_modules/mqtt/test/server.js
index 00c7ec7..3baf7f1 100644
--- a/node_modules/mqtt/test/server.js
+++ b/node_modules/mqtt/test/server.js
@@ -5,11 +5,14 @@
 var inherits = require('inherits')
 var Connection = require('mqtt-connection')
 var MqttServer
+var FastMqttServer
 var MqttSecureServer
 
 function setupConnection (duplex) {
-  var connection = new Connection(duplex)
-  this.emit('client', connection)
+  var that = this
+  var connection = new Connection(duplex, function () {
+    that.emit('client', connection)
+  })
 }
 
 /*
@@ -34,6 +37,31 @@
 }
 inherits(MqttServer, net.Server)
 
+/*
+ * FastMqttServer(w/o waiting for initialization)
+ *
+ * @param {Function} listener - fired on client connection
+ */
+FastMqttServer = module.exports.FastMqttServer = function Server (listener) {
+  if (!(this instanceof Server)) {
+    return new Server(listener)
+  }
+
+  net.Server.call(this)
+
+  this.on('connection', function (duplex) {
+    var connection = new Connection(duplex)
+    this.emit('client', connection)
+  })
+
+  if (listener) {
+    this.on('client', listener)
+  }
+
+  return this
+}
+inherits(FastMqttServer, net.Server)
+
 /**
  * MqttSecureServer
  *

--
Gitblit v1.8.0