Trouble running demo

I’m attempting to run the session.start demo / tutorial and I’m getting a javascript error. Chrome is telling me that ‘KalturaSessionService.start’ is not a function.

All help would be appreciated!

Here’s the entire piece of code I’m running:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<script src="/js/kaltura/KalturaClientBase.js"></script>
<script src="/js/kaltura/KalturaClient.js"></script>
<script src="/js/kaltura/KalturaVO.js"></script>
<script src="/js/kaltura/KalturaTypes.js"></script>
<script src="/js/kaltura/KalturaServices.js"></script>

<script>
  var config = new KalturaConfiguration();
  config.serviceUrl = 'https://www.kaltura.com';
  var client = new KalturaClient(config);
  KalturaSessionService.start(
        "secret goes here",
        "userid",
        2,
        partnerid)
  .execute(client, function(success, ks) {
    if (!success || (ks.code && ks.message)) {
      console.log('Error starting session', success, ks);
    } else {
      console.log('Kaltura Result success', success);
      client.setKs(ks);
    }
  });
</script>

Hi @garberfc,

I don’t see where in your code you’ve included the needed JS files from the AJAX client lib.
Please see the code sample in this thread for references:

Notice, however, that using the JS client to generate a session is not recommended, for the obvious reason that the admin secret will be available to anyone viewing the page source.

Thanks,

Sorry, there was some HTML markup that was causing my tags to be hidden. I’ve edited the original posting.

It appears the Tutorial/Console AIP is out of date with the version of the libraries I downloaded today. The version is 3.3.0.

Here’s some working code for the next person who stumbles into this issue:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="/js/kaltura/webtoolkit.md5.js"></script>
<script src="/js/kaltura/ox.ajast.js"></script>
<script src="/js/kaltura/KalturaClientBase.js"></script>
<script src="/js/kaltura/KalturaTypes.js"></script>
<script src="/js/kaltura/KalturaVO.js"></script>
<script src="/js/kaltura/KalturaServices.js"></script>
<script src="/js/kaltura/KalturaClient.js"></script>

<script>
  var config = new KalturaConfiguration();
  config.serviceUrl = 'https://www.kaltura.com';
  var client = new KalturaClient(config);
  var kalturaSessionService = new KalturaSessionService(client);
  kalturaSessionService.start(function(success, ks) {
        if (!success || (ks.code && ks.message)) {
          console.log('Error starting session', success, ks);
        } else {
          client.setKs(ks);
          console.log("ks=" + ks);
        }},
        "SecretId",
        "UserId",
        2,
        PartnerId);

I found the API Docs here: http://www.kaltura.com/api_v3/testmeDoc/ I’m not sure why I don’t see the class KalturaSessionService in the docs… :frowning:

Hi @garberfc,

Looking at your code, it seems you are using an older version of the JS client. The entire client was redone recently.
I strongly recommend you use the latest, which can be obtained here:
http://cdnbakmi.kaltura.com/content/clientlibs/ajax_22-03-2017.tar.gz
You can always download the latest version from here:

All examples at developer.kaltura.com relate to the new client lib.
Here is a full code sample for generating a KS:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="KalturaFullClient.min.js"></script>

<script>
$( document ).ready(function() {
  var config = new KalturaConfiguration();
  config.serviceUrl = 'https://www.kaltura.com';
  var client = new KalturaClient(config);
  // Note: this is meant only as a sample.
  // You should NEVER generate sessions on the client,
  // as this exposes your Admin Secret to users.
  // Instead, generate a session on the server and pass the
  // KS to the client.
  KalturaSessionService.start(
        "ADMIN_SECRET",
        "USER_ID",
        2,
        PARTNER_ID)
  .execute(client, function(success, ks) {
    if (!success || (ks.code && ks.message)) {
      console.log('Error starting session', success, ks);
    } else {
      client.setKs(ks);
      console.log(ks);
    }
  });
});
</script>
</head>
</html>

Documentation for the session service and its different actions can be found here:

Thanks,