原始代码如下:
this.messages = <Subject<IProgressStatusObject>>wsService
... .connectArchivalProcessCompleteService(UrlSettings.WEBSOCKET_URL + "archiveProcessComplete")
...
我必须更改第一个参数的设置方式。 当前,它仅使用一个常量:'UrlSettings.WEBSOCKET_URL',现在需要从服务器上存储的值进行设置。我已经定义了一个服务方法,该方法可以返回所需的数据,但是我很难设置从服务调用返回的期望值。
这是我到目前为止所拥有的:
@Injectable()
export class ArchivalProcessCompleteService {
public messages: Subject<IProgressStatusObject>;
constructor(
wsService: WebsocketService,
configurationService: ConfigurationService
) {
console.log('connected with localhost url');
this.messages = <Subject<IProgressStatusObject>>(
wsService
.connectArchivalProcessCompleteService(
this.GetWebSocketUrl(configurationService) + 'archiveProcessComplete'
)
.map(
(response: MessageEvent): IProgressStatusObject => {
const data = JSON.parse(response.data);
return {
identifier: data.Identifier,
isArchivingInProgress: data.IsArchivingInProgress,
totalRecordsToArchive: data.TotalRecordsToArchive,
numberOfRecordsArchived: data.NumberOfRecordsArchived,
isArchivingCancelled: data.IsArchiveCancelled
};
}
)
);
}
GetWebSocketUrl(configurationService: ConfigurationService): string{
let wsUrl;
configurationService.getConfigurationData().subscribe(data => {
const WebSocketUrl = this.doSetWebSocketUrl(data);
wsUrl = WebSocketUrl;
});
return wsUrl;
}
private doSetWebSocketUrl(configData: Configuration): string {
return configData.WebSocketUrl;
}
我知道我的doSetWebSocketUrl()方法的返回值具有预期的数据集,但是GetWebSocketUrl方法'wsUrl'的返回值始终是不确定的吗?
我只需要传递给WebsocketService的参数看起来像:.connectArchivalProcessCompleteService('ws:// sequoiaserver:14556 /'+“ archiveProcessComplete”)这是从configurationService.getConfigurationData调用返回的值。