hh-doctor-sdk 0.5.6 → 0.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ const hostTypes = {
4
4
  order: 'order', // host order app
5
5
  family: 'family', // host family app
6
6
  dicom: 'dicom', // host dicom
7
- log: 'log'
7
+ log: 'log', // host log
8
8
  }
9
9
 
10
10
  const testHost = 'https://test.hh-medic.com/orderapp'
@@ -36,7 +36,33 @@ function sendLog(data) {
36
36
  return httpUtils.get(apiPaths.statLog, params, null)
37
37
  }
38
38
 
39
+ function pointLog(type, content, orderId) {
40
+ const isTest = cache.isTest()
41
+ let host = isTest ? 'https://test.hh-medic.com/point-log?' : "https://sec.hh-medic.com/point-log?"
42
+ const id = cache.getLogId() || 1
43
+ let url = `${host}sdkProductId=${appConfig.appID}`
44
+ + `&uuid=${cache.uuid()}`
45
+ + `&tid=${cache.doctorId()}`
46
+ + `&session=${cache.getSessionId()}`
47
+ + `&orderId=${orderId || ''}`
48
+ + `&type=${type || 0}`
49
+ + `&version=${appConfig.appVersion}`
50
+ + `&t=${new Date().getTime()}`
51
+ + `&id=${id}`
52
+ if ('object' == typeof content) {
53
+ for (const key in content) {
54
+ url += `&${key}=${encodeURIComponent(content[key])}`
55
+ }
56
+ } else {
57
+ url += `&content=${encodeURIComponent(content)}`
58
+ }
59
+ wx.downloadFile({
60
+ url: url,
61
+ })
62
+ }
63
+
39
64
  module.exports = {
40
65
  sendLog,
41
- logType
66
+ logType,
67
+ pointLog
42
68
  }
@@ -34,10 +34,32 @@ function setLoginCheck(judgeLogin, directLogin) {
34
34
  wx.loginConfig.directLogin = directLogin
35
35
  }
36
36
 
37
+ function enterForground() {
38
+ wx.statLog.sendStatLog('', '学术小程序进入前台')
39
+ wx.statLog.pointLog(0, {
40
+ ec: 'wmp_doctor_sdk',
41
+ ea: 'life_change',
42
+ el: 'forground',
43
+ ev: 1
44
+ }, null)
45
+ }
46
+
47
+ function enterBackground() {
48
+ wx.statLog.sendStatLog('', '学术小程序进入后台')
49
+ wx.statLog.pointLog(0, {
50
+ ec: 'wmp_doctor_sdk',
51
+ ea: 'life_change',
52
+ el: 'forground',
53
+ ev: 0
54
+ }, null)
55
+ }
56
+
37
57
  module.exports = {
38
58
  initSDK,
39
59
  initEventBus,
40
60
  initTim,
41
61
  initStatLog,
42
62
  setLoginCheck,
63
+ enterForground,
64
+ enterBackground
43
65
  }
@@ -8,6 +8,11 @@ function sendStatLog(orderId, content, type = statLogApi.logType.netLog) {
8
8
  })
9
9
  }
10
10
 
11
+ function pointLog(type, content, orderId) {
12
+ statLogApi.pointLog(type, content, orderId)
13
+ }
14
+
11
15
  module.exports = {
12
16
  sendStatLog,
17
+ pointLog
13
18
  }
@@ -43,18 +43,27 @@ Component({
43
43
  * 组件的初始数据
44
44
  */
45
45
  data: {
46
+ roomID: null,
47
+ token: null,
46
48
  pusher: null, // 主播视频
47
49
  mainRemotePlayer: null, // 主画面显示远端视频
48
50
  remotePlayerList: [], // 小画面远端视频
49
51
  muted: false,
50
52
  beauty: 0,
51
53
  exitRoom: false,
52
- remoteAudioStatus: {}
54
+ remoteAudioStatus: {},
55
+ reconnetCount: 0
53
56
  },
54
57
 
55
58
  lifetimes: {
56
59
  attached: function () {
57
60
 
61
+ },
62
+ detached: function() {
63
+ if (this.reconnectTimer) {
64
+ clearTimeout(this.reconnectTimer)
65
+ this.reconnectTimer = null
66
+ }
58
67
  },
59
68
  ready: function () {
60
69
  this.client = null
@@ -71,11 +80,12 @@ Component({
71
80
  if (orderId) {
72
81
  api.getAgoraToken(orderId).then((res) => {
73
82
  const token = res.data.token
74
- wx.statLog.sendStatLog(orderId, `获取声网token成功 -> ${token}`)
75
- this.joinChannel({
76
- roomID: roomID,
77
- token: token,
83
+ this.setData({
84
+ roomID: '' + roomID,
85
+ token: token
78
86
  })
87
+ wx.statLog.sendStatLog(orderId, `获取声网token成功 -> ${token}`)
88
+ this.joinChannel()
79
89
  }).catch((e) => {
80
90
  wx.statLog.sendStatLog(orderId, `获取声网token失败 -> ${JSON.stringify(e)}`)
81
91
  wx.showToast({
@@ -113,12 +123,13 @@ Component({
113
123
  }
114
124
  },
115
125
 
116
- async joinChannel(data) {
117
- const strRoomID = '' + data.roomID
126
+ async joinChannel() {
127
+ const strRoomID = this.data.roomID
128
+ const token = this.data.token
118
129
  const uuid = cache.uuid()
119
- wx.statLog.sendStatLog(this.properties.orderId, `声网开始进房 ${uuid} - ${strRoomID} - ${data.token}`)
130
+ wx.statLog.sendStatLog(this.properties.orderId, `声网开始进房 ${uuid} - ${strRoomID} - ${token}`)
120
131
  try {
121
- await this.client.join(data.token, strRoomID, uuid)
132
+ await this.client.join(token, strRoomID, uuid)
122
133
  const url = await this.client.publish()
123
134
  const ts = new Date().getTime()
124
135
  this.addMedia(0, uuid, url, {
@@ -133,6 +144,29 @@ Component({
133
144
  }
134
145
  },
135
146
 
147
+ async reJoinChannel() {
148
+ const strRoomID = this.data.roomID
149
+ const token = this.data.token
150
+ const uuid = cache.uuid()
151
+ let uids = this.data.remotePlayerList.map((user) => {
152
+ return user.uid
153
+ })
154
+ uids.splice(0, 0, uuid)
155
+ wx.statLog.sendStatLog(this.properties.orderId, `声网开始重新进房 ${uuid} - ${strRoomID} - ${token}`)
156
+ try {
157
+ await this.client.rejoin(token, strRoomID, uuid, uids)
158
+ const url = await this.client.publish()
159
+ const ts = new Date().getTime()
160
+ this.addMedia(0, uuid, url, {
161
+ key: ts
162
+ })
163
+ wx.statLog.sendStatLog(this.properties.orderId, '(声网)本人重新加入房间')
164
+ } catch (error) {
165
+ wx.statLog.sendStatLog(this.properties.orderId, `(声网)进房出错 ${JSON.stringify(error)}`)
166
+ this.reconnect()
167
+ }
168
+ },
169
+
136
170
  /**
137
171
  * 初始化SDK
138
172
  */
@@ -148,6 +182,38 @@ Component({
148
182
  }
149
183
  },
150
184
 
185
+ async reconnect() {
186
+ if (ths.data.reconnetCount >= 3) {
187
+ this.errorTipHangup('尝试回复连接失败,请稍后重试')
188
+ return
189
+ }
190
+ this.setData({
191
+ reconnetCount: this.data.reconnetCount + 1
192
+ })
193
+ wx.statLog.sendStatLog(this.properties.orderId, `(声网)开始重新连接`)
194
+ wx.showToast({
195
+ title: `尝试恢复连接...`,
196
+ icon: 'none',
197
+ duration: 5000
198
+ });
199
+ // always destroy client first
200
+ // *important* miniapp supports 5 websockets maximum at same time
201
+ // do remember to destroy old client first before creating new ones
202
+ await client.destroy();
203
+ client = null
204
+
205
+ this.reconnectTimer = setTimeout(async () => {
206
+ try {
207
+ await this.initChannel()
208
+ await this.reJoinChannel()
209
+ } catch (e) {
210
+ wx.statLog.sendStatLog(this.properties.orderId, `(声网)重新连接失败 ${JSON.stringify(e)}`)
211
+ // remember control max reconnect times
212
+ return this.reconnect();
213
+ }
214
+ }, 1 * 1000);
215
+ },
216
+
151
217
  errorTipHangup(tip) {
152
218
  wx.showToast({
153
219
  title: tip,
@@ -157,7 +157,7 @@ Component({
157
157
  const {
158
158
  player
159
159
  } = event.data
160
- wx.statLog.sendStatLog(this.properties.orderId, `${player.userID}远端用户开始推送视频`)
160
+ wx.statLog.sendStatLog(this.properties.orderId, `远端用户${player.userID}开始推送视频`)
161
161
  this.triggerEvent('updateUserAudioStatus', {
162
162
  userId: player.userID,
163
163
  audio: false
@@ -219,6 +219,17 @@ Component({
219
219
  pusher: pusher
220
220
  })
221
221
  })
222
+ this.TRTC.on(TRTC_EVENT.LOCAL_NET_STATE_UPDATE, (event) => {
223
+ const netStatus = event.data.pusher.netStatus
224
+ wx.statLog.sendStatLog(this.properties.orderId, `本地网络发生变化=> ${JSON.stringify(netStatus)}`)
225
+ })
226
+ this.TRTC.on(TRTC_EVENT.REMOTE_NET_STATE_UPDATE, (event) => {
227
+ wx.statLog.sendStatLog(this.properties.orderId, `用户网络发生变化=> ${JSON.stringify(event)}`)
228
+ })
229
+ this.TRTC.on(TRTC_EVENT.ERROR, (event) => {
230
+ const { code, message } = event.data
231
+ wx.statLog.sendStatLog(this.properties.orderId, `发生错误=> ${code} = ${message}`)
232
+ })
222
233
  },
223
234
  // 请保持跟 wxml 中绑定的事件名称一致
224
235
  _pusherStateChangeHandler(event) {
@@ -106,7 +106,7 @@ Page({
106
106
  }, 1000);
107
107
  return false
108
108
  }
109
- const info = wx.getSystemInfoSync()
109
+ const info = wx.getDeviceInfo()
110
110
  //mac windows 无需处理顶部间距
111
111
  const isPC = info.platform === 'mac' || info.platform === 'windows'
112
112
  const res = wx.getMenuButtonBoundingClientRect()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hh-doctor-sdk",
3
- "version": "0.5.6",
3
+ "version": "0.5.8",
4
4
  "description": "和缓名医小程序SDK",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"