Skip to main content
Participant
May 3, 2023
Question

How to integrate the mqtt function into the air desktop program of animate?

  • May 3, 2023
  • 1 reply
  • 290 views

There is no supported library, I try to load paho-mqtt.js(Release Eclipse Photon v1.1.0 · eclipse/paho.mqtt.javascript · GitHub), but there are many errors:

 

import flash.filesystem.File;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.system.Security;
import flash.system.SecurityDomain;

// Load Paho MQTT library file
var mqttLoader: URLLoader = new URLLoader();
mqttLoader.addEventListener(Event.COMPLETE, onMqttLibLoaded);
mqttLoader.load(new URLRequest(File.applicationDirectory.resolvePath("libs/paho-mqtt-min.js").nativePath));

// Callback function when Paho MQTT library is loaded
function onMqttLibLoaded(event: Event): void {
	// Execute Paho MQTT library in a security sandbox
	Security.allowDomain("*");
	Security.allowInsecureDomain("*");
	var mqttScript: String = event.target.data;
	var mqttLoader: Loader = new Loader();
	mqttLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onMqttLibReady);
}

// Callback function when Paho MQTT library is ready
function onMqttLibReady(event: Event): void {
	// Use Paho MQTT library for MQTT communication
	var client: MQTTClient = new MQTTClient("127.0.0.1", 8883, "clientId");
	client.connect();
}

 

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
May 3, 2023

you're loading a javascript file with as3. that's going to be problematic.