in src/sdk/Transcription/ConversationTranslator.ts [184:275]
public joinConversationAsync(conversation: any, nickname: string, param1?: string | Callback, param2?: Callback, param3?: Callback): void {
try {
if (typeof conversation === "string") {
Contracts.throwIfNullOrUndefined(conversation, this.privErrors.invalidArgs.replace("{arg}", "conversation id"));
Contracts.throwIfNullOrWhitespace(nickname, this.privErrors.invalidArgs.replace("{arg}", "nickname"));
if (!!this.privConversation) {
this.handleError(new Error(this.privErrors.permissionDeniedStart), param3);
}
let lang: string = param1 as string;
if (lang === undefined || lang === null || lang === "") { lang = ConversationConnectionConfig.defaultLanguageCode; }
// create a placeholder config
this.privSpeechTranslationConfig = SpeechTranslationConfig.fromSubscription(
this.privPlaceholderKey,
this.privPlaceholderRegion);
this.privSpeechTranslationConfig.setProfanity(ProfanityOption.Masked);
this.privSpeechTranslationConfig.addTargetLanguage(lang);
this.privSpeechTranslationConfig.setProperty(PropertyId[PropertyId.SpeechServiceConnection_RecoLanguage], lang);
this.privSpeechTranslationConfig.setProperty(PropertyId[PropertyId.ConversationTranslator_Name], nickname);
const endpoint: string = this.privProperties.getProperty(PropertyId.ConversationTranslator_Host);
if (endpoint) {
this.privSpeechTranslationConfig.setProperty(PropertyId[PropertyId.ConversationTranslator_Host], endpoint);
}
const speechEndpointHost: string = this.privProperties.getProperty(PropertyId.SpeechServiceConnection_Host);
if (speechEndpointHost) {
this.privSpeechTranslationConfig.setProperty(PropertyId[PropertyId.SpeechServiceConnection_Host], speechEndpointHost);
}
// join the conversation
this.privConversation = new ConversationImpl(this.privSpeechTranslationConfig);
this.privConversation.conversationTranslator = this;
this.privConversation.joinConversationAsync(
conversation,
nickname,
lang,
((result: string) => {
if (!result) {
this.handleError(new Error(this.privErrors.permissionDeniedConnect), param3);
}
this.privSpeechTranslationConfig.authorizationToken = result;
// connect to the ws
this.privConversation.startConversationAsync(
(() => {
this.handleCallback(param2, param3);
}),
((error: any) => {
this.handleError(error, param3);
}));
}),
((error: any) => {
this.handleError(error, param3);
}));
} else if (typeof conversation === "object") {
Contracts.throwIfNullOrUndefined(conversation, this.privErrors.invalidArgs.replace("{arg}", "conversation id"));
Contracts.throwIfNullOrWhitespace(nickname, this.privErrors.invalidArgs.replace("{arg}", "nickname"));
// save the nickname
this.privProperties.setProperty(PropertyId.ConversationTranslator_Name, nickname);
// ref the conversation object
this.privConversation = conversation as ConversationImpl;
// ref the conversation translator object
this.privConversation.conversationTranslator = this;
Contracts.throwIfNullOrUndefined(this.privConversation, this.privErrors.permissionDeniedConnect);
Contracts.throwIfNullOrUndefined(this.privConversation.room.token, this.privErrors.permissionDeniedConnect);
this.privSpeechTranslationConfig = conversation.config;
this.handleCallback(param1 as Callback, param2);
} else {
this.handleError(
new Error(this.privErrors.invalidArgs.replace("{arg}", "invalid conversation type")),
param2);
}
} catch (error) {
this.handleError(error, typeof param1 === "string" ? param3 : param2);
}
}