WXdraw.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. console.log("打印主页json", JSON.stringify(bitRate))
  151. wsss.send(JSON.stringify(bitRate));
  152. console.log("打印主页json", wsss)
  153. } else if (codes == "return") {
  154. var bitRate = {
  155. "data": {
  156. "keyCode": "4"
  157. },
  158. "event": "keyCode"
  159. }
  160. wsss.send(JSON.stringify(bitRate));
  161. } else if (codes == "gengduo") {
  162. var bitRate = {
  163. "data": {
  164. "keyCode": "187"
  165. },
  166. "event": "keyCode"
  167. }
  168. wsss.send(JSON.stringify(bitRate));
  169. }
  170. })
  171. //高清控制
  172. $(".PictureQuality").on("click", function() {
  173. $(this).addClass("avit").siblings().removeClass('avit')
  174. let id = $(this).attr("data-id")
  175. var bitRate = {
  176. "data": {
  177. "bitRate": id
  178. },
  179. "event": "bitRate"
  180. }
  181. wsss.send(JSON.stringify(bitRate));
  182. console.log(id)
  183. })
  184. //画图形
  185. var draw_graph = function(graphType, obj) {
  186. console.log('111》》》', graphType)
  187. //把蒙版放于画板上面
  188. //$("#canvas_bak").css("z-index",1);
  189. $("#container").css("z-index", 30);
  190. $("#dedit").css("z-index", 20);
  191. //先画在蒙版上 再复制到画布上
  192. chooseImg(obj);
  193. var canDraw = false;
  194. var startX;
  195. var startY;
  196. //鼠标按下获取 开始xy开始画图
  197. var touchstart = function(e) {
  198. $('.control-right-img').attr({
  199. "data-id": "2"
  200. })
  201. $(".leftmains").css({
  202. "right": "-4rem"
  203. })
  204. // .toFixed(2)
  205. var touchfor = e.originalEvent.targetTouches; //for 的手指数组
  206. var touch = e.originalEvent.targetTouches[0];
  207. var thochlethng = e.originalEvent.targetTouches.length
  208. //是否横屏
  209. if (resolving == 0) {
  210. let ping
  211. for (let i = 0; i < touchfor.length; i++) {
  212. let cawidthXs = touchfor[i].pageY * (1280 / voheight)
  213. let caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  214. ping = {
  215. "data": {
  216. "action": 0,
  217. "count": touchfor.length,
  218. "pointerId": i,
  219. "x": cawidthXs.toFixed(2),
  220. "y": caheightYs.toFixed(2)
  221. },
  222. "event": "0"
  223. }
  224. }
  225. wsss.send(JSON.stringify(ping));
  226. console.log("鼠标按下>>>", ping)
  227. } else {
  228. let ping
  229. for (let i = 0; i < touchfor.length; i++) {
  230. let cawidthXs = touchfor[i].pageX * (720 / vowidth)
  231. let caheightYs = touchfor[i].pageY * (1280 / voheight)
  232. ping = {
  233. "data": {
  234. "action": 0,
  235. "count": touchfor.length,
  236. "pointerId": i,
  237. "x": cawidthXs.toFixed(2),
  238. "y": caheightYs.toFixed(2)
  239. },
  240. "event": "0"
  241. }
  242. }
  243. wsss.send(JSON.stringify(ping));
  244. console.log("鼠标按下>>>", ping)
  245. }
  246. canDraw = true;
  247. };
  248. //鼠标离开 把蒙版canvas的图片生成到canvas中
  249. var touchend = function(e) {
  250. var touchfor = e.originalEvent.changedTouches; //for 的手指数组
  251. var touch = e.originalEvent.changedTouches[0];
  252. var thochlethng = e.originalEvent.changedTouches.length
  253. // alert(thochlethng)
  254. //是否横屏 morePortionUp
  255. if (resolving == 0) {
  256. let ping
  257. for (let i = 0; i < touchfor.length; i++) {
  258. let cawidthXs = touchfor[i].pageY * (1280 / voheight)
  259. let caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  260. ping = {
  261. "data": {
  262. "action": 1,
  263. "count": touchfor.length,
  264. "pointerId": i,
  265. "x": cawidthXs.toFixed(2),
  266. "y": caheightYs.toFixed(2)
  267. },
  268. "event": "1"
  269. }
  270. }
  271. wsss.send(JSON.stringify(ping));
  272. } else {
  273. let ping
  274. for (let i = 0; i < touchfor.length; i++) {
  275. let cawidthXs = touchfor[i].pageX * (720 / vowidth)
  276. let caheightYs = touchfor[i].pageY * (1280 / voheight)
  277. ping = {
  278. "data": {
  279. "action": 1,
  280. "count": touchfor.length,
  281. "pointerId": i,
  282. "x": cawidthXs.toFixed(2),
  283. "y": caheightYs.toFixed(2)
  284. },
  285. "event": "1"
  286. }
  287. }
  288. wsss.send(JSON.stringify(ping));
  289. }
  290. canDraw = false;
  291. };
  292. //清空层 云手机超出屏幕的开关
  293. var clearContext = function(type) {
  294. canDraw = false;
  295. }
  296. // 鼠标移动
  297. var touchmove = function(e) {
  298. e = e || window.event;
  299. var touchfor = e.originalEvent.targetTouches; //for 的手指数组
  300. var touch = e.originalEvent.targetTouches[0];
  301. var thochlethng = e.originalEvent.targetTouches.length
  302. let ping
  303. //是否横屏 morePortionMove
  304. if (resolving == 0) {
  305. let obj = []
  306. for (let i = 0; i < touchfor.length; i++) {
  307. let cawidthXs = touchfor[i].pageY * (1280 / voheight)
  308. let caheightYs = 720 - touchfor[i].pageX * (720 / vowidth)
  309. ping = {
  310. "data": {
  311. "action": 2,
  312. "count": touchfor.length,
  313. "pointerId": i,
  314. "x": cawidthXs.toFixed(2),
  315. "y": caheightYs.toFixed(2)
  316. },
  317. "event": "2"
  318. }
  319. }
  320. wsss.send(JSON.stringify(ping));
  321. } else {
  322. let ping
  323. for (let i = 0; i < touchfor.length; i++) {
  324. let cawidthXs = touchfor[i].pageX * (720 / vowidth)
  325. let caheightYs = touchfor[i].pageY * (1280 / voheight)
  326. ping = {
  327. "data": {
  328. "action": 2,
  329. "count": touchfor.length,
  330. "pointerId": i,
  331. "x": cawidthXs.toFixed(2),
  332. "y": caheightYs.toFixed(2)
  333. },
  334. "event": "2"
  335. }
  336. }
  337. wsss.send(JSON.stringify(ping));
  338. }
  339. // var ping = {"data":{"action":2,"count":1,"pointerId":0,"x":cawidthX.toFixed(2),"y":caheightY.toFixed(2)},"event":"2"}
  340. };
  341. //鼠标离开区域以外 除了涂鸦 都清空
  342. var mouseout = function() {
  343. if (graphType != 'handwriting') {
  344. clearContext();
  345. }
  346. }
  347. $(canvas_bak).unbind();
  348. $(canvas_bak).bind('touchstart', touchstart);
  349. $(canvas_bak).bind('touchmove', touchmove);
  350. $(canvas_bak).bind('touchend', touchend);
  351. $(canvas_bak).bind('mouseout', mouseout);
  352. }
  353. //选择功能按钮 修改样式
  354. function chooseImg(obj) {
  355. }