WXdraw.js 9.7 KB

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