message.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 pages = getCurrentPages();
  13. var channelData = pages[0].getChannelData();
  14. if (!strings.isEmpty(channelData)) {
  15. channelData.map((v, index) => {
  16. if (v.channelNum === other.channel) {
  17. actionIndex = index;
  18. }
  19. });
  20. }
  21. canllback(actionIndex);
  22. } catch (e) {}
  23. };
  24. // 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]}]}
  25. function getDeviceInfo(payloads) {
  26. var other = payloads.other;
  27. var SrcDeviceName = payloads.SrcDeviceName;
  28. ///连上就调用2次 payloads.SrcDeviceName:AIrSMArT_7cdfa1fcbb24
  29. const app = getApp();
  30. const strings = require('../strings');
  31. const lexin_util = require('../lexin/util');
  32. const lexin_devices = require('../lexin/devices');
  33. var pages = getCurrentPages();
  34. var deviceList = pages[0].getDeviceList();
  35. if (!strings.isEmpty(deviceList)) {
  36. var currentDeviceId = "";
  37. /// 获取需要连接的那个设备,获取设备名称
  38. for (var i = 0; i < deviceList.length; i++) {
  39. if (SrcDeviceName) {
  40. var device = deviceList[i];
  41. var deviceId = device.deviceId;
  42. if (device.connectType != 3) {
  43. continue;
  44. }
  45. var mac = lexin_util.getMacByDeviceId(deviceId);
  46. var index = SrcDeviceName.indexOf(mac);
  47. console.log("index:", index, mac, deviceId);
  48. ///彻底连接成功
  49. if (index !== -1) {
  50. currentDeviceId = deviceId;
  51. var devName = other.devName;
  52. var ProdModel = other.ProdModel;
  53. if (device.ProdModel != ProdModel) {
  54. device.ProdModel = ProdModel;
  55. }
  56. if (device.devName != devName) {
  57. device.devName = devName;
  58. }
  59. ///猫王妙播音响·X4 (BZK)
  60. ///设置图片
  61. var classifyProducts = app.globalData.classifyProducts;
  62. if (!strings.isEmpty(classifyProducts)) {
  63. for (var i = 0; i < classifyProducts.length; i++) {
  64. var productItem = classifyProducts[i];
  65. if (productItem.clientType == ProdModel) {
  66. device.devName = productItem.name;
  67. device.imageUrl = productItem.img;
  68. device.offlineImg = productItem.offlineImg;
  69. break;
  70. }
  71. }
  72. }
  73. break;
  74. }
  75. }
  76. }
  77. console.log("index2:", device);
  78. /// 去更新选中目标
  79. if (!strings.isEmpty(currentDeviceId)) {
  80. var targetDevice = null;
  81. for (var i = 0; i < deviceList.length; i++) {
  82. var device = deviceList[i];
  83. var deviceId = device.deviceId;
  84. if (deviceId == currentDeviceId) {
  85. targetDevice = device;
  86. break;
  87. }
  88. }
  89. console.log("index3:", device);
  90. ///处理目标设备
  91. if (targetDevice != null) {
  92. var clientTypes = lexin_devices.clientTypes;
  93. for (var i = 0; i < clientTypes.length; i++) {
  94. if (clientTypes[i] == targetDevice.ProdModel) {
  95. var deviceListSelect = pages[0].getDeviceListSelect();
  96. if (deviceListSelect == null) {
  97. pages[0].refreshCurrentDevice(device);
  98. }
  99. break;
  100. }
  101. }
  102. }
  103. }
  104. }
  105. };
  106. ///获取电量
  107. function getBattery(battery) {
  108. var b = 0;
  109. ///0格 10
  110. if (battery < 20) {
  111. b = 0;
  112. }
  113. ///1格 20、30
  114. else if (20 <= battery && battery < 40) {
  115. b = 1;
  116. }
  117. ///2格 40、50
  118. else if (40 <= battery && battery < 60) {
  119. b = 2;
  120. }
  121. ///3格 60、70
  122. else if (60 <= battery && battery < 80) {
  123. b = 3;
  124. }
  125. ///满格 4格 80、90
  126. else if (80 <= battery && battery <= 100) {
  127. b = 4;
  128. }
  129. /// 充电中
  130. else if (battery > 100) {
  131. b = 5
  132. };
  133. return b;
  134. };
  135. ///播放和播放状态 PlayState: ///播放状态:0默认状态,1播放状态,2暂停状态, 3停止状态,4缓冲状态。
  136. function getPlay() {
  137. var pages = getCurrentPages();
  138. var deviceList = pages[0].getDeviceList();
  139. var deviceListSelect = pages[0].getDeviceListSelect();
  140. if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
  141. return;
  142. };
  143. const app = getApp();
  144. const lexin_util = require('../lexin/util');
  145. var deviceId = deviceList[deviceListSelect].deviceId;
  146. // 接收设备当前播放状态
  147. var deviceMacId = lexin_util.getDeviceMacId(deviceId);
  148. const obj = {
  149. DstDeviceName: deviceMacId
  150. }
  151. app.PubMsg({
  152. type: "get_position",
  153. ...obj
  154. });
  155. };