WXdraw.js 7.3 KB

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