Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/* global importScripts */
2
var H5P = H5P || {};
3
importScripts('h5p-version.js', 'h5p-content-upgrade-process.js');
4
 
5
var libraryLoadedCallback;
6
 
7
/**
8
 * Register message handlers
9
 */
10
var messageHandlers = {
11
  newJob: function (job) {
12
    // Start new job
13
    new H5P.ContentUpgradeProcess(job.name, new H5P.Version(job.oldVersion), new H5P.Version(job.newVersion), job.params, job.id, function loadLibrary(name, version, next) {
14
      // TODO: Cache?
15
      postMessage({
16
        action: 'loadLibrary',
17
        name: name,
18
        version: version.toString()
19
      });
20
      libraryLoadedCallback = next;
21
    }, function done(err, result) {
22
      if (err) {
23
        // Return error
24
        postMessage({
25
          action: 'error',
26
          id: job.id,
27
          err: err.message ? err.message : err
28
        });
29
 
30
        return;
31
      }
32
 
33
      // Return upgraded content
34
      postMessage({
35
        action: 'done',
36
        id: job.id,
37
        params: result
38
      });
39
    });
40
  },
41
  libraryLoaded: function (data) {
42
    var library = data.library;
43
    if (library.upgradesScript) {
44
      try {
45
        importScripts(library.upgradesScript);
46
      }
47
      catch (err) {
48
        libraryLoadedCallback(err);
49
        return;
50
      }
51
    }
52
    libraryLoadedCallback(null, data.library);
53
  }
54
};
55
 
56
/**
57
 * Handle messages from our master
58
 */
59
onmessage = function (event) {
60
  if (event.data.action !== undefined && messageHandlers[event.data.action]) {
61
    messageHandlers[event.data.action].call(this, event.data);
62
  }
63
};