Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38fb6ae
commit 4facb18
Showing
4 changed files
with
87 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
// test mqttjs in worker | ||
|
||
importScripts('/dist/mqtt.js'); | ||
|
||
/** @type { import('../../src').MqttClient }*/ | ||
const MQTT = mqtt; | ||
|
||
postMessage(typeof MQTT?.connect === 'function' ? 'worker ready' : 'worker error'); | ||
const client = MQTT.connect(`ws://localhost:4000`, { | ||
clientId: `testClient-worker_` + Math.random().toString(16).substr(2, 8), | ||
}); | ||
|
||
client.on('offline', () => { | ||
console.log('worker client offline'); | ||
}) | ||
|
||
client.on('reconnect', () => { | ||
console.log('worker client reconnect'); | ||
}) | ||
|
||
client.on('error', (err) => { | ||
console.log('worker client error', err); | ||
}) | ||
|
||
client.on('connect', () => { | ||
console.log('worker client connect'); | ||
client.end(() => { | ||
console.log('worker client end'); | ||
postMessage('worker ready'); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters