• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
May 03, 2023 May 03, 2023

Copy link to clipboard

Copied

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();
}

 

TOPICS
ActionScript , How to

Views

230

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 03, 2023 May 03, 2023

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines