WXdraw.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. //蒙版
  2. var canvas_bak = document.getElementById("box");
  3. var winHeight = window.screen.height - window.innerHeight;
  4. var vowidth = window.screen.width;
  5. var topwinHeightDraw = window.screen.height - window.innerHeight + 30; // 计算title top 头部
  6. var numse = window.screen.height;
  7. // 计算title top 头部
  8. if (numse <= 70) {
  9. var voheight = window.screen.height - winHeight - 34 - 20
  10. } else {
  11. var voheight = window.screen.height - topwinHeightDraw - 20
  12. }
  13. // 画笔大小
  14. var resolving;
  15. var url = window.location.href;
  16. url = url.split('/');
  17. var parameters = GetRequest();
  18. var form = {};
  19. var roomList = ['test.androidscloud.com', 'vclusters.imwork.net:2221'];
  20. form.clientType = parameters["clientType"];
  21. form.cardIp = parameters["cardIp"];
  22. form.port = parameters["port"];
  23. form.sn = parameters["sn"];
  24. form.username = parameters["username"];
  25. form.userCardId = parameters["userCardId"];
  26. form.ip = parameters["ip"];
  27. var room = parameters["rm"];
  28. var isWSS = false;
  29. var wsUrl;
  30. if (room == "A1") {
  31. wsUrl = roomList[0];
  32. } else {
  33. wsUrl = roomList[1];
  34. }
  35. var cUrl = isWSS ? "wss" : "ws" + "://" + wsUrl + "/card?cardIp=" + form.ip;
  36. var wsss;
  37. doConnect();
  38. function doConnect() {
  39. wsss = new WebSocket(cUrl);
  40. wsss.binaryType = 'arraybuffer';
  41. wsss.onopen = function () {
  42. var pings = {
  43. "event": "getScreenStatus"
  44. }
  45. wsss.send(JSON.stringify(pings));
  46. var bitRate = {
  47. "data": {
  48. "bitRate": 2243000
  49. },
  50. "event": "bitRate"
  51. }
  52. wsss.send(ExexuteMove(JSON.stringify(bitRate), form.sn))
  53. };
  54. wsss.onclose = function () {
  55. $.confirm({
  56. title: '提示',
  57. text: '连接断开,是否准备重连?',
  58. onOK: function () {
  59. doConnect();
  60. },
  61. onCancel: function () {
  62. wx.miniProgram.switchTab({
  63. url: '/pages/home/home'
  64. })
  65. }
  66. });
  67. };
  68. wsss.onerror = function () {
  69. $.confirm({
  70. title: '提示',
  71. text: '连接断开,是否准备重连?',
  72. onOK: function () {
  73. doConnect();
  74. },
  75. onCancel: function () {
  76. wx.miniProgram.switchTab({
  77. url: '/pages/home/home'
  78. })
  79. }
  80. });
  81. };
  82. }
  83. $('#box').on("click", function () {
  84. draw_graph('pencil', this)
  85. })
  86. //剪切板
  87. $(".upload").on("click", function () {
  88. var texts = $(this).attr("data-text")
  89. if (texts == "uploads") {
  90. $(".mainbox").css({
  91. "display": "block"
  92. })
  93. $(".sbox").css({
  94. "display": "none"
  95. })
  96. }
  97. })
  98. //home 控制home
  99. $(".botmat1img").on("click", function () {
  100. var codes = $(this).attr("data-text")
  101. if (codes == "home") {
  102. wsss.send(ExexuteKeyBoard(3), form.sn);
  103. } else if (codes == "return") {
  104. wsss.send(ExexuteKeyBoard(4), form.sn);
  105. } else if (codes == "gengduo") {
  106. wsss.send(ExexuteKeyBoard(187), form.sn);
  107. }
  108. })
  109. //高清控制
  110. $(".PictureQuality").on("click", function () {
  111. $(this).addClass("avit").siblings().removeClass('avit')
  112. var id = $(this).attr("data-id")
  113. var bitRate = {
  114. "data": {
  115. "bitRate": id
  116. },
  117. "event": "bitRate"
  118. }
  119. wsss.send(ExexuteMove(JSON.stringify(bitRate), form.sn))
  120. })
  121. //画图形
  122. var draw_graph = function (graphType, obj) {
  123. //把蒙版放于画板上面
  124. $("#container").css("z-index", 30);
  125. $("#dedit").css("z-index", 20);
  126. var canDraw = false;
  127. //鼠标按下获取 开始xy开始画图
  128. var touchstart = function (e) {
  129. $('.control-right-img').attr({
  130. "data-id": "2"
  131. })
  132. $(".leftmains").css({
  133. "right": "-4rem"
  134. })
  135. var touchfor = e.originalEvent.targetTouches; //for 的手指数组
  136. //是否横屏
  137. if (resolving == 0) {
  138. var ping;
  139. for (var i = 0; i < touchfor.length; i++) {
  140. var cawidthXs = touchfor[i].pageY * (1280 / voheight)
  141. var caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  142. ping = {
  143. "data": {
  144. "action": 0,
  145. "count": touchfor.length,
  146. "pointerId": i,
  147. "x": cawidthXs.toFixed(2),
  148. "y": caheightYs.toFixed(2)
  149. },
  150. "event": "0"
  151. }
  152. }
  153. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  154. } else {
  155. var ping;
  156. for (var i = 0; i < touchfor.length; i++) {
  157. var cawidthXs = touchfor[i].pageX * (720 / vowidth)
  158. var caheightYs = touchfor[i].pageY * (1280 / voheight)
  159. ping = {
  160. "data": {
  161. "action": 0,
  162. "count": touchfor.length,
  163. "pointerId": i,
  164. "x": cawidthXs.toFixed(2),
  165. "y": caheightYs.toFixed(2)
  166. },
  167. "event": "0"
  168. }
  169. }
  170. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn));
  171. }
  172. canDraw = true;
  173. };
  174. //鼠标离开 把蒙版canvas的图片生成到canvas中
  175. var touchend = function (e) {
  176. var touchfor = e.originalEvent.changedTouches; //for 的手指数组
  177. //是否横屏 morePortionUp
  178. if (resolving == 0) {
  179. var ping;
  180. for (var i = 0; i < touchfor.length; i++) {
  181. var cawidthXs = touchfor[i].pageY * (1280 / voheight);
  182. var caheightYs = 720 - touchfor[i].pageX * (720 / vowidth);
  183. ping = {
  184. "data": {
  185. "action": 1,
  186. "count": touchfor.length,
  187. "pointerId": i,
  188. "x": cawidthXs.toFixed(2),
  189. "y": caheightYs.toFixed(2)
  190. },
  191. "event": "1"
  192. }
  193. }
  194. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn));
  195. } else {
  196. var ping;
  197. for (var i = 0; i < touchfor.length; i++) {
  198. var cawidthXs = touchfor[i].pageX * (720 / vowidth);
  199. var caheightYs = touchfor[i].pageY * (1280 / voheight);
  200. ping = {
  201. "data": {
  202. "action": 1,
  203. "count": touchfor.length,
  204. "pointerId": i,
  205. "x": cawidthXs.toFixed(2),
  206. "y": caheightYs.toFixed(2)
  207. },
  208. "event": "1"
  209. }
  210. }
  211. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  212. }
  213. canDraw = false;
  214. };
  215. //清空层 云手机超出屏幕的开关
  216. var clearContext = function () {
  217. canDraw = false;
  218. }
  219. // 鼠标移动
  220. var touchmove = function (e) {
  221. e = e || window.event;
  222. var touchfor = e.originalEvent.targetTouches; //for 的手指数组
  223. var ping;
  224. //是否横屏 morePortionMove
  225. if (resolving == 0) {
  226. for (var i = 0; i < touchfor.length; i++) {
  227. var cawidthXs = touchfor[i].pageY * (1280 / voheight)
  228. var caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  229. ping = {
  230. "data": {
  231. "action": 2,
  232. "count": touchfor.length,
  233. "pointerId": i,
  234. "x": cawidthXs.toFixed(2),
  235. "y": caheightYs.toFixed(2)
  236. },
  237. "event": "2"
  238. }
  239. }
  240. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn))
  241. } else {
  242. var ping;
  243. for (var i = 0; i < touchfor.length; i++) {
  244. var cawidthXs = touchfor[i].pageX * (720 / vowidth);
  245. var caheightYs = touchfor[i].pageY * (1280 / voheight);
  246. ping = {
  247. "data": {
  248. "action": 2,
  249. "count": touchfor.length,
  250. "pointerId": i,
  251. "x": cawidthXs.toFixed(2),
  252. "y": caheightYs.toFixed(2)
  253. },
  254. "event": "2"
  255. }
  256. }
  257. wsss.send(ExexuteMove(JSON.stringify(ping), form.sn));
  258. };
  259. };
  260. //鼠标离开区域以外 除了涂鸦 都清空
  261. var mouseout = function () {
  262. if (graphType != 'handwriting') {
  263. clearContext();
  264. }
  265. }
  266. $(canvas_bak).unbind();
  267. $(canvas_bak).bind('touchstart', touchstart);
  268. $(canvas_bak).bind('touchmove', touchmove);
  269. $(canvas_bak).bind('touchend', touchend);
  270. $(canvas_bak).bind('mouseout', mouseout);
  271. }
  272. // 获取url中"?"符后的字串
  273. function GetRequest() {
  274. var url = location.search;
  275. var obj = new Object();
  276. if (url.indexOf("?") != -1) {
  277. var str = url.substr(1);
  278. strs = str.split("&");
  279. for (var i = 0; i < strs.length; i++) {
  280. obj[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
  281. }
  282. }
  283. return obj;
  284. }