1

Duplicate Session

Тема: Duplicate Session

Hello,

Trying to create a session duplicate using the wialonjs-api library to avoid CORS; the following code duplication works ok but the challenge is in case if multiple components try to call the duplicate at the same time a single session instance with the same SID is getting returned for all the simultaneous calls. Is there any advice in such a use case where we may need to get 3 to 4 simultaneous duplicate yet unique sessions ? We tried to differentiate calls with the AppName param attribute, but it hasn't helped. Any insight on this is greatly appreciated!

generateNewSessionObject: async function(context: string,urlSid: string): Promise<any> {
  try {
   
    const newSession = new W.Session(WIALON_API_URL, {
      eventsTimeout: 0
    });   
   
    // Duplicate with a unique context name
    const duplicateParams = {
      sid:urlSid,
      operateAs:"",     
      continueCurrentSession: true,
      appName:context
    };
    console.log("MY CONTEXT",duplicateParams);
   
    const response = await new Promise<any>((resolve, reject) => {
      newSession.execute('core/duplicate', duplicateParams, (response: any) => {
        if (response?.error) {
          reject(new Error(`Duplication failed: ${response.error}`));
        } else {
          resolve(response);
        }
      });
    });
   
    return newSession;
  } catch (error) {
    console.error("Error generating new session object:", error);
    throw error;
  }
},


BR