@@ -18,6 +18,7 @@ import {DATA_SYNCHRONIZER_TOPIC, DATASOURCE_TIME_TOPIC} from "../Constants";
1818import DataSource from "./DataSource.datasource" ;
1919import { Mode } from './Mode' ;
2020import MqttConnector from "../connector/MqttConnector" ;
21+ import { isDefined } from "../utils/Utils" ;
2122
2223/**
2324 * The DataSource is the abstract class used to create different datasources.
@@ -186,7 +187,7 @@ class TimeSeriesRealtimeDatasource extends DataSource {
186187 await this . checkInit ( ) ;
187188 const topic = DATA_SYNCHRONIZER_TOPIC + this . dataSynchronizer . id ;
188189 this . properties . version = this . dataSynchronizer . version ( ) ;
189- return this . dataSourceWorker . postMessageWithAck ( {
190+ return this . getWorker ( ) . postMessageWithAck ( {
190191 message : 'topics' ,
191192 topics : {
192193 data : topic ,
@@ -201,29 +202,32 @@ class TimeSeriesRealtimeDatasource extends DataSource {
201202 }
202203
203204 async removeDataSynchronizer ( ) {
204- if ( this . dataSourceWorker ) {
205- this . dataSourceWorker . terminate ( ) ;
206- this . dataSynchronizer = undefined ;
207- }
205+ await this . removeWorker ( ) ;
206+ this . dataSynchronizer = undefined ;
208207 // this.init = undefined;
209208 return this . checkInit ( ) ;
210-
211209 }
212210
213211 /**
214212 * Disconnect the dataSource then the protocol will be closed as well.
215213 */
216214 async disconnect ( ) {
217- await this . checkInit ( ) ;
218- return this . dataSourceWorker . postMessageWithAck ( {
219- message : 'disconnect' ,
220- dsId : this . id ,
221- mode : Mode . REAL_TIME ,
222- } ) ;
215+ if ( isDefined ( this . init ) ) {
216+ try {
217+ return this . getWorker ( ) . postMessageWithAck ( {
218+ message : 'disconnect' ,
219+ dsId : this . id ,
220+ mode : Mode . REAL_TIME ,
221+ } ) ;
222+ } catch ( ex ) {
223+ console . error ( ex ) ;
224+ }
225+ }
223226 }
224227
225228 async doConnect ( ) {
226- return this . dataSourceWorker . postMessageWithAck ( {
229+ await this . checkInit ( ) ;
230+ return this . getWorker ( ) . postMessageWithAck ( {
227231 message : 'connect' ,
228232 startTime : 'now' ,
229233 version : this . version ( ) ,
@@ -247,7 +251,7 @@ class TimeSeriesRealtimeDatasource extends DataSource {
247251 topics . sync = this . dataSynchronizer . getTimeTopicId ( )
248252 }
249253
250- return this . dataSourceWorker . postMessageWithAck ( {
254+ return this . getWorker ( ) . postMessageWithAck ( {
251255 message : 'topics' ,
252256 topics : topics ,
253257 dsId : this . id ,
@@ -273,6 +277,12 @@ class TimeSeriesRealtimeDatasource extends DataSource {
273277 version ( ) {
274278 return this . properties . version ;
275279 }
280+
281+ async reset ( ) {
282+ console . warn ( `dataSource ${ this . id } has been reset` ) ;
283+ await super . reset ( ) ;
284+ return this . doConnect ( ) ;
285+ }
276286}
277287
278288export default TimeSeriesRealtimeDatasource ;
0 commit comments