liuxiaolong
2019-05-06 3e0536f508aad49f743e7bfabca34e3980a1b6e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// 初始化插件
/* eslint-disable */
export function WebVideo(json) {
  console.log(json, '参数')
  this.g_iWndIndex = 0
  this.szDeviceIdentify = ''
  this.deviceport = json.deviceport ? json.deviceport : ''
  this.rtspport = json.rtspport ? json.rtspport : ''
  this.channels = []
  this.ip = json.ip ? json.ip : ''
  this.port = json.port ? json.port : ''
  this.username = json.username ? json.username : ''
  this.password = json.password ? json.password : ''
  this.domId = json.domId ? json.domId : 'divPlugin'
  this.init = function() {
    var self = this
    // 检查插件是否已经安装过
    var iRet = WebVideoCtrl.I_CheckPluginInstall()
    if (iRet === -1) {
      alert('您还未安装过插件,双击开发包目录里的WebComponentsKit.exe安装!')
      return
    }
    // 初始化插件参数及插入插件
    WebVideoCtrl.I_InitPlugin('100%', '100%', {
      bWndFull: true,
      iPackageType: 2,
      iWndowType: 1,
      cbInitPluginComplete: function() {
        WebVideoCtrl.I_InsertOBJECTPlugin(self.domId)
      }
    })
  }
  // 登录
  this.clickLogin = function() {
    var self = this
 
    if ('' === self.ip || '' === self.port) {
      return
    }
 
    self.szDeviceIdentify = self.ip + '_' + self.port
    console.log(self.szDeviceIdentify, 'szDeviceIdentify', WebVideoCtrl)
    const res = WebVideoCtrl.I_Login(
      self.ip,
      1,
      self.port,
      self.username,
      self.password,
      {
        success: function(xmlDoc) {
          console.log(xmlDoc, 'xmlDoc  登录成功!')
          setTimeout(function() {
            self.getChannelInfo()
            self.getDevicePort()
          }, 10)
          setTimeout(function() {
            self.clickStartRealPlay()
          }, 500)
        },
        error: function(status, xmlDoc) {
          console.log('登录失败!')
        }
      }
    )
 
    // 已经登陆
    if (res === -1) {
      console.log('已经登陆过了')
      setTimeout(function() {
        self.getChannelInfo()
        self.getDevicePort()
      }, 10)
      setTimeout(function() {
        self.clickStartRealPlay()
      }, 500)
    }
  }
  // 退出
  this.clickLogout = function() {
    var self = this
    if (self.szDeviceIdentify == null) {
      return
    }
    var iRet = WebVideoCtrl.I_Logout(self.szDeviceIdentify)
    if (iRet === 0) {
      self.getChannelInfo()
      self.getDevicePort()
    }
  }
  // 获取通道
  this.getChannelInfo = function() {
    var self = this
    self.channels = []
    if (null === self.szDeviceIdentify) {
      return
    }
    // 模拟通道
    WebVideoCtrl.I_GetAnalogChannelInfo(self.szDeviceIdentify, {
      async: false,
      success: function(xmlDoc) {
        var oChannels = $(xmlDoc).find('VideoInputChannel')
 
        $.each(oChannels, function(i) {
          var id = $(this)
              .find('id')
              .eq(0)
              .text(),
            name = $(this)
              .find('name')
              .eq(0)
              .text()
          if ('' === name) {
            name = 'Camera ' + (i < 9 ? '0' + (i + 1) : i + 1)
          }
          // oSel.append("<option value='" + id + "' bZero='false'>" + name + "</option>");
          self.channels.push({
            id: id,
            name: name
          })
        })
        console.log('获取模拟通道成功!')
      },
      error: function(status, xmlDoc) {
        // showOPInfo(szDeviceIdentify + " 获取模拟通道失败!", status, xmlDoc);
        console.log('获取模拟通道失败!', status, xmlDoc)
      }
    })
  }
  // 获取端口
  this.getDevicePort = function() {
    var self = this
 
    if (null === self.szDeviceIdentify) {
      return
    }
 
    var oPort = WebVideoCtrl.I_GetDevicePort(self.szDeviceIdentify)
    if (oPort != null) {
      self.deviceport = oPort.iDevicePort
      self.deviceport = oPort.iRtspPort
 
      console.log('获取端口成功!', self.szDeviceIdentify)
    } else {
      console.log(' 获取端口失败!')
    }
  }
 
  // 开始预览
  this.clickStartRealPlay = function() {
    var self = this
    var oWndInfo = WebVideoCtrl.I_GetWindowStatus(self.g_iWndIndex),
      iChannelID = self.channels[0].value,
      szInfo = ''
    console.log(self, 'self')
    if (null === self.szDeviceIdentify) {
      return
    }
    console.log(
      self.rtspport,
      'self.rtspport',
      iChannelID,
      'iChannelID',
      self.szDeviceIdentify
    )
    var startRealPlay = function() {
      var res = WebVideoCtrl.I_StartRealPlay(self.szDeviceIdentify, {
        iRtspPort: self.rtspport,
        iStreamType: '1',
        iChannelID: iChannelID,
        bZeroChannel: false,
        success: function() {
          console.log('开始预览成功')
        },
        error: function(status, xmlDoc) {
          if (403 === status) {
            szInfo = '设备不支持Websocket取流!'
          } else {
            szInfo = '开始预览失败!'
          }
          console.log(szInfo, status, xmlDoc)
        }
      })
      console.log(res, 'res---播放函数')
    }
 
    if (oWndInfo != null) {
      // 已经在播放了,先停止
      WebVideoCtrl.I_Stop({
        success: function() {
          startRealPlay()
        }
      })
    } else {
      startRealPlay()
    }
  }
  // 停止预览
  this.clickStopRealPlay = function() {
    var self = this
    var oWndInfo = WebVideoCtrl.I_GetWindowStatus(self.g_iWndIndex)
    if (oWndInfo != null) {
      WebVideoCtrl.I_Stop({
        success: function() {},
        error: function() {}
      })
    }
  }
}