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