@jupyterlite/server 0.6.0-alpha.6 → 0.6.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,14 @@
1
1
  import { ISignal } from '@lumino/signaling';
2
2
  import { IServiceWorkerManager } from './tokens';
3
+ /**
4
+ * A class that manages the ServiceWorker registration and communication,
5
+ * used for accessing the file system.
6
+ */
3
7
  export declare class ServiceWorkerManager implements IServiceWorkerManager {
4
- constructor(options?: IServiceWorkerManager.IOptions);
8
+ /**
9
+ * Construct a new ServiceWorkerManager.
10
+ */
11
+ constructor(options: IServiceWorkerManager.IOptions);
5
12
  /**
6
13
  * A signal emitted when the registration changes.
7
14
  */
@@ -10,12 +17,39 @@ export declare class ServiceWorkerManager implements IServiceWorkerManager {
10
17
  * Whether the ServiceWorker is enabled or not.
11
18
  */
12
19
  get enabled(): boolean;
20
+ /**
21
+ * A unique id to identify the browsing context where the ServiceWorkerManager was instantiated.
22
+ */
23
+ get browsingContextId(): string;
24
+ /**
25
+ * Whether the ServiceWorker is ready or not.
26
+ */
13
27
  get ready(): Promise<void>;
14
- private unregisterOldServiceWorkers;
15
- private initialize;
28
+ /**
29
+ * Initialize the ServiceWorkerManager.
30
+ */
31
+ private _initialize;
32
+ /**
33
+ * Unregister old service workers if the version has changed.
34
+ */
35
+ private _unregisterOldServiceWorkers;
36
+ /**
37
+ * Ping the service worker to keep it alive.
38
+ */
16
39
  private _pingServiceWorker;
40
+ /**
41
+ * Set the registration and emit a signal.
42
+ */
17
43
  private _setRegistration;
44
+ /**
45
+ * Handle a message received on the BroadcastChannel
46
+ */
47
+ private _onBroadcastMessage;
18
48
  private _registration;
19
49
  private _registrationChanged;
20
50
  private _ready;
51
+ private _broadcastChannel;
52
+ private _browsingContextId;
53
+ private _contents;
54
+ private _driveContentsProcessor;
21
55
  }
@@ -1,42 +1,57 @@
1
- import { PromiseDelegate } from '@lumino/coreutils';
2
- import { Signal } from '@lumino/signaling';
3
1
  import { PageConfig, URLExt } from '@jupyterlab/coreutils';
2
+ import { DRIVE_API_PATH, DriveContentsProcessor, } from '@jupyterlite/contents';
3
+ import { PromiseDelegate, UUID } from '@lumino/coreutils';
4
+ import { Signal } from '@lumino/signaling';
4
5
  import { WORKER_NAME } from './tokens';
6
+ /**
7
+ * The version of the app
8
+ */
5
9
  const VERSION = PageConfig.getOption('appVersion');
10
+ /**
11
+ * Used to keep the service worker alive
12
+ */
6
13
  const SW_PING_ENDPOINT = '/api/service-worker-heartbeat';
14
+ /**
15
+ * A class that manages the ServiceWorker registration and communication,
16
+ * used for accessing the file system.
17
+ */
7
18
  export class ServiceWorkerManager {
19
+ /**
20
+ * Construct a new ServiceWorkerManager.
21
+ */
8
22
  constructor(options) {
9
23
  var _a;
10
- this.unregisterOldServiceWorkers = async (scriptURL) => {
11
- const versionKey = `${scriptURL}-version`;
12
- // Check if we have an installed version. If we do, compare it to the current version
13
- // and unregister all service workers if they are different.
14
- const installedVersion = localStorage.getItem(versionKey);
15
- if ((installedVersion && installedVersion !== VERSION) || !installedVersion) {
16
- // eslint-disable-next-line no-console
17
- console.info('New version, unregistering existing service workers.');
18
- const registrations = await navigator.serviceWorker.getRegistrations();
19
- await Promise.all(registrations.map((registration) => registration.unregister()));
20
- // eslint-disable-next-line no-console
21
- console.info('All existing service workers have been unregistered.');
24
+ /**
25
+ * Handle a message received on the BroadcastChannel
26
+ */
27
+ this._onBroadcastMessage = async (event) => {
28
+ if (!this._broadcastChannel || !this._driveContentsProcessor) {
29
+ return;
22
30
  }
23
- localStorage.setItem(versionKey, VERSION);
24
- };
25
- this._pingServiceWorker = async () => {
26
- const response = await fetch(SW_PING_ENDPOINT);
27
- const text = await response.text();
28
- if (text === 'ok') {
29
- setTimeout(this._pingServiceWorker, 20000);
31
+ const { data, browsingContextId } = event.data;
32
+ if (browsingContextId !== this._browsingContextId) {
33
+ // Message is not meant for us
34
+ return;
30
35
  }
36
+ const response = await this._driveContentsProcessor.processDriveRequest(data);
37
+ this._broadcastChannel.postMessage(response);
31
38
  };
32
39
  this._registration = null;
33
40
  this._registrationChanged = new Signal(this);
34
41
  this._ready = new PromiseDelegate();
35
- const workerUrl = (_a = options === null || options === void 0 ? void 0 : options.workerUrl) !== null && _a !== void 0 ? _a : URLExt.join(PageConfig.getBaseUrl(), WORKER_NAME);
42
+ const workerUrl = (_a = options.workerUrl) !== null && _a !== void 0 ? _a : URLExt.join(PageConfig.getBaseUrl(), WORKER_NAME);
36
43
  const fullWorkerUrl = new URL(workerUrl, window.location.href);
37
44
  const enableCache = PageConfig.getOption('enableServiceWorkerCache') || 'false';
38
45
  fullWorkerUrl.searchParams.set('enableCache', enableCache);
39
- void this.initialize(fullWorkerUrl.href).catch(console.warn);
46
+ // Initialize broadcast channel related properties
47
+ this._browsingContextId = UUID.uuid4();
48
+ this._contents = options.contents;
49
+ this._broadcastChannel = new BroadcastChannel(DRIVE_API_PATH);
50
+ this._broadcastChannel.addEventListener('message', this._onBroadcastMessage);
51
+ this._driveContentsProcessor = new DriveContentsProcessor({
52
+ contentsManager: this._contents,
53
+ });
54
+ void this._initialize(fullWorkerUrl.href).catch(console.warn);
40
55
  }
41
56
  /**
42
57
  * A signal emitted when the registration changes.
@@ -50,18 +65,31 @@ export class ServiceWorkerManager {
50
65
  get enabled() {
51
66
  return this._registration !== null;
52
67
  }
68
+ /**
69
+ * A unique id to identify the browsing context where the ServiceWorkerManager was instantiated.
70
+ */
71
+ get browsingContextId() {
72
+ return this._browsingContextId;
73
+ }
74
+ /**
75
+ * Whether the ServiceWorker is ready or not.
76
+ */
53
77
  get ready() {
54
78
  return this._ready.promise;
55
79
  }
56
- async initialize(workerUrl) {
80
+ /**
81
+ * Initialize the ServiceWorkerManager.
82
+ */
83
+ async _initialize(workerUrl) {
57
84
  const { serviceWorker } = navigator;
58
85
  let registration = null;
59
86
  if (!serviceWorker) {
60
87
  console.warn('ServiceWorkers not supported in this browser');
88
+ return;
61
89
  }
62
90
  else if (serviceWorker.controller) {
63
91
  const scriptURL = serviceWorker.controller.scriptURL;
64
- await this.unregisterOldServiceWorkers(scriptURL);
92
+ await this._unregisterOldServiceWorkers(scriptURL);
65
93
  registration = (await serviceWorker.getRegistration(scriptURL)) || null;
66
94
  // eslint-disable-next-line no-console
67
95
  console.info('JupyterLite ServiceWorker was already registered');
@@ -88,6 +116,37 @@ export class ServiceWorkerManager {
88
116
  setTimeout(this._pingServiceWorker, 20000);
89
117
  }
90
118
  }
119
+ /**
120
+ * Unregister old service workers if the version has changed.
121
+ */
122
+ async _unregisterOldServiceWorkers(scriptURL) {
123
+ const versionKey = `${scriptURL}-version`;
124
+ // Check if we have an installed version. If we do, compare it to the current version
125
+ // and unregister all service workers if they are different.
126
+ const installedVersion = localStorage.getItem(versionKey);
127
+ if ((installedVersion && installedVersion !== VERSION) || !installedVersion) {
128
+ // eslint-disable-next-line no-console
129
+ console.info('New version, unregistering existing service workers.');
130
+ const registrations = await navigator.serviceWorker.getRegistrations();
131
+ await Promise.all(registrations.map((registration) => registration.unregister()));
132
+ // eslint-disable-next-line no-console
133
+ console.info('All existing service workers have been unregistered.');
134
+ }
135
+ localStorage.setItem(versionKey, VERSION);
136
+ }
137
+ /**
138
+ * Ping the service worker to keep it alive.
139
+ */
140
+ async _pingServiceWorker() {
141
+ const response = await fetch(SW_PING_ENDPOINT);
142
+ const text = await response.text();
143
+ if (text === 'ok') {
144
+ setTimeout(this._pingServiceWorker, 20000);
145
+ }
146
+ }
147
+ /**
148
+ * Set the registration and emit a signal.
149
+ */
91
150
  _setRegistration(registration) {
92
151
  this._registration = registration;
93
152
  this._registrationChanged.emit(this._registration);
@@ -1 +1 @@
1
- {"version":3,"file":"service-worker-manager.js","sourceRoot":"","sources":["../src/service-worker-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAW,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,UAAU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AAS,UAAU,CAAC;QAC1C,qFAAqF;QACrF,4DAA4D;QAC5D,MAAM,gBAAgB,GAAG,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAE1D,IAAI,CAAC,gBAAgB,IAAI,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE;YAC3E,sCAAsC;YACtC,OAAO,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC;YACrE,MAAM,aAAa,GAAG,MAAM,SAAS,CAAC,aAAa,CAAC,gBAAgB,EAAE,CAAC;YAEvE,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;YAElF,sCAAsC;YACtC,OAAO,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC;SACtE;QAED,YAAY,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,kBAAkB;QAC9B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAC/C,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,UAAU,CAAC,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;SAC5C;IACH,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,YAA8C;QACrE,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACrD,CAAC;CAmCF"}
@@ -118,10 +118,6 @@ async function broadcastOne(request) {
118
118
  };
119
119
  });
120
120
  const message = await request.json();
121
- // Mark message as being for broadcast.ts
122
- // This makes sure we won't get problems with messages
123
- // across tabs with multiple notebook tabs open
124
- message.receiver = 'broadcast.ts';
125
121
  broadcast.postMessage(message);
126
122
  return await promise;
127
123
  }
@@ -1 +1 @@
1
- {"version":3,"file":"service-worker.js","sourceRoot":"","sources":["../src/service-worker.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,8EAA8E;AAE9E;;GAEG;AACH,MAAM,KAAK,GAAG,UAAU,CAAC;AAEzB;;GAEG;AACH,MAAM,SAAS,GAAG,IAAI,gBAAgB,CAAC,eAAe,CAAC,CAAC;AAExD;;GAEG;AACH,IAAI,WAAW,GAAG,KAAK,CAAC;AAExB;;GAEG;AACH,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAC5C,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AAC9C,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAExC,iBAAiB;AAEjB;;GAEG;AACH,SAAS,SAAS,CAAC,KAAsB;IACvC,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;IACxB,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC9B,CAAC;AAED;;GAEG;AACH,SAAS,UAAU,CAAC,KAAsB;IACxC,sCAAsC;IACtC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC;IACzD,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,KAAK,MAAM,CAAC;IACzD,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;AACxC,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,OAAO,CAAC,KAAiB;IACtC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAE1B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACvC,IAAI,GAAG,CAAC,QAAQ,KAAK,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,SAAS,GAAG,CAAC,KAAK,EAAE,EAAE;YAC9B,OAAO,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpD,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;IACrC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAE/B,OAAO,MAAM,OAAO,CAAC;AACvB,CAAC;AAED,KAAK,UAAU,SAAS;IACtB,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,WAAW,CAAC,OAAgB,EAAE,QAAkB;IAC7D,MAAM,KAAK,GAAG,MAAM,SAAS,EAAE,CAAC;IAChC,OAAO,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,QAAQ;IACrB,MAAM,KAAK,GAAG,MAAM,SAAS,EAAE,CAAC;IAChC,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAChC,CAAC"}
package/lib/tokens.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Token } from '@lumino/coreutils';
2
2
  import { ISignal } from '@lumino/signaling';
3
+ import { Contents } from '@jupyterlab/services';
3
4
  /**
4
5
  * The token for the ServiceWorker.
5
6
  */
@@ -16,6 +17,10 @@ export interface IServiceWorkerManager {
16
17
  * Whether the ServiceWorker is enabled or not.
17
18
  */
18
19
  readonly enabled: boolean;
20
+ /**
21
+ * A unique id to identify the browsing context where the ServiceWorkerManager was instantiated.
22
+ */
23
+ readonly browsingContextId: string;
19
24
  /**
20
25
  * A Promise that resolves when the ServiceWorker is registered, or rejects if it cannot
21
26
  */
@@ -29,6 +34,10 @@ export declare namespace IServiceWorkerManager {
29
34
  * An options object for initializing a worker manager.
30
35
  */
31
36
  interface IOptions {
37
+ /**
38
+ * The contents manager to use for handling drive contents requests
39
+ */
40
+ contents: Contents.IManager;
32
41
  /**
33
42
  * URL to load the worker file. Default to "{baseURL}/service-worker.js"
34
43
  */
package/lib/tokens.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI1C,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,KAAK,CAC5C,2CAA2C,CAC5C,CAAC;AAwCF,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAM1C,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,KAAK,CAC5C,2CAA2C,CAC5C,CAAC;AAkDF,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlite/server",
3
- "version": "0.6.0-alpha.6",
3
+ "version": "0.6.0-alpha.8",
4
4
  "description": "JupyterLite - Server",
5
5
  "homepage": "https://github.com/jupyterlite/jupyterlite",
6
6
  "bugs": {
@@ -43,26 +43,26 @@
43
43
  "watch": "tsc -b --watch"
44
44
  },
45
45
  "dependencies": {
46
- "@jupyterlab/coreutils": "~6.4.0-rc.0",
47
- "@jupyterlab/nbformat": "~4.4.0-rc.0",
48
- "@jupyterlab/observables": "~5.4.0-rc.0",
49
- "@jupyterlab/services": "~7.4.0-rc.0",
50
- "@jupyterlab/settingregistry": "~4.4.0-rc.0",
51
- "@jupyterlab/statedb": "~4.4.0-rc.0",
52
- "@jupyterlite/contents": "^0.6.0-alpha.6",
53
- "@jupyterlite/kernel": "^0.6.0-alpha.6",
54
- "@jupyterlite/session": "^0.6.0-alpha.6",
55
- "@jupyterlite/settings": "^0.6.0-alpha.6",
56
- "@jupyterlite/translation": "^0.6.0-alpha.6",
57
- "@lumino/application": "^2.4.2",
58
- "@lumino/coreutils": "^2.2.0",
59
- "@lumino/signaling": "^2.1.3",
46
+ "@jupyterlab/coreutils": "~6.4.0",
47
+ "@jupyterlab/nbformat": "~4.4.0",
48
+ "@jupyterlab/observables": "~5.4.0",
49
+ "@jupyterlab/services": "~7.4.0",
50
+ "@jupyterlab/settingregistry": "~4.4.0",
51
+ "@jupyterlab/statedb": "~4.4.0",
52
+ "@jupyterlite/contents": "^0.6.0-alpha.8",
53
+ "@jupyterlite/kernel": "^0.6.0-alpha.8",
54
+ "@jupyterlite/session": "^0.6.0-alpha.8",
55
+ "@jupyterlite/settings": "^0.6.0-alpha.8",
56
+ "@jupyterlite/translation": "^0.6.0-alpha.8",
57
+ "@lumino/application": "^2.4.3",
58
+ "@lumino/coreutils": "^2.2.1",
59
+ "@lumino/signaling": "^2.1.4",
60
60
  "mock-socket": "^9.3.1"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@babel/core": "^7.11.6",
64
64
  "@babel/preset-env": "^7.12.1",
65
- "@jupyterlab/testutils": "~4.4.0-rc.0",
65
+ "@jupyterlab/testutils": "~4.4.0",
66
66
  "@types/jest": "^29.5.3",
67
67
  "@types/serviceworker": "^0.0.56",
68
68
  "jest": "^29.6.2",
@@ -1,20 +1,56 @@
1
- import { PromiseDelegate } from '@lumino/coreutils';
2
- import { ISignal, Signal } from '@lumino/signaling';
3
-
4
1
  import { PageConfig, URLExt } from '@jupyterlab/coreutils';
5
2
 
3
+ import { Contents } from '@jupyterlab/services';
4
+
5
+ import {
6
+ DRIVE_API_PATH,
7
+ DriveContentsProcessor,
8
+ TDriveMethod,
9
+ TDriveRequest,
10
+ } from '@jupyterlite/contents';
11
+
12
+ import { PromiseDelegate, UUID } from '@lumino/coreutils';
13
+
14
+ import { ISignal, Signal } from '@lumino/signaling';
15
+
6
16
  import { IServiceWorkerManager, WORKER_NAME } from './tokens';
7
17
 
18
+ /**
19
+ * The version of the app
20
+ */
8
21
  const VERSION = PageConfig.getOption('appVersion');
22
+
23
+ /**
24
+ * Used to keep the service worker alive
25
+ */
9
26
  const SW_PING_ENDPOINT = '/api/service-worker-heartbeat';
27
+
28
+ /**
29
+ * A class that manages the ServiceWorker registration and communication,
30
+ * used for accessing the file system.
31
+ */
10
32
  export class ServiceWorkerManager implements IServiceWorkerManager {
11
- constructor(options?: IServiceWorkerManager.IOptions) {
33
+ /**
34
+ * Construct a new ServiceWorkerManager.
35
+ */
36
+ constructor(options: IServiceWorkerManager.IOptions) {
12
37
  const workerUrl =
13
- options?.workerUrl ?? URLExt.join(PageConfig.getBaseUrl(), WORKER_NAME);
38
+ options.workerUrl ?? URLExt.join(PageConfig.getBaseUrl(), WORKER_NAME);
14
39
  const fullWorkerUrl = new URL(workerUrl, window.location.href);
15
40
  const enableCache = PageConfig.getOption('enableServiceWorkerCache') || 'false';
16
41
  fullWorkerUrl.searchParams.set('enableCache', enableCache);
17
- void this.initialize(fullWorkerUrl.href).catch(console.warn);
42
+
43
+ // Initialize broadcast channel related properties
44
+ this._browsingContextId = UUID.uuid4();
45
+ this._contents = options.contents;
46
+ this._broadcastChannel = new BroadcastChannel(DRIVE_API_PATH);
47
+ this._broadcastChannel.addEventListener('message', this._onBroadcastMessage);
48
+
49
+ this._driveContentsProcessor = new DriveContentsProcessor({
50
+ contentsManager: this._contents,
51
+ });
52
+
53
+ void this._initialize(fullWorkerUrl.href).catch(console.warn);
18
54
  }
19
55
 
20
56
  /**
@@ -34,40 +70,34 @@ export class ServiceWorkerManager implements IServiceWorkerManager {
34
70
  return this._registration !== null;
35
71
  }
36
72
 
73
+ /**
74
+ * A unique id to identify the browsing context where the ServiceWorkerManager was instantiated.
75
+ */
76
+ get browsingContextId(): string {
77
+ return this._browsingContextId;
78
+ }
79
+
80
+ /**
81
+ * Whether the ServiceWorker is ready or not.
82
+ */
37
83
  get ready(): Promise<void> {
38
84
  return this._ready.promise;
39
85
  }
40
86
 
41
- private unregisterOldServiceWorkers = async (scriptURL: string) => {
42
- const versionKey = `${scriptURL}-version`;
43
- // Check if we have an installed version. If we do, compare it to the current version
44
- // and unregister all service workers if they are different.
45
- const installedVersion = localStorage.getItem(versionKey);
46
-
47
- if ((installedVersion && installedVersion !== VERSION) || !installedVersion) {
48
- // eslint-disable-next-line no-console
49
- console.info('New version, unregistering existing service workers.');
50
- const registrations = await navigator.serviceWorker.getRegistrations();
51
-
52
- await Promise.all(registrations.map((registration) => registration.unregister()));
53
-
54
- // eslint-disable-next-line no-console
55
- console.info('All existing service workers have been unregistered.');
56
- }
57
-
58
- localStorage.setItem(versionKey, VERSION);
59
- };
60
-
61
- private async initialize(workerUrl: string): Promise<void> {
87
+ /**
88
+ * Initialize the ServiceWorkerManager.
89
+ */
90
+ private async _initialize(workerUrl: string): Promise<void> {
62
91
  const { serviceWorker } = navigator;
63
92
 
64
93
  let registration: ServiceWorkerRegistration | null = null;
65
94
 
66
95
  if (!serviceWorker) {
67
96
  console.warn('ServiceWorkers not supported in this browser');
97
+ return;
68
98
  } else if (serviceWorker.controller) {
69
99
  const scriptURL = serviceWorker.controller.scriptURL;
70
- await this.unregisterOldServiceWorkers(scriptURL);
100
+ await this._unregisterOldServiceWorkers(scriptURL);
71
101
 
72
102
  registration = (await serviceWorker.getRegistration(scriptURL)) || null;
73
103
  // eslint-disable-next-line no-console
@@ -98,21 +128,80 @@ export class ServiceWorkerManager implements IServiceWorkerManager {
98
128
  setTimeout(this._pingServiceWorker, 20000);
99
129
  }
100
130
  }
101
- private _pingServiceWorker = async (): Promise<void> => {
131
+
132
+ /**
133
+ * Unregister old service workers if the version has changed.
134
+ */
135
+ private async _unregisterOldServiceWorkers(scriptURL: string): Promise<void> {
136
+ const versionKey = `${scriptURL}-version`;
137
+ // Check if we have an installed version. If we do, compare it to the current version
138
+ // and unregister all service workers if they are different.
139
+ const installedVersion = localStorage.getItem(versionKey);
140
+
141
+ if ((installedVersion && installedVersion !== VERSION) || !installedVersion) {
142
+ // eslint-disable-next-line no-console
143
+ console.info('New version, unregistering existing service workers.');
144
+ const registrations = await navigator.serviceWorker.getRegistrations();
145
+
146
+ await Promise.all(registrations.map((registration) => registration.unregister()));
147
+
148
+ // eslint-disable-next-line no-console
149
+ console.info('All existing service workers have been unregistered.');
150
+ }
151
+
152
+ localStorage.setItem(versionKey, VERSION);
153
+ }
154
+
155
+ /**
156
+ * Ping the service worker to keep it alive.
157
+ */
158
+ private async _pingServiceWorker(): Promise<void> {
102
159
  const response = await fetch(SW_PING_ENDPOINT);
103
160
  const text = await response.text();
104
161
  if (text === 'ok') {
105
162
  setTimeout(this._pingServiceWorker, 20000);
106
163
  }
107
- };
164
+ }
165
+
166
+ /**
167
+ * Set the registration and emit a signal.
168
+ */
108
169
  private _setRegistration(registration: ServiceWorkerRegistration | null) {
109
170
  this._registration = registration;
110
171
  this._registrationChanged.emit(this._registration);
111
172
  }
112
173
 
174
+ /**
175
+ * Handle a message received on the BroadcastChannel
176
+ */
177
+ private _onBroadcastMessage = async <T extends TDriveMethod>(
178
+ event: MessageEvent<{
179
+ data: TDriveRequest<T>;
180
+ browsingContextId: string;
181
+ }>,
182
+ ): Promise<void> => {
183
+ if (!this._broadcastChannel || !this._driveContentsProcessor) {
184
+ return;
185
+ }
186
+
187
+ const { data, browsingContextId } = event.data;
188
+
189
+ if (browsingContextId !== this._browsingContextId) {
190
+ // Message is not meant for us
191
+ return;
192
+ }
193
+
194
+ const response = await this._driveContentsProcessor.processDriveRequest(data);
195
+ this._broadcastChannel.postMessage(response);
196
+ };
197
+
113
198
  private _registration: ServiceWorkerRegistration | null = null;
114
199
  private _registrationChanged = new Signal<this, ServiceWorkerRegistration | null>(
115
200
  this,
116
201
  );
117
202
  private _ready = new PromiseDelegate<void>();
203
+ private _broadcastChannel: BroadcastChannel;
204
+ private _browsingContextId: string;
205
+ private _contents: Contents.IManager | undefined;
206
+ private _driveContentsProcessor: DriveContentsProcessor | undefined;
118
207
  }
@@ -142,10 +142,6 @@ async function broadcastOne(request: Request): Promise<Response> {
142
142
  });
143
143
 
144
144
  const message = await request.json();
145
- // Mark message as being for broadcast.ts
146
- // This makes sure we won't get problems with messages
147
- // across tabs with multiple notebook tabs open
148
- message.receiver = 'broadcast.ts';
149
145
  broadcast.postMessage(message);
150
146
 
151
147
  return await promise;
package/src/tokens.ts CHANGED
@@ -2,6 +2,8 @@ import { Token } from '@lumino/coreutils';
2
2
 
3
3
  import { ISignal } from '@lumino/signaling';
4
4
 
5
+ import { Contents } from '@jupyterlab/services';
6
+
5
7
  import SW_URL from './service-worker?text';
6
8
 
7
9
  /**
@@ -28,6 +30,11 @@ export interface IServiceWorkerManager {
28
30
  */
29
31
  readonly enabled: boolean;
30
32
 
33
+ /**
34
+ * A unique id to identify the browsing context where the ServiceWorkerManager was instantiated.
35
+ */
36
+ readonly browsingContextId: string;
37
+
31
38
  /**
32
39
  * A Promise that resolves when the ServiceWorker is registered, or rejects if it cannot
33
40
  */
@@ -42,6 +49,11 @@ export namespace IServiceWorkerManager {
42
49
  * An options object for initializing a worker manager.
43
50
  */
44
51
  export interface IOptions {
52
+ /**
53
+ * The contents manager to use for handling drive contents requests
54
+ */
55
+ contents: Contents.IManager;
56
+
45
57
  /**
46
58
  * URL to load the worker file. Default to "{baseURL}/service-worker.js"
47
59
  */