WXdraw.js 7.0 KB

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