@@ -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 => {
@@ -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 ) {
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 ;
@@ -152,15 +163,19 @@ 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
161172export 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
165180 let completed = null ;
166181 WebVideoCtrl . I_Logout ( szDeviceIdentify ) . then ( ( ) => {
@@ -173,13 +188,13 @@ export function logout(id) {
173188 const handler = setInterval ( ( ) => {
174189 if ( completed !== null ) {
175190 clearInterval ( handler )
176- resolve ( vision ) ;
191+ resolve ( ) ;
177192 }
178193 } , 16 ) ;
179194 } ) ;
180195}
181196
182- export async function startRealPlay ( id ) {
197+ export async function startRealPlay ( id , iStreamType , iChannelID ) {
183198 const vision = Data . get ( id ) ;
184199 const { iWndIndex, szDeviceIdentify } = vision ;
185200
@@ -188,26 +203,28 @@ export async function startRealPlay(id) {
188203
189204 const oWndInfo = WebVideoCtrl . I_GetWindowStatus ( iWndIndex ) ;
190205 const iRtspPort = vision . devicePort . iRtspPort ;
191- const iChannelID = 1 ;
192206 const bZeroChannel = false ;
193- const iStreamType = 1 ;
194-
207+ let completed = null ;
195208 const startRealPlay = function ( ) {
196209 WebVideoCtrl . I_StartRealPlay ( szDeviceIdentify , {
210+ iWndIndex : iWndIndex ,
197211 iStreamType : iStreamType ,
198212 iChannelID : iChannelID ,
199213 bZeroChannel : bZeroChannel ,
200214 iPort : iRtspPort ,
201215 success : function ( ) {
202-
216+ vision . realPlaying = true ;
217+ completed = true ;
203218 } ,
204219 error : function ( oError ) {
205-
220+ vision . realPlaying = false ;
221+ completed = false ;
206222 }
207223 } ) ;
208224 } ;
209225
210- if ( oWndInfo != null ) {
226+ console . log ( oWndInfo ) ;
227+ if ( oWndInfo !== null ) {
211228 WebVideoCtrl . I_Stop ( {
212229 success : function ( ) {
213230 startRealPlay ( ) ;
@@ -217,31 +234,59 @@ export async function startRealPlay(id) {
217234 else {
218235 startRealPlay ( ) ;
219236 }
237+
238+ return new Promise ( ( resolve , reject ) => {
239+ const handler = setInterval ( ( ) => {
240+ if ( completed !== null ) {
241+ clearInterval ( handler )
242+ resolve ( completed ) ;
243+ }
244+ } , 16 ) ;
245+ } ) ;
220246}
221247
222248export function stopRealPlay ( id ) {
223249 const vision = Data . get ( id ) ;
224250 const { iWndIndex, szDeviceIdentify } = vision ;
225251
226252 const oWndInfo = WebVideoCtrl . I_GetWindowStatus ( iWndIndex ) ;
253+ let completed = null ;
254+ console . log ( oWndInfo ) ;
227255 if ( oWndInfo !== null ) {
228256 WebVideoCtrl . I_Stop ( {
229257 success : function ( ) {
230-
258+ vision . realPlaying = false ;
259+ completed = true ;
231260 } ,
232261 error : function ( oError ) {
233-
262+ completed = false ;
234263 }
235264 } ) ;
236265 }
266+
267+ return new Promise ( ( resolve , reject ) => {
268+ const handler = setInterval ( ( ) => {
269+ if ( completed !== null ) {
270+ clearInterval ( handler )
271+ resolve ( completed ) ;
272+ }
273+ } , 16 ) ;
274+ } ) ;
237275}
238276
239277export function dispose ( id ) {
240- stopRealPlay ( id ) ;
241- logout ( id ) ;
278+ const vision = Data . get ( id ) ;
279+ Data . remove ( id ) ;
280+
281+ const { realPlaying, logined } = vision ;
282+ if ( realPlaying === true ) {
283+ stopRealPlay ( id ) ;
284+ }
285+ if ( logined === true ) {
286+ logout ( id ) ;
287+ }
242288 WebVideoCtrl . I_DestroyPlugin ( ) ;
243289
244- Data . remove ( id ) ;
245290}
246291
247292const getTagNameFirstValue = ( xmlDoc , tagName ) => {
0 commit comments