@@ -11,17 +11,20 @@ export async function init(id) {
1111
1212 const el = document . getElementById ( id ) ;
1313 if ( el === null ) {
14- return ;
14+ return false ;
1515 }
1616
1717 const result = await initWindow ( id ) ;
1818 if ( result . inited === false ) {
19- return ;
19+ return false ;
2020 }
2121
2222 Data . set ( id , {
23- iWndIndex : result . iWndIndex
23+ iWndIndex : result . iWndIndex ,
24+ inited : true
2425 } ) ;
26+
27+ return true ;
2528}
2629
2730const initWindow = id => {
@@ -30,7 +33,7 @@ const initWindow = id => {
3033 bWndFull : true ,
3134 iWndowType : 1 ,
3235 cbSelWnd : function ( xmlDoc ) {
33- result . iWndIndex = getTagNameFirstValue ( xmlDoc , "SelectWnd" )
36+ result . iWndIndex = parseInt ( getTagNameFirstValue ( xmlDoc , "SelectWnd" ) ) ;
3437 } ,
3538 cbDoubleClickWnd : function ( iWndIndex , bFullScreen ) {
3639
@@ -59,6 +62,14 @@ const initWindow = id => {
5962
6063export async function login ( id , ip , port , userName , password , loginType ) {
6164 const vision = Data . get ( id ) ;
65+ const { inited, logined } = vision ;
66+ if ( inited !== true || ip . length === 0 || port <= 0 || userName . length === 0 || password . length === 0 ) {
67+ return false ;
68+ }
69+ if ( logined === true ) {
70+ return true ;
71+ }
72+
6273 vision . szDeviceIdentify = `${ ip } _${ port } ` ;
6374 vision . logined = null ;
6475 vision . loginErrorCode = null ;
@@ -84,9 +95,9 @@ export async function login(id, ip, port, userName, password, loginType) {
8495
8596 return new Promise ( ( resolve , reject ) => {
8697 const handler = setInterval ( async ( ) => {
87- if ( vision . logined !== void 0 ) {
98+ if ( vision . logined !== null ) {
8899 clearInterval ( handler )
89- resolve ( vision ) ;
100+ resolve ( vision . logined ) ;
90101 }
91102 } , 16 ) ;
92103 } ) ;
@@ -152,34 +163,27 @@ const getChannelInfo = vision => {
152163 const handler = setInterval ( ( ) => {
153164 if ( analog_completed && digital_completed && zero_completed ) {
154165 clearInterval ( handler )
155- resolve ( vision ) ;
166+ resolve ( ) ;
156167 }
157168 } , 16 ) ;
158169 } ) ;
159170}
160171
161- export function logout ( id ) {
172+ export async function logout ( id ) {
162173 const vision = Data . get ( id ) ;
163- const { szDeviceIdentify } = vision ;
174+ const { szDeviceIdentify, logined } = vision ;
175+ if ( logined !== true ) {
176+ vision . logined = false ;
177+ return ;
178+ }
164179
165- let completed = null ;
166- WebVideoCtrl . I_Logout ( szDeviceIdentify ) . then ( ( ) => {
167- completed = true ;
168- } , ( ) => {
169- completed = false ;
170- } ) ;
180+ stopRealPlay ( id ) ;
171181
172- return new Promise ( ( resolve , reject ) => {
173- const handler = setInterval ( ( ) => {
174- if ( completed !== null ) {
175- clearInterval ( handler )
176- resolve ( vision ) ;
177- }
178- } , 16 ) ;
179- } ) ;
182+ await WebVideoCtrl . I_Logout ( szDeviceIdentify ) ;
183+ vision . logined = false ;
180184}
181185
182- export async function startRealPlay ( id ) {
186+ export async function startRealPlay ( id , iStreamType , iChannelID ) {
183187 const vision = Data . get ( id ) ;
184188 const { iWndIndex, szDeviceIdentify } = vision ;
185189
@@ -188,26 +192,28 @@ export async function startRealPlay(id) {
188192
189193 const oWndInfo = WebVideoCtrl . I_GetWindowStatus ( iWndIndex ) ;
190194 const iRtspPort = vision . devicePort . iRtspPort ;
191- const iChannelID = 1 ;
192195 const bZeroChannel = false ;
193- const iStreamType = 1 ;
194-
196+ let completed = null ;
195197 const startRealPlay = function ( ) {
196198 WebVideoCtrl . I_StartRealPlay ( szDeviceIdentify , {
199+ iWndIndex : iWndIndex ,
197200 iStreamType : iStreamType ,
198201 iChannelID : iChannelID ,
199202 bZeroChannel : bZeroChannel ,
200203 iPort : iRtspPort ,
201204 success : function ( ) {
202-
205+ vision . realPlaying = true ;
206+ completed = true ;
203207 } ,
204208 error : function ( oError ) {
205-
209+ vision . realPlaying = false ;
210+ completed = false ;
206211 }
207212 } ) ;
208213 } ;
209214
210- if ( oWndInfo != null ) {
215+ console . log ( oWndInfo ) ;
216+ if ( oWndInfo !== null ) {
211217 WebVideoCtrl . I_Stop ( {
212218 success : function ( ) {
213219 startRealPlay ( ) ;
@@ -217,39 +223,70 @@ export async function startRealPlay(id) {
217223 else {
218224 startRealPlay ( ) ;
219225 }
226+
227+ return new Promise ( ( resolve , reject ) => {
228+ const handler = setInterval ( ( ) => {
229+ if ( completed !== null ) {
230+ clearInterval ( handler )
231+ resolve ( completed ) ;
232+ }
233+ } , 16 ) ;
234+ } ) ;
220235}
221236
222237export function stopRealPlay ( id ) {
223238 const vision = Data . get ( id ) ;
224- const { iWndIndex, szDeviceIdentify } = vision ;
239+ const { iWndIndex, realPlaying } = vision ;
240+
241+ if ( realPlaying !== true ) {
242+ return true ;
243+ }
225244
226245 const oWndInfo = WebVideoCtrl . I_GetWindowStatus ( iWndIndex ) ;
246+ let completed = null ;
227247 if ( oWndInfo !== null ) {
228248 WebVideoCtrl . I_Stop ( {
229249 success : function ( ) {
230-
250+ vision . realPlaying = false ;
251+ completed = true ;
231252 } ,
232253 error : function ( oError ) {
233-
254+ completed = false ;
234255 }
235256 } ) ;
236257 }
258+
259+ return new Promise ( ( resolve , reject ) => {
260+ const handler = setInterval ( ( ) => {
261+ if ( completed !== null ) {
262+ clearInterval ( handler )
263+ resolve ( completed ) ;
264+ }
265+ } , 16 ) ;
266+ } ) ;
237267}
238268
239269export function dispose ( id ) {
240- stopRealPlay ( id ) ;
241- logout ( id ) ;
270+ const vision = Data . get ( id ) ;
271+ Data . remove ( id ) ;
272+
273+ const { realPlaying, logined } = vision ;
274+ if ( realPlaying === true ) {
275+ stopRealPlay ( id ) ;
276+ }
277+ if ( logined === true ) {
278+ logout ( id ) ;
279+ }
242280 WebVideoCtrl . I_DestroyPlugin ( ) ;
243281
244- Data . remove ( id ) ;
245282}
246283
247- const getTagNameFirstValue = ( xmlDoc , tagName ) => {
284+ const getTagNameFirstValue = ( xmlDoc , tagName , defaultValue = '0' ) => {
248285 const tags = xmlDoc . getElementsByTagName ( tagName ) ;
249286 if ( tags . length > 0 ) {
250287 return tags [ 0 ] . textContent ;
251288 }
252- return null ;
289+ return defaultValue ;
253290}
254291
255292const getTagNameValues = ( xmlDoc , tagName ) => {
0 commit comments