WXdraw.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. //画布
  2. var canvas;
  3. var context;
  4. //蒙版
  5. var canvas_bak = document.getElementById("box");;
  6. var context_bak;
  7. var canvasWidth = 720;
  8. var canvasHeight = 1280;
  9. var canvasTop;
  10. var canvasLeft;
  11. var winHeight = window.screen.height - window.innerHeight
  12. var vowidth = window.screen.width
  13. var topwinHeightDraw = window.screen.height - window.innerHeight + 30; //计算title top 头部
  14. var numse = window.screen.height //-winHeight
  15. //计算title top 头部
  16. if (numse <= 70) {
  17. var voheight = window.screen.height - winHeight - 34 - 20
  18. } else {
  19. console.log("numse>>>", numse)
  20. var voheight = window.screen.height - topwinHeightDraw - 20
  21. }
  22. //console.log("画笔大小>>>",window.innerHeight)
  23. //画笔大小
  24. var size = 1;
  25. var color = '#000000';
  26. var resolving
  27. //alert(winHeight)
  28. var url = window.location.href;
  29. url = url.split('/')
  30. var query = window.location.search.substring(1);
  31. // debugger
  32. // query = "clientType=3&username=WqXTc1593762177&userCardId=377"
  33. // debugger
  34. var vars = query.split("&");
  35. var data = {}
  36. var clientType = vars.find(e => {
  37. return e.startsWith('clientType')
  38. }) || ''
  39. var cardIp = vars.find(e => {
  40. return e.startsWith('cardIp')
  41. }) || ''
  42. var port = vars.find(e => {
  43. return e.startsWith('port')
  44. }) || ''
  45. var sn = vars.find(e => {
  46. return e.startsWith('sn')
  47. }) || ''
  48. var username = vars.find(e => {
  49. return e.startsWith('username')
  50. }) || ''
  51. var userCardId = vars.find(e => {
  52. return e.startsWith('userCardId')
  53. }) || ''
  54. var ip = vars.find(e => {
  55. return e.startsWith('ip')
  56. }) || ''
  57. var data = {}
  58. data.clientType = clientType.substring(11, clientType.length)
  59. data.cardIp = cardIp.substring(7, cardIp.length)
  60. data.port = port.substring(5, port.length)
  61. data.sn = sn.substring(3, sn.length)
  62. data.username = username.substring(9, username.length)
  63. data.userCardId = userCardId.substring(11, userCardId.length)
  64. data.ip = ip.substring(3, ip.length)
  65. // var urlss=url[2]
  66. // urlss = "14.215.128.96"
  67. urlss = '192.168.31.20'
  68. // urlss = 'test.androidscloud.com'
  69. // debugger
  70. var cUrl = ''
  71. cUrl = "ws://192.168.11.66:9101";
  72. // if (data.clientType == 3) {
  73. // cUrl = "wss://" + urlss + "/authControlWebSocket?" + "clientType=" + data.clientType + "&username=" + data.username +
  74. // "&userCardId=" + data.userCardId
  75. // } else if (data.clientType == 2) {
  76. // // cUrl = "wss://" + urlss + "/shareWebSocket?" + "clientType=" + data.clientType + "&username=" + data.username +
  77. // // "&userCardId=" + data.userCardId + "&ip=" + data.ip
  78. // cUrl = "wss://test.androidscloud.com/videoWebSocket?clientType=1&cardIp=14.215.128.96&port=2005&sn=RK3930C2301900005";
  79. // } else {
  80. // cUrl = "wss://" + urlss + "/controlWebSocket?" + "clientType=" + data.clientType + "&cardIp=" + data.cardIp + "&port=" +
  81. // data.port + "&sn=" + data.sn
  82. // }
  83. console.log(cUrl, 'curl')
  84. // var cUrl = Number(data.clientType) === 3? "ws://"+urlss+"/authControlWebSocket?"+"clientType="+data.clientType+"&username="+data.username+"&userCardId="+data.userCardId : "ws://"+urlss+"/controlWebSocket?"+"clientType="+data.clientType+"&cardIp="+data.cardIp+"&port="+data.port+"&sn="+data.sn
  85. var wsss = new WebSocket(cUrl);
  86. console.log('wsssss==============', wsss)
  87. wsss.binaryType = 'arraybuffer';
  88. ////
  89. // wsss = new WebSocket(
  90. // "ws://14.215.128.96/authControlWebSocket?clientType=3&username=WqXTc1593762177&userCardId=377");
  91. wsss.onopen = function() {
  92. console.log("onopen==============");
  93. var pings = {
  94. "event": "getScreenStatus"
  95. }
  96. wsss.send(JSON.stringify(pings));
  97. var bitRate = {
  98. "data": {
  99. "bitRate": 2243000
  100. },
  101. "event": "bitRate"
  102. }
  103. wsss.send(JSON.stringify(bitRate));
  104. };
  105. wsss.onmessage = function(event) {
  106. console.log("onMessage==============", event);
  107. var resets = JSON.parse(event.data)
  108. var resets = event.data;
  109. resets.errorMsg && alert(resets.errorMsg)
  110. resolving = resets.data.orientation
  111. if (resolving == 1) {} else {}
  112. console.log('>>>resolvingresolvingresolving', resolving)
  113. };
  114. wsss.onclose = function(event) {
  115. console.log("onclose==============");
  116. };
  117. wsss.onerror = function(event) {
  118. console.log("onerror==============");
  119. };
  120. $('#box').on("click", function() {
  121. draw_graph('pencil', this)
  122. })
  123. //剪切板
  124. $(".upload").on("click", function() {
  125. let texts = $(this).attr("data-text")
  126. if (texts == "uploads") {
  127. $(".mainbox").css({
  128. "display": "block"
  129. })
  130. $(".sbox").css({
  131. "display": "none"
  132. })
  133. } else if (texts == "Signout") {
  134. // alert()
  135. }
  136. })
  137. //home 控制home
  138. $(".botmat1img").on("click", function() {
  139. let codes = $(this).attr("data-text")
  140. console.log(codes)
  141. if (codes == "home") {
  142. var bitRate = {
  143. "data": {
  144. "keyCode": "3"
  145. },
  146. "event": "keyCode"
  147. }
  148. wsss.send(JSON.stringify(bitRate));
  149. } else if (codes == "return") {
  150. var bitRate = {
  151. "data": {
  152. "keyCode": "4"
  153. },
  154. "event": "keyCode"
  155. }
  156. wsss.send(JSON.stringify(bitRate));
  157. } else if (codes == "gengduo") {
  158. var bitRate = {
  159. "data": {
  160. "keyCode": "187"
  161. },
  162. "event": "keyCode"
  163. }
  164. wsss.send(JSON.stringify(bitRate));
  165. }
  166. })
  167. //高清控制
  168. $(".PictureQuality").on("click", function() {
  169. $(this).addClass("avit").siblings().removeClass('avit')
  170. let id = $(this).attr("data-id")
  171. var bitRate = {
  172. "data": {
  173. "bitRate": id
  174. },
  175. "event": "bitRate"
  176. }
  177. wsss.send(JSON.stringify(bitRate));
  178. console.log(id)
  179. })
  180. //画图形
  181. var draw_graph = function(graphType, obj) {
  182. console.log('111》》》', graphType)
  183. //把蒙版放于画板上面
  184. //$("#canvas_bak").css("z-index",1);
  185. $("#container").css("z-index", 30);
  186. $("#dedit").css("z-index", 20);
  187. //先画在蒙版上 再复制到画布上
  188. chooseImg(obj);
  189. var canDraw = false;
  190. var startX;
  191. var startY;
  192. //鼠标按下获取 开始xy开始画图
  193. var touchstart = function(e) {
  194. $('.control-right-img').attr({
  195. "data-id": "2"
  196. })
  197. $(".leftmains").css({
  198. "right": "-4rem"
  199. })
  200. // .toFixed(2)
  201. var touchfor = e.originalEvent.targetTouches; //for 的手指数组
  202. var touch = e.originalEvent.targetTouches[0];
  203. var thochlethng = e.originalEvent.targetTouches.length
  204. //是否横屏
  205. if (resolving == 0) {
  206. let ping
  207. for (let i = 0; i < touchfor.length; i++) {
  208. let cawidthXs = touchfor[i].pageY * (1280 / voheight)
  209. let caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  210. ping = {
  211. "data": {
  212. "action": 0,
  213. "count": touchfor.length,
  214. "pointerId": i,
  215. "x": cawidthXs.toFixed(2),
  216. "y": caheightYs.toFixed(2)
  217. },
  218. "event": "0"
  219. }
  220. }
  221. wsss.send(JSON.stringify(ping));
  222. console.log("鼠标按下>>>", ping)
  223. } else {
  224. let ping
  225. for (let i = 0; i < touchfor.length; i++) {
  226. let cawidthXs = touchfor[i].pageX * (720 / vowidth)
  227. let caheightYs = touchfor[i].pageY * (1280 / voheight)
  228. ping = {
  229. "data": {
  230. "action": 0,
  231. "count": touchfor.length,
  232. "pointerId": i,
  233. "x": cawidthXs.toFixed(2),
  234. "y": caheightYs.toFixed(2)
  235. },
  236. "event": "0"
  237. }
  238. }
  239. wsss.send(JSON.stringify(ping));
  240. console.log("鼠标按下>>>", ping)
  241. }
  242. canDraw = true;
  243. };
  244. //鼠标离开 把蒙版canvas的图片生成到canvas中
  245. var touchend = function(e) {
  246. var touchfor = e.originalEvent.changedTouches; //for 的手指数组
  247. var touch = e.originalEvent.changedTouches[0];
  248. var thochlethng = e.originalEvent.changedTouches.length
  249. // alert(thochlethng)
  250. //是否横屏 morePortionUp
  251. if (resolving == 0) {
  252. let ping
  253. for (let i = 0; i < touchfor.length; i++) {
  254. let cawidthXs = touchfor[i].pageY * (1280 / voheight)
  255. let caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  256. ping = {
  257. "data": {
  258. "action": 1,
  259. "count": touchfor.length,
  260. "pointerId": i,
  261. "x": cawidthXs.toFixed(2),
  262. "y": caheightYs.toFixed(2)
  263. },
  264. "event": "1"
  265. }
  266. }
  267. wsss.send(JSON.stringify(ping));
  268. } else {
  269. let ping
  270. for (let i = 0; i < touchfor.length; i++) {
  271. let cawidthXs = touchfor[i].pageX * (720 / vowidth)
  272. let caheightYs = touchfor[i].pageY * (1280 / voheight)
  273. ping = {
  274. "data": {
  275. "action": 1,
  276. "count": touchfor.length,
  277. "pointerId": i,
  278. "x": cawidthXs.toFixed(2),
  279. "y": caheightYs.toFixed(2)
  280. },
  281. "event": "1"
  282. }
  283. }
  284. wsss.send(JSON.stringify(ping));
  285. }
  286. canDraw = false;
  287. };
  288. //清空层 云手机超出屏幕的开关
  289. var clearContext = function(type) {
  290. canDraw = false;
  291. }
  292. // 鼠标移动
  293. var touchmove = function(e) {
  294. e = e || window.event;
  295. var touchfor = e.originalEvent.targetTouches; //for 的手指数组
  296. var touch = e.originalEvent.targetTouches[0];
  297. var thochlethng = e.originalEvent.targetTouches.length
  298. let ping
  299. //是否横屏 morePortionMove
  300. if (resolving == 0) {
  301. let obj = []
  302. for (let i = 0; i < touchfor.length; i++) {
  303. let cawidthXs = touchfor[i].pageY * (1280 / voheight)
  304. let caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  305. ping = {
  306. "data": {
  307. "action": 2,
  308. "count": touchfor.length,
  309. "pointerId": i,
  310. "x": cawidthXs.toFixed(2),
  311. "y": caheightYs.toFixed(2)
  312. },
  313. "event": "2"
  314. }
  315. }
  316. wsss.send(JSON.stringify(ping));
  317. } else {
  318. let ping
  319. for (let i = 0; i < touchfor.length; i++) {
  320. let cawidthXs = touchfor[i].pageX * (720 / vowidth)
  321. let caheightYs = touchfor[i].pageY * (1280 / voheight)
  322. ping = {
  323. "data": {
  324. "action": 2,
  325. "count": touchfor.length,
  326. "pointerId": i,
  327. "x": cawidthXs.toFixed(2),
  328. "y": caheightYs.toFixed(2)
  329. },
  330. "event": "2"
  331. }
  332. }
  333. wsss.send(JSON.stringify(ping));
  334. }
  335. // var ping = {"data":{"action":2,"count":1,"pointerId":0,"x":cawidthX.toFixed(2),"y":caheightY.toFixed(2)},"event":"2"}
  336. };
  337. //鼠标离开区域以外 除了涂鸦 都清空
  338. var mouseout = function() {
  339. if (graphType != 'handwriting') {
  340. clearContext();
  341. }
  342. }
  343. $(canvas_bak).unbind();
  344. $(canvas_bak).bind('touchstart', touchstart);
  345. $(canvas_bak).bind('touchmove', touchmove);
  346. $(canvas_bak).bind('touchend', touchend);
  347. $(canvas_bak).bind('mouseout', mouseout);
  348. }
  349. //选择功能按钮 修改样式
  350. function chooseImg(obj) {
  351. }