@aochuang/client-sdk 1.0.326 → 1.0.328

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aochuang/client-sdk",
3
- "version": "1.0.326",
3
+ "version": "1.0.328",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1,3 +1,5 @@
1
+ import Socket from '../../socket'
2
+
1
3
  export default class ClietChatSocket {
2
4
  get connectStatus () {
3
5
  return this.socket.connectStatus
@@ -33,21 +35,20 @@ export default class ClietChatSocket {
33
35
  // 执行消息前回调
34
36
  this.beforeFireCallback = options.beforeFireCallback
35
37
  }
36
- /**
37
- * 发送聊天消息
38
- */
39
- sendChatMessage (options) {
40
- const message = Object.assign({
41
- content: null,
42
- msgType: null,
43
- msgSubType: null,
44
- qwAccountId: null
45
- // contactId: null,
46
- // roomId: null
47
- }, options, {
48
- cmdType: 'CmdQwSendMessage'
38
+
39
+ sendMessage (message, beforeCallback) {
40
+ return this.socket.sendMessage(message, (data) => {
41
+ let ps = Promise.resolve()
42
+ // 如果发送消息的时候,连接是断开或者失败的,重新连接一次,主要是防止用户发送消息的时候网络断开了,提示socket已关闭,体验不好,程序静默来处理
43
+ if (this.socket.connectStatus === Socket.CONNECT_STATUS_ENUM.Close || this.socket.connectStatus === Socket.CONNECT_STATUS_ENUM.Error) {
44
+ ps = this.socket.reconnect()
45
+ }
46
+ return ps.finally(() => {
47
+ if (beforeCallback) {
48
+ return beforeCallback(data)
49
+ }
50
+ })
49
51
  })
50
- return this.socket.sendMessage(message)
51
52
  }
52
53
 
53
54
  connect () {
@@ -25,6 +25,7 @@ class ClientChat {
25
25
  _sessionPollRequestMap = {}
26
26
 
27
27
  constructor (options) {
28
+
28
29
  options = Object.assign({
29
30
  client: null,
30
31
  socket: null, // socket实例