wangkang3 4 anni fa
parent
commit
57e2b527f0

+ 2 - 15
ebc-middle-platform/src/stomp/ipu-stomp.js

@ -1,5 +1,6 @@
1 1
import {Stomp} from './stomp'
2 2
import SockJS from './sockjs-client'
3
import UUID from './uuid'
3 4
/*
4 5
   * 1.兼容SockJS和Stomp,支持ws、http、https多种url前缀
5 6
   * 2.装饰器模式持有Stomp客户端的引用
@ -29,20 +30,6 @@ function _connectWithSockJS(url) {
29 30
  return Stomp.over(socket)
30 31
}
31 32
32
function uuid() {
33
  var s = []
34
  var hexDigits = '0123456789abcdef'
35
  for (var i = 0; i < 36; i++) {
36
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
37
  }
38
  s[14] = '4' // bits 12-15 of the time_hi_and_version field to 0010
39
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) // bits 6-7 of the clock_seq_hi_and_reserved to 01
40
  s[8] = s[13] = s[18] = s[23] = '-'
41
42
  var uuid = s.join('')
43
  return uuid
44
}
45
46 33
/* 建立连接 */
47 34
StompClient.prototype.connect = function(account, passcode, onConnected, onFailure, host) { // host参数的使用方式
48 35
  // var onConnected, onFailure
@ -55,7 +42,7 @@ StompClient.prototype.connect = function(account, passcode, onConnected, onFailu
55 42
  //   onFailure = new Function()
56 43
  // }
57 44
  console.log('connecting')
58
  var headers = {'login': account, 'passcode': passcode, 'host': host, 'uuid': uuid()}
45
  var headers = {'login': account, 'passcode': passcode, 'host': host, 'uuid': UUID()}
59 46
  this.client.connect(headers, onConnected, onFailure)
60 47
}
61 48

+ 48 - 0
ebc-middle-platform/src/stomp/uuid.js

@ -0,0 +1,48 @@
1
var uniqueId
2
3
export default function getUUID() {
4
    	if (!uniqueId) {
5
    		uniqueId = cans()
6
    	}
7
    	return uniqueId
8
};
9
10
function cans() {
11
	    var canvas = document.createElement('canvas')
12
	    var ctx = canvas.getContext('2d')
13
	    var txt = 'http://security.tencent.com/'
14
	    ctx.textBaseline = 'top'
15
	    ctx.font = "14px 'Arial'"
16
	    ctx.textBaseline = 'tencent'
17
	    ctx.fillStyle = '#f60'
18
	    ctx.fillRect(125, 1, 62, 20)
19
	    ctx.fillStyle = '#069'
20
	    ctx.fillText(txt, 2, 15)
21
	    ctx.fillStyle = 'rgba(102, 204, 0, 0.7)'
22
	    ctx.fillText(txt, 4, 17)
23
24
	    var b64 = canvas.toDataURL().replace('data:image/png;base64,', '')
25
	    var bin = atob(b64)
26
	    var crc = bin2hex(bin.slice(-16, -12))
27
	    // var crc = bin.slice(-16,-12);
28
  return crc
29
}
30
31
function bin2hex(str) {
32
  var result = ''
33
  for (i = 0; i < str.length; i++) {
34
    result += int16_to_hex(str.charCodeAt(i))
35
  }
36
  return result
37
}
38
39
function int16_to_hex(i) {
40
  var result = i.toString(16)
41
  var j = 0
42
  while (j + result.length < 4) {
43
    result = '0' + result
44
    j++
45
  }
46
  return result
47
}
48