WebIM.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import websdk from "../newSDK/uni_sdk4.0.7";
  2. import config from "./WebIMConfig";
  3. console.group = console.group || {};
  4. console.groupEnd = console.groupEnd || {};
  5. var window = {};
  6. let WebIM = window.WebIM = uni.WebIM = websdk;
  7. window.WebIM.config = config; //var DOMParser = window.DOMParser = xmldom.DOMParser;
  8. //let document = window.document = new DOMParser().parseFromString("<?xml version='1.0'?>\n", "text/xml");
  9. WebIM.isDebug = function (option) {
  10. if (option) {
  11. WebIM.config.isDebug = option.isDebug;
  12. openDebug(WebIM.config.isDebug);
  13. }
  14. function openDebug(value) {
  15. function ts() {
  16. var d = new Date();
  17. var Hours = d.getHours(); // 获取当前小时数(0-23)
  18. var Minutes = d.getMinutes(); // 获取当前分钟数(0-59)
  19. var Seconds = d.getSeconds(); // 获取当前秒数(0-59)
  20. return (Hours < 10 ? "0" + Hours : Hours) + ":" + (Minutes < 10 ? "0" + Minutes : Minutes) + ":" + (Seconds < 10 ? "0" + Seconds : Seconds) + " ";
  21. }
  22. }
  23. };
  24. /**
  25. * Set autoSignIn as true (autoSignInName and autoSignInPwd are configured below),
  26. * You can auto signed in each time when you refresh the page in dev model.
  27. */
  28. WebIM.config.autoSignIn = false;
  29. if (WebIM.config.autoSignIn) {
  30. WebIM.config.autoSignInName = "lwz2";
  31. WebIM.config.autoSignInPwd = "1";
  32. } // var stropheConn = new window.Strophe.Connection("ws://im-api.easemob.com/ws/", {
  33. // inactivity: 30,
  34. // maxRetries: 5,
  35. // pollingTime: 4500
  36. // });
  37. //
  38. // stropheConn.connect(
  39. // '$t$' + 'YWMtmbQEBKKIEeaGmMtXyg5n1wAAAVlkQvGO2WOJGlMCEJKM4VV9GCMnb_XLCXU',
  40. // function() {
  41. // console.log(arguments, 'ggogogo');
  42. // }, stropheConn.wait, stropheConn.hold);
  43. WebIM.parseEmoji = function (msg) {
  44. if (typeof WebIM.Emoji === "undefined" || typeof WebIM.Emoji.map === "undefined") {
  45. return msg;
  46. }
  47. var emoji = WebIM.Emoji,
  48. reg = null;
  49. var msgList = [];
  50. var objList = [];
  51. for (var face in emoji.map) {
  52. if (emoji.map.hasOwnProperty(face)) {
  53. while (msg.indexOf(face) > -1) {
  54. msg = msg.replace(face, "^" + emoji.map[face] + "^");
  55. }
  56. }
  57. }
  58. var ary = msg.split("^");
  59. var reg = /^e.*g$/;
  60. for (var i = 0; i < ary.length; i++) {
  61. if (ary[i] != "") {
  62. msgList.push(ary[i]);
  63. }
  64. }
  65. for (var i = 0; i < msgList.length; i++) {
  66. if (reg.test(msgList[i])) {
  67. var obj = {};
  68. obj.data = msgList[i];
  69. obj.type = "emoji";
  70. objList.push(obj);
  71. } else {
  72. var obj = {};
  73. obj.data = msgList[i];
  74. obj.type = "txt";
  75. objList.push(obj);
  76. }
  77. }
  78. return objList;
  79. };
  80. WebIM.time = function () {
  81. var date = new Date();
  82. var Hours = date.getHours();
  83. var Minutes = date.getMinutes();
  84. var Seconds = date.getSeconds();
  85. var time = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + (Hours < 10 ? "0" + Hours : Hours) + ":" + (Minutes < 10 ? "0" + Minutes : Minutes) + ":" + (Seconds < 10 ? "0" + Seconds : Seconds);
  86. return time;
  87. };
  88. WebIM.Emoji = {
  89. path: "../static/images/faces/",
  90. map: {
  91. "[):]": "ee_1.png",
  92. "[:D]": "ee_2.png",
  93. "[;)]": "ee_3.png",
  94. "[:-o]": "ee_4.png",
  95. "[:p]": "ee_5.png",
  96. "[(H)]": "ee_6.png",
  97. "[:@]": "ee_7.png",
  98. "[:s]": "ee_8.png",
  99. "[:$]": "ee_9.png",
  100. "[:(]": "ee_10.png",
  101. "[:'(]": "ee_11.png",
  102. "[<o)]": "ee_12.png",
  103. "[(a)]": "ee_13.png",
  104. "[8o|]": "ee_14.png",
  105. "[8-|]": "ee_15.png",
  106. "[+o(]": "ee_16.png",
  107. "[|-)]": "ee_17.png",
  108. "[:|]": "ee_18.png",
  109. "[*-)]": "ee_19.png",
  110. "[:-#]": "ee_20.png",
  111. "[^o)]": "ee_21.png",
  112. "[:-*]": "ee_22.png",
  113. "[8-)]": "ee_23.png",
  114. "[del]": "btn_del.png",
  115. "[(|)]": "ee_24.png",
  116. "[(u)]": "ee_25.png",
  117. "[(S)]": "ee_26.png",
  118. "[(*)]": "ee_27.png",
  119. "[(#)]": "ee_28.png",
  120. "[(R)]": "ee_29.png",
  121. "[({)]": "ee_30.png",
  122. "[(})]": "ee_31.png",
  123. "[(k)]": "ee_32.png",
  124. "[(F)]": "ee_33.png",
  125. "[(W)]": "ee_34.png",
  126. "[(D)]": "ee_35.png"
  127. }
  128. };
  129. WebIM.EmojiObj = {
  130. // 相对 emoji.js 路径
  131. path: "../static/images/faces/",
  132. map1: {
  133. "[):]": "ee_1.png",
  134. "[:D]": "ee_2.png",
  135. "[;)]": "ee_3.png",
  136. "[:-o]": "ee_4.png",
  137. "[:p]": "ee_5.png",
  138. "[(H)]": "ee_6.png",
  139. "[:@]": "ee_7.png"
  140. },
  141. map2: {
  142. "[:s]": "ee_8.png",
  143. "[:$]": "ee_9.png",
  144. "[:(]": "ee_10.png",
  145. "[:'(]": "ee_11.png",
  146. "[<o)]": "ee_12.png",
  147. "[(a)]": "ee_13.png",
  148. "[8o|]": "ee_14.png"
  149. },
  150. map3: {
  151. "[8-|]": "ee_15.png",
  152. "[+o(]": "ee_16.png",
  153. "[|-)]": "ee_17.png",
  154. "[:|]": "ee_18.png",
  155. "[*-)]": "ee_19.png",
  156. "[:-#]": "ee_20.png",
  157. "[del]": "del.png"
  158. },
  159. map4: {
  160. "[^o)]": "ee_21.png",
  161. "[:-*]": "ee_22.png",
  162. "[8-)]": "ee_23.png",
  163. "[(|)]": "ee_24.png",
  164. "[(u)]": "ee_25.png",
  165. "[(S)]": "ee_26.png",
  166. "[(*)]": "ee_27.png"
  167. },
  168. map5: {
  169. "[(#)]": "ee_28.png",
  170. "[(R)]": "ee_29.png",
  171. "[({)]": "ee_30.png",
  172. "[(})]": "ee_31.png",
  173. "[(k)]": "ee_32.png",
  174. "[(F)]": "ee_33.png",
  175. "[(W)]": "ee_34.png",
  176. "[(D)]": "ee_35.png"
  177. },
  178. map6: {
  179. "[del]": "del.png"
  180. }
  181. };
  182. // uni.connectSocket({url: WebIM.config.xmppURL, method: "GET"})
  183. WebIM.conn = new WebIM.connection({
  184. appKey: WebIM.config.appkey,
  185. isMultiLoginSessions: WebIM.config.isMultiLoginSessions,
  186. https: typeof WebIM.config.https === "boolean" ? WebIM.config.https : location.protocol === "https:",
  187. url: WebIM.config.xmppURL,
  188. apiUrl: WebIM.config.apiURL,
  189. isAutoLogin: true,
  190. heartBeatWait: WebIM.config.heartBeatWait,
  191. autoReconnectNumMax: WebIM.config.autoReconnectNumMax,
  192. autoReconnectInterval: WebIM.config.autoReconnectInterval,
  193. isDebug: false,
  194. isHttpDNS:false
  195. });
  196. module.exports = {
  197. "default": WebIM
  198. };