1
0
forked from dyf/APP

增加晶全app静态页面

This commit is contained in:
微微一笑
2025-07-05 14:49:26 +08:00
parent 194035cf79
commit aede64dacd
2323 changed files with 524101 additions and 0 deletions

130
node_modules/mqtt/lib/connect/ali.js generated vendored Normal file
View File

@ -0,0 +1,130 @@
'use strict'
var Transform = require('readable-stream').Transform
var duplexify = require('duplexify')
var base64 = require('base64-js')
/* global FileReader */
var my
var proxy
var stream
var isInitialized = false
function buildProxy () {
var proxy = new Transform()
proxy._write = function (chunk, encoding, next) {
my.sendSocketMessage({
data: chunk.buffer,
success: function () {
next()
},
fail: function () {
next(new Error())
}
})
}
proxy._flush = function socketEnd (done) {
my.closeSocket({
success: function () {
done()
}
})
}
return proxy
}
function setDefaultOpts (opts) {
if (!opts.hostname) {
opts.hostname = 'localhost'
}
if (!opts.path) {
opts.path = '/'
}
if (!opts.wsOptions) {
opts.wsOptions = {}
}
}
function buildUrl (opts, client) {
var protocol = opts.protocol === 'alis' ? 'wss' : 'ws'
var url = protocol + '://' + opts.hostname + opts.path
if (opts.port && opts.port !== 80 && opts.port !== 443) {
url = protocol + '://' + opts.hostname + ':' + opts.port + opts.path
}
if (typeof (opts.transformWsUrl) === 'function') {
url = opts.transformWsUrl(url, opts, client)
}
return url
}
function bindEventHandler () {
if (isInitialized) return
isInitialized = true
my.onSocketOpen(function () {
stream.setReadable(proxy)
stream.setWritable(proxy)
stream.emit('connect')
})
my.onSocketMessage(function (res) {
if (typeof res.data === 'string') {
var array = base64.toByteArray(res.data)
var buffer = Buffer.from(array)
proxy.push(buffer)
} else {
var reader = new FileReader()
reader.addEventListener('load', function () {
var data = reader.result
if (data instanceof ArrayBuffer) data = Buffer.from(data)
else data = Buffer.from(data, 'utf8')
proxy.push(data)
})
reader.readAsArrayBuffer(res.data)
}
})
my.onSocketClose(function () {
stream.end()
stream.destroy()
})
my.onSocketError(function (res) {
stream.destroy(res)
})
}
function buildStream (client, opts) {
opts.hostname = opts.hostname || opts.host
if (!opts.hostname) {
throw new Error('Could not determine host. Specify host manually.')
}
var websocketSubProtocol =
(opts.protocolId === 'MQIsdp') && (opts.protocolVersion === 3)
? 'mqttv3.1'
: 'mqtt'
setDefaultOpts(opts)
var url = buildUrl(opts, client)
my = opts.my
my.connectSocket({
url: url,
protocols: websocketSubProtocol
})
proxy = buildProxy()
stream = duplexify.obj()
bindEventHandler()
return stream
}
module.exports = buildStream

157
node_modules/mqtt/lib/connect/index.js generated vendored Normal file
View File

@ -0,0 +1,157 @@
'use strict'
var MqttClient = require('../client')
var Store = require('../store')
var url = require('url')
var xtend = require('xtend')
var protocols = {}
if (process.title !== 'browser') {
protocols.mqtt = require('./tcp')
protocols.tcp = require('./tcp')
protocols.ssl = require('./tls')
protocols.tls = require('./tls')
protocols.mqtts = require('./tls')
} else {
protocols.wx = require('./wx')
protocols.wxs = require('./wx')
protocols.ali = require('./ali')
protocols.alis = require('./ali')
}
protocols.ws = require('./ws')
protocols.wss = require('./ws')
/**
* Parse the auth attribute and merge username and password in the options object.
*
* @param {Object} [opts] option object
*/
function parseAuthOptions (opts) {
var matches
if (opts.auth) {
matches = opts.auth.match(/^(.+):(.+)$/)
if (matches) {
opts.username = matches[1]
opts.password = matches[2]
} else {
opts.username = opts.auth
}
}
}
/**
* connect - connect to an MQTT broker.
*
* @param {String} [brokerUrl] - url of the broker, optional
* @param {Object} opts - see MqttClient#constructor
*/
function connect (brokerUrl, opts) {
if ((typeof brokerUrl === 'object') && !opts) {
opts = brokerUrl
brokerUrl = null
}
opts = opts || {}
if (brokerUrl) {
var parsed = url.parse(brokerUrl, true)
if (parsed.port != null) {
parsed.port = Number(parsed.port)
}
opts = xtend(parsed, opts)
if (opts.protocol === null) {
throw new Error('Missing protocol')
}
opts.protocol = opts.protocol.replace(/:$/, '')
}
// merge in the auth options if supplied
parseAuthOptions(opts)
// support clientId passed in the query string of the url
if (opts.query && typeof opts.query.clientId === 'string') {
opts.clientId = opts.query.clientId
}
if (opts.cert && opts.key) {
if (opts.protocol) {
if (['mqtts', 'wss', 'wxs', 'alis'].indexOf(opts.protocol) === -1) {
switch (opts.protocol) {
case 'mqtt':
opts.protocol = 'mqtts'
break
case 'ws':
opts.protocol = 'wss'
break
case 'wx':
opts.protocol = 'wxs'
break
case 'ali':
opts.protocol = 'alis'
break
default:
throw new Error('Unknown protocol for secure connection: "' + opts.protocol + '"!')
}
}
} else {
// don't know what protocol he want to use, mqtts or wss
throw new Error('Missing secure protocol key')
}
}
if (!protocols[opts.protocol]) {
var isSecure = ['mqtts', 'wss'].indexOf(opts.protocol) !== -1
opts.protocol = [
'mqtt',
'mqtts',
'ws',
'wss',
'wx',
'wxs',
'ali',
'alis'
].filter(function (key, index) {
if (isSecure && index % 2 === 0) {
// Skip insecure protocols when requesting a secure one.
return false
}
return (typeof protocols[key] === 'function')
})[0]
}
if (opts.clean === false && !opts.clientId) {
throw new Error('Missing clientId for unclean clients')
}
if (opts.protocol) {
opts.defaultProtocol = opts.protocol
}
function wrapper (client) {
if (opts.servers) {
if (!client._reconnectCount || client._reconnectCount === opts.servers.length) {
client._reconnectCount = 0
}
opts.host = opts.servers[client._reconnectCount].host
opts.port = opts.servers[client._reconnectCount].port
opts.protocol = (!opts.servers[client._reconnectCount].protocol ? opts.defaultProtocol : opts.servers[client._reconnectCount].protocol)
opts.hostname = opts.host
client._reconnectCount++
}
return protocols[opts.protocol](client, opts)
}
return new MqttClient(wrapper, opts)
}
module.exports = connect
module.exports.connect = connect
module.exports.MqttClient = MqttClient
module.exports.Store = Store

19
node_modules/mqtt/lib/connect/tcp.js generated vendored Normal file
View File

@ -0,0 +1,19 @@
'use strict'
var net = require('net')
/*
variables port and host can be removed since
you have all required information in opts object
*/
function buildBuilder (client, opts) {
var port, host
opts.port = opts.port || 1883
opts.hostname = opts.hostname || opts.host || 'localhost'
port = opts.port
host = opts.hostname
return net.createConnection(port, host)
}
module.exports = buildBuilder

41
node_modules/mqtt/lib/connect/tls.js generated vendored Normal file
View File

@ -0,0 +1,41 @@
'use strict'
var tls = require('tls')
function buildBuilder (mqttClient, opts) {
var connection
opts.port = opts.port || 8883
opts.host = opts.hostname || opts.host || 'localhost'
opts.rejectUnauthorized = opts.rejectUnauthorized !== false
delete opts.path
connection = tls.connect(opts)
/* eslint no-use-before-define: [2, "nofunc"] */
connection.on('secureConnect', function () {
if (opts.rejectUnauthorized && !connection.authorized) {
connection.emit('error', new Error('TLS not authorized'))
} else {
connection.removeListener('error', handleTLSerrors)
}
})
function handleTLSerrors (err) {
// How can I get verify this error is a tls error?
if (opts.rejectUnauthorized) {
mqttClient.emit('error', err)
}
// close this connection to match the behaviour of net
// otherwise all we get is an error from the connection
// and close event doesn't fire. This is a work around
// to enable the reconnect code to work the same as with
// net.createConnection
connection.end()
}
connection.on('error', handleTLSerrors)
return connection
}
module.exports = buildBuilder

92
node_modules/mqtt/lib/connect/ws.js generated vendored Normal file
View File

@ -0,0 +1,92 @@
'use strict'
var websocket = require('websocket-stream')
var urlModule = require('url')
var WSS_OPTIONS = [
'rejectUnauthorized',
'ca',
'cert',
'key',
'pfx',
'passphrase'
]
var IS_BROWSER = process.title === 'browser'
function buildUrl (opts, client) {
var url = opts.protocol + '://' + opts.hostname + ':' + opts.port + opts.path
if (typeof (opts.transformWsUrl) === 'function') {
url = opts.transformWsUrl(url, opts, client)
}
return url
}
function setDefaultOpts (opts) {
if (!opts.hostname) {
opts.hostname = 'localhost'
}
if (!opts.port) {
if (opts.protocol === 'wss') {
opts.port = 443
} else {
opts.port = 80
}
}
if (!opts.path) {
opts.path = '/'
}
if (!opts.wsOptions) {
opts.wsOptions = {}
}
if (!IS_BROWSER && opts.protocol === 'wss') {
// Add cert/key/ca etc options
WSS_OPTIONS.forEach(function (prop) {
if (opts.hasOwnProperty(prop) && !opts.wsOptions.hasOwnProperty(prop)) {
opts.wsOptions[prop] = opts[prop]
}
})
}
}
function createWebSocket (client, opts) {
var websocketSubProtocol =
(opts.protocolId === 'MQIsdp') && (opts.protocolVersion === 3)
? 'mqttv3.1'
: 'mqtt'
setDefaultOpts(opts)
var url = buildUrl(opts, client)
return websocket(url, [websocketSubProtocol], opts.wsOptions)
}
function buildBuilder (client, opts) {
return createWebSocket(client, opts)
}
function buildBuilderBrowser (client, opts) {
if (!opts.hostname) {
opts.hostname = opts.host
}
if (!opts.hostname) {
// Throwing an error in a Web Worker if no `hostname` is given, because we
// can not determine the `hostname` automatically. If connecting to
// localhost, please supply the `hostname` as an argument.
if (typeof (document) === 'undefined') {
throw new Error('Could not determine host. Specify host manually.')
}
var parsed = urlModule.parse(document.URL)
opts.hostname = parsed.hostname
if (!opts.port) {
opts.port = parsed.port
}
}
return createWebSocket(client, opts)
}
if (IS_BROWSER) {
module.exports = buildBuilderBrowser
} else {
module.exports = buildBuilder
}

134
node_modules/mqtt/lib/connect/wx.js generated vendored Normal file
View File

@ -0,0 +1,134 @@
'use strict'
var Transform = require('readable-stream').Transform
var duplexify = require('duplexify')
/* global wx */
var socketTask
var proxy
var stream
function buildProxy () {
var proxy = new Transform()
proxy._write = function (chunk, encoding, next) {
socketTask.send({
data: chunk.buffer,
success: function () {
next()
},
fail: function (errMsg) {
next(new Error(errMsg))
}
})
}
proxy._flush = function socketEnd (done) {
socketTask.close({
success: function () {
done()
}
})
}
return proxy
}
function setDefaultOpts (opts) {
if (!opts.hostname) {
opts.hostname = 'localhost'
}
if (!opts.path) {
opts.path = '/'
}
if (!opts.wsOptions) {
opts.wsOptions = {}
}
}
function buildUrl (opts, client) {
var protocol = opts.protocol === 'wxs' ? 'wss' : 'ws'
var url = protocol + '://' + opts.hostname + opts.path
if (opts.port && opts.port !== 80 && opts.port !== 443) {
url = protocol + '://' + opts.hostname + ':' + opts.port + opts.path
}
if (typeof (opts.transformWsUrl) === 'function') {
url = opts.transformWsUrl(url, opts, client)
}
return url
}
function bindEventHandler () {
socketTask.onOpen(function () {
stream.setReadable(proxy)
stream.setWritable(proxy)
stream.emit('connect')
})
socketTask.onMessage(function (res) {
var data = res.data
if (data instanceof ArrayBuffer) data = Buffer.from(data)
else data = Buffer.from(data, 'utf8')
proxy.push(data)
})
socketTask.onClose(function () {
stream.end()
stream.destroy()
})
socketTask.onError(function (res) {
stream.destroy(new Error(res.errMsg))
})
}
function buildStream (client, opts) {
opts.hostname = opts.hostname || opts.host
if (!opts.hostname) {
throw new Error('Could not determine host. Specify host manually.')
}
var websocketSubProtocol =
(opts.protocolId === 'MQIsdp') && (opts.protocolVersion === 3)
? 'mqttv3.1'
: 'mqtt'
setDefaultOpts(opts)
var url = buildUrl(opts, client)
socketTask = wx.connectSocket({
url: url,
protocols: websocketSubProtocol
})
proxy = buildProxy()
stream = duplexify.obj()
stream._destroy = function (err, cb) {
socketTask.close({
success: function () {
cb && cb(err)
}
})
}
var destroyRef = stream.destroy
stream.destroy = function () {
stream.destroy = destroyRef
var self = this
process.nextTick(function () {
socketTask.close({
fail: function () {
self._destroy(new Error())
}
})
})
}.bind(stream)
bindEventHandler()
return stream
}
module.exports = buildStream