UNPKG

miniapp-web-jsapi

Version:

JSAPI/View adapter for miniprogram running on the web

23 lines 915 B
export function getNetworkType(options) { var _options$success, _options$fail; var connection = navigator.connection; var type = connection === null || connection === void 0 ? void 0 : connection.effectiveType; if (type) { // slow-2g/2g/3g/4g if (type === 'slow-2g') { type = '2g'; } } else { // bluetooth/cellular/ethernet/none/wifi/wimax/other/unknown type = (connection === null || connection === void 0 ? void 0 : connection.type) || 'none'; // not support yet if (['wifi', 'none'].indexOf(type) === -1) { type = 'unknown'; } } type = type.toUpperCase(); (_options$success = options.success) === null || _options$success === void 0 ? void 0 : _options$success.call(options, { networkAvailable: navigator.onLine, networkType: type }); (_options$fail = options.fail) === null || _options$fail === void 0 ? void 0 : _options$fail.call(options); }