WXdraw.js 6.5 KB

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