pxt-core 10.2.28 → 10.2.30

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.
package/built/pxt.js CHANGED
@@ -120608,28 +120608,27 @@ var pxt;
120608
120608
  };
120609
120609
  loop();
120610
120610
  }
120611
- recvPacketAsync() {
120612
- let final = (res) => {
120613
- if (res.status != "ok")
120614
- this.error("USB IN transfer failed");
120615
- let arr = new Uint8Array(res.data.buffer);
120616
- if (arr.length == 0)
120617
- return this.recvPacketAsync();
120618
- return arr;
120619
- };
120620
- if (!this.dev)
120621
- return Promise.reject(new Error("Disconnected"));
120622
- if (!this.epIn) {
120623
- return this.dev.controlTransferIn({
120611
+ async recvPacketAsync(timeoutMs) {
120612
+ const startTime = Date.now();
120613
+ while (!timeoutMs || Date.now() < startTime + timeoutMs) {
120614
+ if (!this.dev) {
120615
+ return Promise.reject(new Error("Disconnected"));
120616
+ }
120617
+ const res = await (this.epIn ? this.dev.transferIn(this.epIn.endpointNumber, 64) : this.dev.controlTransferIn({
120624
120618
  requestType: "class",
120625
120619
  recipient: "interface",
120626
120620
  request: controlTransferGetReport,
120627
120621
  value: controlTransferInReport,
120628
120622
  index: this.iface.interfaceNumber
120629
- }, 64).then(final);
120623
+ }, 64));
120624
+ if (res.status != "ok")
120625
+ this.error("USB IN transfer failed");
120626
+ let arr = new Uint8Array(res.data.buffer);
120627
+ if (arr.length != 0) {
120628
+ return arr;
120629
+ }
120630
120630
  }
120631
- return this.dev.transferIn(this.epIn.endpointNumber, 64)
120632
- .then(final);
120631
+ this.error("USB IN timed out");
120633
120632
  }
120634
120633
  initAsync() {
120635
120634
  if (!this.dev)
package/built/pxtlib.d.ts CHANGED
@@ -1959,7 +1959,7 @@ declare namespace pxt.packetio {
1959
1959
  }
1960
1960
  interface PacketIO {
1961
1961
  sendPacketAsync(pkt: Uint8Array): Promise<void>;
1962
- recvPacketAsync?: () => Promise<Uint8Array>;
1962
+ recvPacketAsync?: (timeout?: number) => Promise<Uint8Array>;
1963
1963
  onDeviceConnectionChanged: (connect: boolean) => void;
1964
1964
  onConnectionChanged: () => void;
1965
1965
  onData: (v: Uint8Array) => void;
package/built/pxtlib.js CHANGED
@@ -22922,28 +22922,27 @@ var pxt;
22922
22922
  };
22923
22923
  loop();
22924
22924
  }
22925
- recvPacketAsync() {
22926
- let final = (res) => {
22927
- if (res.status != "ok")
22928
- this.error("USB IN transfer failed");
22929
- let arr = new Uint8Array(res.data.buffer);
22930
- if (arr.length == 0)
22931
- return this.recvPacketAsync();
22932
- return arr;
22933
- };
22934
- if (!this.dev)
22935
- return Promise.reject(new Error("Disconnected"));
22936
- if (!this.epIn) {
22937
- return this.dev.controlTransferIn({
22925
+ async recvPacketAsync(timeoutMs) {
22926
+ const startTime = Date.now();
22927
+ while (!timeoutMs || Date.now() < startTime + timeoutMs) {
22928
+ if (!this.dev) {
22929
+ return Promise.reject(new Error("Disconnected"));
22930
+ }
22931
+ const res = await (this.epIn ? this.dev.transferIn(this.epIn.endpointNumber, 64) : this.dev.controlTransferIn({
22938
22932
  requestType: "class",
22939
22933
  recipient: "interface",
22940
22934
  request: controlTransferGetReport,
22941
22935
  value: controlTransferInReport,
22942
22936
  index: this.iface.interfaceNumber
22943
- }, 64).then(final);
22937
+ }, 64));
22938
+ if (res.status != "ok")
22939
+ this.error("USB IN transfer failed");
22940
+ let arr = new Uint8Array(res.data.buffer);
22941
+ if (arr.length != 0) {
22942
+ return arr;
22943
+ }
22944
22944
  }
22945
- return this.dev.transferIn(this.epIn.endpointNumber, 64)
22946
- .then(final);
22945
+ this.error("USB IN timed out");
22947
22946
  }
22948
22947
  initAsync() {
22949
22948
  if (!this.dev)
@@ -71,6 +71,7 @@ export declare class EditorDriver extends IframeDriver {
71
71
  addEventListener(event: "workspacediagnostics", handler: (ev: pxt.editor.EditorWorkspaceDiagnostics) => void): void;
72
72
  addEventListener(event: "editorcontentloaded", handler: (ev: pxt.editor.EditorContentLoadedRequest) => void): void;
73
73
  addEventListener(event: "projectcloudstatus", handler: (ev: pxt.editor.EditorMessageProjectCloudStatus) => void): void;
74
+ addEventListener(event: "serviceworkerregistered", handler: (ev: pxt.editor.EditorMessageServiceWorkerRegisteredRequest) => void): void;
74
75
  sendMessage(message: pxt.editor.EditorMessageRequest): Promise<pxt.editor.EditorMessageResponse>;
75
76
  protected handleMessage(event: MessageEvent): void;
76
77
  protected handleWorkspaceSync(event: pxt.editor.EditorWorkspaceSyncRequest | pxt.editor.EditorWorkspaceSaveRequest): Promise<void>;