|
@@ -56,26 +56,26 @@ export default function IMSDK() {
|
56
|
56
|
...paramsRef.current,
|
57
|
57
|
fail: (err) => reject(err),
|
58
|
58
|
}).then((task) => {
|
59
|
|
- console.log('[WS][connect]', task)
|
|
59
|
+ console.log(`[${now()}]`, '[WS] [connect]', task)
|
60
|
60
|
instanceRef.current = task
|
61
|
61
|
|
62
|
62
|
task.onOpen(function () {
|
63
|
|
- console.log('[WS][onOpen]', paramsRef.current)
|
|
63
|
+ console.log(`[${now()}]`, '[WS] [onOpen]', paramsRef.current)
|
64
|
64
|
resolve()
|
65
|
65
|
})
|
66
|
66
|
|
67
|
67
|
task.onMessage(function (msg) {
|
68
|
|
- console.info('[WS][onMessage]', msg)
|
|
68
|
+ console.info(`[${now()}]`, '[WS] [onMessage]', msg)
|
69
|
69
|
instanceRef.onMessage().forEach((f) => f(msg))
|
70
|
70
|
})
|
71
|
71
|
|
72
|
72
|
task.onError(function (error) {
|
73
|
|
- console.error('[WS][onError]', error)
|
|
73
|
+ console.error(`[${now()}]`, '[WS] [onError]', error)
|
74
|
74
|
instanceRef.onError().forEach((f) => f(error))
|
75
|
75
|
})
|
76
|
76
|
|
77
|
77
|
task.onClose(function (res) {
|
78
|
|
- console.warn('[WS][onClose]', res)
|
|
78
|
+ console.warn(`[${now()}]`, '[WS] [onClose]', res)
|
79
|
79
|
instanceRef.onClose().forEach((f) => f(res))
|
80
|
80
|
})
|
81
|
81
|
})
|
|
@@ -83,14 +83,14 @@ export default function IMSDK() {
|
83
|
83
|
}
|
84
|
84
|
|
85
|
85
|
function send(data) {
|
86
|
|
- console.log('[WS][SEND]', data)
|
|
86
|
+ console.log(`[${now()}]`, '[WS] [SEND]', data)
|
87
|
87
|
return new Promise((resovle, reject) => {
|
88
|
88
|
if (instanceRef.current) {
|
89
|
89
|
instanceRef.current.send({
|
90
|
90
|
data,
|
91
|
91
|
success: resovle,
|
92
|
92
|
fail: (err) => {
|
93
|
|
- console.error('[WS][SEND]', err)
|
|
93
|
+ console.error(`[${now()}]`, '[WS] [SEND]', err)
|
94
|
94
|
reject(err)
|
95
|
95
|
},
|
96
|
96
|
})
|
|
@@ -99,4 +99,18 @@ export default function IMSDK() {
|
99
|
99
|
}
|
100
|
100
|
})
|
101
|
101
|
}
|
|
102
|
+
|
|
103
|
+ function now() {
|
|
104
|
+ const dt = new Date()
|
|
105
|
+ const year = dt.getFullYear()
|
|
106
|
+ const month = dt.getMonth() + 1
|
|
107
|
+ const day = dt.getDate()
|
|
108
|
+ const hour = dt.getHours()
|
|
109
|
+ const minutes = dt.getMinutes()
|
|
110
|
+ const seconds = dt.getSeconds()
|
|
111
|
+
|
|
112
|
+ const formate = n => n >= 10 ? n : `0${n}`
|
|
113
|
+
|
|
114
|
+ return `${year}-${formate(month)}-${formate(day)} ${formate(hour)}:${formate(minutes)}:${formate(seconds)}`
|
|
115
|
+ }
|
102
|
116
|
}
|