WXdraw.js 6.6 KB

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