WXdraw.js 9.9 KB

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