ngx-mqtt 中的 tcp 连接

tcp connection in ngx-mqtt

我使用 ngx-mqtt 连接到 angular 中的代理。但是连接只在ws(websocket)上,tcp连接没有做。

以下是出版商对图书馆的部分评价:

For reasons of convenience, I removed the copied typings from mqtt.js and added it as a dev-dependency while still bundling the browserified latest version of it. This means although you have the ability to use mqtt, mqtts, tcp, ssl, wx or wxs as the protocol in the client options, you can not, because this is a browser library where you can not connect with something other than websockets . You also can not use key, cert and ca for the same reasons.

现在如何向该库添加 tcp 连接?

正如您在问题中包含的文档部分中明确指出的那样。当 运行 在 Web 浏览器中时,您可以 通过 WebSockets 使用 MQTT。

这是因为网络浏览器沙箱只允许 HTTP 或 WebSocket 连接,而不是本机 TCP 连接