Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XMLHttpRequest is not defined #19

Open
Belephor92 opened this issue Sep 7, 2020 · 6 comments
Open

XMLHttpRequest is not defined #19

Belephor92 opened this issue Sep 7, 2020 · 6 comments

Comments

@Belephor92
Copy link

Belephor92 commented Sep 7, 2020

Subject of the issue

When calling this.client.request(new SessionStartAction(authData)) I receive the error "XMLHttpRequest is not defined"
I checked the configuration with the start Kultura Session guide from the workflow section and the connection itself should work.

Your environment

  • kaltura-typescript-version: 16.5
  • nest-js project environment
  • Package manager: npm

Steps to reproduce

Set up the library as described in https://developer.kaltura.com/workflows/Generate_API_Sessions/Authentication;step=1

Expected behaviour

I should receive the token

Actual behaviour

I get following error:
ReferenceError: XMLHttpRequest is not defined
at C:\Career Partner\Projects\idss-discovery\node_modules\kaltura-typescript-client\adapters\adapters\utils.ts:102:15
at new CancelableAction (C:\Career Partner\Projects\idss-discovery\node_modules\kaltura-typescript-client\cancelable-action.ts:23:26)
at Object.createCancelableAction (C:\Career Partner\Projects\idss-discovery\node_modules\kaltura-typescript-client\adapters\adapters\utils.ts:101:17)
at KalturaRequestAdapter.transmit (C:\Career Partner\Projects\idss-discovery\node_modules\kaltura-typescript-client\adapters\adapters\kaltura-request-adapter.ts:22:21)
at KalturaClient.request (C:\Career Partner\Projects\idss-discovery\node_modules\kaltura-typescript-client\kaltura-client-service.ts:96:48)
at new VideoSearchService (C:\Career Partner\Projects\idss-discovery\src\domain\modules\video-search\video-search.service.ts:32:17)
at Injector.instantiateClass (C:\Career Partner\Projects\idss-discovery\node_modules@nestjs\core\injector\injector.js:290:19)
at callback (C:\Career Partner\Projects\idss-discovery\node_modules@nestjs\core\injector\injector.js:77:41)
at Injector.resolveConstructorParams (C:\Career Partner\Projects\idss-discovery\node_modules@nestjs\core\injector\injector.js:118:24)
at Injector.loadInstance (C:\Career Partner\Projects\idss-discovery\node_modules@nestjs\core\injector\injector.js:81:9)

I tried adding XMLHttpRequest manually using npm install to the project and added it as dependency in util.js in my node_modules.
The error disappeard but when starting the connection I get another error: KalturaclientException that contains the correct response token. I guess this behavior comes from the manually installed XMLHttpRequest package.

Do you have any idea how to fix my problem?

Thanks in advance,

best regards,
Tony

@kaltura-hooks
Copy link

Hi @Belephor92,

Thank for you reporting an issue and helping improve Kaltura!

To get the fastest response time, and help the maintainers review and test your reported issues or suggestions, please ensure that your issue includes the following (please comment with more info if you have not included all this info in your original issue):

  • Is the issue you're experiencing consistent and across platforms? or does it only happens on certain conditions?
    please provide as much details as possible.
  • Which Kaltura deployment you're using: Kaltura SaaS, or self-hosted?
    If self hosted, are you using the RPM or deb install?
  • Packages installed.
    When using RPM, paste the output for:
	# rpm -qa \"kaltura*\"
For deb based systems:
	# dpkg -l \"kaltura-*\"
  • If running a self hosted ENV - provide the MySQL server version used
  • If running a self hosted ENV - is this a single all in 1 server or a cluster?
  • If running a self hosted ENV, while making the problematic request, run:
	# tail -f /opt/kaltura/log/*.log /opt/kaltura/log/batch/*.log | grep -A 1 -B 1 --color \"ERR:\|PHP\|trace\|CRIT\|\[error\]\"

and paste the output.

  • When relevant, provide any screenshots or screen recordings showing the issue you're experiencing.

For general troubleshooting see:
https://github.com/kaltura/platform-install-packages/blob/Jupiter-10.13.0/doc/kaltura-packages-faq.md#troubleshooting-help

If you only have a general question rather than a bug report, please close this issue and post at:
http://forum.kaltura.org

Thank you in advance,

@Belephor92
Copy link
Author

This is rather a bug than a question.
The XMLHttpResponse is a missing dependency as I assume. This has to be fixed.

@shugli
Copy link

shugli commented Sep 29, 2021

Hi @Belephor92! I am experiencing the same issue as you.
Did you ever get it solved somehow?
Thanks for your feedback!

@Belephor92
Copy link
Author

Belephor92 commented Sep 29, 2021

Hi @shugli,
I think the problem was how we built up the request. I had a look at our current working code for you.

async checkSession() {
      this.logger.verbose('checking session');
      await kaltura.services.user
        .get(kalturaConfig.USER_ID)
        .execute(this.client)
        .then((result) => {
          this.logger.verbose('session active');
        }, (error) => {
          this.logger.warn('session has to be restarted');
          this.startKalturaSession();
          return new Promise((resolve) => setTimeout(resolve, 1000)); // wait a second for session to be started
        });
    }
    startKalturaSession() {
      this.logger.verbose('trying to start kaltura session');
      kaltura.services.session
        .start(
          kalturaConfig.ADMIN_SECRET,
          kalturaConfig.USER_ID,
          kaltura.enums.SessionType.ADMIN,
          kalturaConfig.PARTNER_ID,
          kalturaConfig.EXPIRY,
          'appId:appName-appDomain',
        )
        .completion((success, ks) => {
          if (!success) throw new Error(ks.message);
          this.client.setKs(ks);
          kaltura.services.user
            .get(kalturaConfig.USER_ID)
            .execute(this.client)
            .then((result) => {
              this.logger.verbose('kaltura session started');
            });
        })
        .execute(this.client);
    }

The startKalturaSession function starts the session.
Before every call I use the checkSession function in order to revalidate the token.

Here is an example for a call that we do:

    public async executeESearch(searchFilters: {searchTerm: string, courseCode: string, pageSize?: number}) {
      await this.checkSession();
      const searchTerm = SearchUtil.replaceUmlaute(searchFilters.searchTerm);
      this.logger.verbose(`starting ESearch for course ${searchFilters.courseCode} with term ${searchTerm}`);
      const searchParams = new kaltura.objects.ESearchEntryParams();
      searchParams.searchOperator = new kaltura.objects.ESearchEntryOperator();
      searchParams.searchOperator.operator = kaltura.enums.ESearchOperatorType.OR_OP;
      searchParams.searchOperator.searchItems = [];

      // courseCode search in metadata
      searchParams.searchOperator.searchItems[0] = new kaltura.objects.ESearchEntryMetadataItem();
      searchParams.searchOperator.searchItems[0].metadataProfileId = someIntForMetadata;
      searchParams.searchOperator.searchItems[0].xpath = 'wont show here'
      searchParams.searchOperator.searchItems[0].addHighlight = false;
      searchParams.searchOperator.searchItems[0].itemType = kaltura.enums.ESearchItemType.EXACT_MATCH;
      searchParams.searchOperator.searchItems[0].searchTerm = searchFilters.courseCode;

      // AND
      searchParams.searchOperator.searchItems[1] = new kaltura.objects.ESearchEntryOperator();
      searchParams.searchOperator.searchItems[1].operator = kaltura.enums.ESearchOperatorType.OR_OP;
      searchParams.searchOperator.searchItems[1].searchItems = [];

      // in Name
      searchParams.searchOperator.searchItems[1].searchItems[0] = new kaltura.objects.ESearchEntryItem();
      searchParams.searchOperator.searchItems[1].searchItems[0].searchTerm = searchTerm;
      searchParams.searchOperator.searchItems[1].searchItems[0].itemType = kaltura.enums.ESearchItemType.PARTIAL;
      searchParams.searchOperator.searchItems[1].searchItems[0].addHighlight = false;
      searchParams.searchOperator.searchItems[1].searchItems[0].fieldName = kaltura.enums.ESearchEntryFieldName.NAME;

      // or Description
      searchParams.searchOperator.searchItems[1].searchItems[1] = new kaltura.objects.ESearchEntryItem();
      searchParams.searchOperator.searchItems[1].searchItems[1].searchTerm = searchTerm;
      searchParams.searchOperator.searchItems[1].searchItems[1].itemType = kaltura.enums.ESearchItemType.PARTIAL;
      searchParams.searchOperator.searchItems[1].searchItems[1].addHighlight = false;
      searchParams.searchOperator.searchItems[1].searchItems[1].fieldName = kaltura.enums.ESearchEntryFieldName.DESCRIPTION;

      // or Tags
      searchParams.searchOperator.searchItems[1].searchItems[2] = new kaltura.objects.ESearchEntryItem();
      searchParams.searchOperator.searchItems[1].searchItems[2].searchTerm = searchTerm;
      searchParams.searchOperator.searchItems[1].searchItems[2].itemType = kaltura.enums.ESearchItemType.PARTIAL;
      searchParams.searchOperator.searchItems[1].searchItems[2].addHighlight = false;
      searchParams.searchOperator.searchItems[1].searchItems[2].fieldName = kaltura.enums.ESearchEntryFieldName.TAGS;

      const pager = new kaltura.objects.Pager();
      pager.pageSize = searchFilters.pageSize ?? 50;

      return kaltura.services.eSearch
        .searchEntry(searchParams, pager)
        .execute(this.client)
        .then(
          (result) => result,
          (err) => {
            this.logger.error(err);
            return err;
          },
        );
    }

@shugli
Copy link

shugli commented Sep 30, 2021

Thanks @Belephor92 !

But are you still using the Typescript client lib? Because this looks more like the nodeJS implementation, or?

@shugli
Copy link

shugli commented Sep 30, 2021

Ok, solution proposed in tensorflow/tfjs#514 (comment) actually did the job!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants