message.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. module.exports = {
  2. getPosition: getPosition,
  3. getDeviceInfo: getDeviceInfo,
  4. getBattery: getBattery,
  5. getPlay: getPlay,
  6. }
  7. // payloads.other: {"songInfoID":"843265795768623127","songFrom":"4","songAlbumID":"","artist":"巴洛克古典乐","title":"巴洛克古典乐","url":"http://speed.radio1964.cn/hls/1fmottosbaroquemusicradiozug.m3u8","albumURI":"http://airsmart-photo1.oss-cn-shanghai.aliyuncs.com/img/20211122/98101225b3cb4a0fb5728159ce4ca6d5.png","realUrl":"http://speed.radio1964.cn/hls/1fmottosbaroquemusicradiozug.m3u8","channel":5,"Duration":0,"RelTime":0,"PlayState":1,"PlayMode":0,"SongType":2,"userid":"1","channelType":1,"platformId":4,"platformName":"海外电台","isVip":0,"playable":1,"unplayableMsg":"","unplayableCode":0,"vipIconType":0,"vipIconTypeName":""}
  8. function getPosition(other, canllback) {
  9. try {
  10. var actionIndex = null;
  11. const strings = require('../strings');
  12. var channelData = getCurrentPages()[0].getChannelData();
  13. if (!strings.isEmpty(channelData)) {
  14. channelData.map((v, index) => {
  15. if (v.channelNum === other.channel) {
  16. actionIndex = index;
  17. }
  18. });
  19. }
  20. canllback(actionIndex);
  21. } catch (e) {}
  22. };
  23. // payloads.other: {"Guid":"AIrSMArT_7cdfa1fd3af0","ProdModel":"MW-2AX(WIFI)","sim_iccid":"","esim_iccid":"","SoftVer":"3.0.7","Firmware":"RTOS","Power":50,"lowBatteryNtf":0,"Volume":27,"Mute":0,"pauseShutdown":0,"PlayState":1,"PlayMode":0,"devName":"猫王小王子OTR-X","deviceId":"","deviceSecret":"","is_tts_enable":1,"SignalQuality":100,"CardIndex":0,"CardSum":0,"NetModel":2,"is_netmode_auto":2,"Imei":"","mid":"","deviceDSN":"1044250776739909632","userid":"1","user_id_white":"1039072","alarm":[{"alarm_id":"0","alarm_name":"open","current_timestamp":"2024-12-12 00:00:00","on_off_timestamp":"16:19:25","operation":"on","song_uri":"","weekly_repeat":"0","enable":"0","action":"update","week_actives":[0,0,0,0,0,0,0]},{"alarm_id":"1","alarm_name":"open","current_timestamp":"2024-12-11 20:00:48","on_off_timestamp":"07:00:00","operation":"on","song_uri":"","weekly_repeat":"0","enable":"1","action":"update","week_actives":[0,0,0,0,0,0,0]}]}
  24. function getDeviceInfo(payloads) {
  25. var other = payloads.other;
  26. var SrcDeviceName = payloads.SrcDeviceName;
  27. ///连上就调用2次 payloads.SrcDeviceName:AIrSMArT_7cdfa1fcbb24
  28. const strings = require('../strings');
  29. const lexin_util = require('../lexin/util');
  30. var deviceList = getCurrentPages()[0].getDeviceList();
  31. if (!strings.isEmpty(deviceList)) {
  32. var currentDeviceId = "";
  33. /// 获取需要连接的那个设备,获取设备名称
  34. for (var i = 0; i < deviceList.length; i++) {
  35. if (SrcDeviceName) {
  36. var device = deviceList[i];
  37. var deviceId = device.deviceId;
  38. var mac = lexin_util.getMacByDeviceId(deviceId);
  39. var index = SrcDeviceName.indexOf(mac);
  40. ///彻底连接成功
  41. if (index !== -1) {
  42. currentDeviceId = deviceId;
  43. var ProdModel = other.ProdModel;
  44. var devName = other.devName;
  45. if (device.ProdModel != ProdModel || device.devName != devName) {
  46. device.devName = devName;
  47. device.ProdModel = ProdModel;
  48. }
  49. break;
  50. }
  51. }
  52. }
  53. /// 去更新选中目标
  54. if (!strings.isEmpty(currentDeviceId)) {
  55. for (var i = 0; i < deviceList.length; i++) {
  56. var device = deviceList[i];
  57. var deviceId = device.deviceId;
  58. if (deviceId == currentDeviceId) {
  59. getCurrentPages()[0].refreshCurrentDevice(device);
  60. break;
  61. }
  62. }
  63. }
  64. }
  65. };
  66. ///获取电量
  67. function getBattery(battery) {
  68. var b = 0;
  69. if (battery < 20) {
  70. _babttery = 0
  71. } else if (20 <= battery && battery < 40) {
  72. b = 1
  73. } else if (40 <= battery && battery < 60) {
  74. b = 2
  75. } else if (60 <= battery && battery < 80) {
  76. b = 3
  77. } else if (80 <= battery && battery <= 100) {
  78. b = 4
  79. } else if (battery > 100) {
  80. b = 5
  81. };
  82. return b;
  83. };
  84. ///播放和播放状态
  85. function getPlay() {
  86. var deviceList = getCurrentPages()[0].getDeviceList();
  87. var deviceListSelect = getCurrentPages()[0].getDeviceListSelect();
  88. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  89. return;
  90. };
  91. const app = getApp();
  92. const lexin_util = require('../lexin/util');
  93. var deviceId = deviceList[deviceListSelect].deviceId;
  94. // 接收设备当前播放状态
  95. var deviceMacId = lexin_util.getDeviceMacId(deviceId);
  96. const obj = {
  97. DstDeviceName: deviceMacId
  98. }
  99. app.PubMsg({
  100. type: "get_position",
  101. ...obj
  102. });
  103. };