adaptlearning / adapt-contrib-xapi

TinCan/xAPI extension for the Adapt Framework
GNU General Public License v3.0
12 stars 28 forks source link

xAPI Bookmarking should be possible #48

Closed EBusch closed 5 years ago

EBusch commented 5 years ago

When initializing, users should be asked if they would like to resume

moloko commented 5 years ago

@EBusch just to check: have you tried the bookmarking plugin in combination with this extension? I haven’t tried it myself but the bookmarking plugin is written in a way that should be tracking-system agnostic so should work with the xAPI extension providing it sets the location property in Adapt.offlineStorage correctly...

EBusch commented 5 years ago

@moloko perhaps I have something misconfigured but for this to work for me I had to make a couple changes:

       getLocation: function()
    {
      if (!this.get('isInitialised')) {
          return null;
      }

      var activityId = this.get('activityId');
      var actor = this.get('actor');

      var location = this.xapiWrapper.getState(activityId, actor, "location", null, null, null);
      return location;
    },

    sendLocation: function(name, location) {
      if (!this.get('isInitialised')) {
          return;
      }

      var activityId = this.get('activityId');
      var actor = this.get('actor');
      this.xapiWrapper.sendState(activityId, actor, name, null, location, null, null, function(error, xhr) {
        if (error) {
          Adapt.trigger('xapi:lrs:sendState:error', error);
        }

        Adapt.trigger('xapi:lrs:sendState:success', location);
      });
    },

And then in the initializer:

    Adapt.on('adapt:initialize', function() {
      xapi.setupListeners();
      Adapt.offlineStorage.initialize({
          get: function(name) {
            if (name === "location")
            {
              return xapi.getLocation();
            }
              return null;
          },
          set: function(name, value) {
              if (name === "location")
              {
                xapi.sendLocation(name, value);
              }
          }
      });
    });
danielstorey commented 5 years ago

Hi @EBusch

Firstly, thanks so much for your willingness to contribute and provide solutions. I have tested adapt-contrib-xapi with the bookmarking extension and everything seems to be working without the need for any additional code.

Please check you have the latest version of adapt-contrib-xapi and that you have included adapt-contrib-bookmarking in the build and have configured it correctly in course.json as per the example here https://github.com/adaptlearning/adapt-contrib-bookmarking/blob/master/example.json

You should also consider that this PR is specific to one particular plugin. If there was an issue persisting offline storage between xapi sessions this would not provide a fix for other plugins which also rely on this functionality.

If you have any further questions or need assistance getting the bookmarking extension to work please head over to the Adapt Gitter chat rooms:

https://gitter.im/adaptlearning/xAPI https://gitter.im/adaptlearning/adapt_framework

Everyone there is very friendly and always happy to help! It might also be worth heading there for a chat to discuss possible issues/enhancements to the xAPI extension before creating issues and PRs on GitHub.