WXdraw.js 6.8 KB

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