WXdraw.js 7.1 KB

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