Reputation: 53
I am calling a function from service in component. Service will get data from sdk and response in callback function. I'm not able to send callback response to component.
Component.ts
async publishSession() {
let publishCallback = await this.myService.publishStream();
}
Service.ts
callbackResponse;
publishStream(publishCapabilities, mediaConstraints) {
this.session = session;
var videoElement = document.getElementsByTagName('video')[0];
var publishOptions = {
publishToken: publishing,
mediaConstraints: mediaConstraints,
videoElement: videoElement
};
return this.sdk.publishToChannel(publishOptions, this.publisherCallback.bind(this));
}
publisherCallback(error, response) {
if (error) {
this.logger.log(error);
}
this.callbackResponse = response; // need this response in component once received here.
}
It returns null;
Upvotes: 0
Views: 217
Reputation: 1863
As @JacopoSciampi mentioned, the method publishToChannel()
needs to itself return a value. You should then await on publishCallback
to get the value from the latest callback you called. IMO this structure is a little bit redundant and you could simplify this entire structure. You could do:
// component.ts
await publishStream()
await publishToChannel()
Upvotes: 1