Skip to content

Commit

Permalink
Progress Head
Browse files Browse the repository at this point in the history
Progress Data
Progress Path
Progress Paramaters
onDataSync
  • Loading branch information
tomekmarchi committed Oct 6, 2023
1 parent 1f9a884 commit db5300c
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 61 deletions.
60 changes: 51 additions & 9 deletions udsp/request/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { on } from './on.js';
import { flushOutgoing, flushIncoming, flush } from './flush.js';
import { onPacket } from './onPacket.js';
import {
isBuffer,
isPlainObject,
isString,
promise,
assign,
objectSize, eachArray, jsonParse,
construct, isArray, clear, isFalse,
isTrue, clearBuffer, hasValue
isBuffer, isPlainObject, isString, promise,
assign, objectSize, eachArray, jsonParse, construct,
isArray, clear, isFalse, isTrue, clearBuffer, hasValue, calcProgress
} from '@universalweb/acid';
import { encode, decode } from 'msgpackr';
import { toBase64 } from '#crypto';
import { onDataSync, callOnDataSyncEvent } from './onDataSync.js';
import { onData } from './onData.js';
import { onPath } from './onPath.js';
import { onHead } from './onHead.js';
import { onParameters } from './onParameters.js';
/**
* @todo Adjust packet size to account for other packet data.
*/
Expand Down Expand Up @@ -518,6 +518,48 @@ export class Base {
flushIncoming = flushIncoming;
flush = flush;
on = on;
onDataSync = onDataSync;
callOnDataSyncEvent = callOnDataSyncEvent;
onData = onData;
onPath = onPath;
onParameters = onParameters;
onHead = onHead;
onDataProgress() {
if (this.totalIncomingDataSize) {
if (this.currentIncomingDataSize > 0) {
this.incomingDataProgress = calcProgress(this.totalIncomingDataSize, this.currentIncomingDataSize);
}
console.log(`DATA PROGRESS current:${this.currentIncomingDataSize}`, this.totalIncomingDataSize);
console.log('Incoming Progress', this.incomingDataProgress);
}
}
onHeadProgress() {
if (this.totalIncomingHeadSize) {
if (this.currentIncomingHeadSize > 0) {
this.incomingHeadProgress = calcProgress(this.currentIncomingHeadSize, this.currentIncomingHeadSize);
}
console.log(`Head PROGRESS current:${this.currentIncomingHeadSize}`, this.currentIncomingHeadSize);
console.log('Incoming Progress', this.incomingHeadProgress);
}
}
onPathProgress() {
if (this.totalIncomingPathSize) {
if (this.currentIncomingPathSize > 0) {
this.incomingPathProgress = calcProgress(this.currentIncomingPathSize, this.currentIncomingPathSize);
}
console.log(`Path PROGRESS current:${this.currentIncomingPathSize}`, this.currentIncomingPathSize);
console.log('Incoming Progress', this.incomingPathProgress);
}
}
onParamatersProgress() {
if (this.totalIncomingParamatersSize) {
if (this.currentIncomingParamatersSize > 0) {
this.incomingParamatersProgress = calcProgress(this.currentIncomingParamatersSize, this.currentIncomingParamatersSize);
}
console.log(`Paramaters PROGRESS current:${this.currentIncomingParamatersSize}`, this.currentIncomingParamatersSize);
console.log('Incoming Progress', this.incomingParamatersProgress);
}
}
outgoingHead;
outgoingData;
incomingHeadState = false;
Expand All @@ -527,7 +569,7 @@ export class Base {
currentIncomingParametersSize = 0;
currentIncomingPathSize = 0;
totalReceivedUniquePackets = 0;
progress = 0;
calcProgress = 0;
progressHead = 0;
progressData = 0;
dataOrdered = [];
Expand Down
7 changes: 0 additions & 7 deletions udsp/request/onData.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { progress } from '@universalweb/acid';
export async function onData(message) {
console.log('On Data event');
if (this.totalIncomingDataSize) {
if (this.currentIncomingDataSize > 0) {
this.incomingProgress = progress(this.totalIncomingDataSize, this.currentIncomingDataSize);
}
console.log('Incoming Progress', this.incomingProgress);
}
if (this.events.data) {
this.events.data(message.data, message.packetId);
}
Expand Down
26 changes: 17 additions & 9 deletions udsp/request/onDataSync.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
function callOnDataSyncEvent() {
if (this.events.dataSync) {
this.events.dataSync(message.data, message.packetId);
}
export async function callOnDataSyncEvent(message) {
console.log('callOnDataSyncEvent', message.packetId);
this.events.dataSync(message.data, message.packetId);
}
export function onDataSync(message) {
if (message.packetId === this.onDataCurrentId) {

while (this.) {

export async function onDataSync(message) {
const source = this;
if (source.events.dataSync) {
const { packetId } = message;
const { incomingDataPackets } = this;
if (packetId === this.onDataCurrentId) {
await source.callOnDataSyncEvent(message);
const nextId = this.onDataCurrentId++;
let currentMessage = source.incomingDataPackets[this.onDataCurrentId];
while (currentMessage) {
await source.callOnDataSyncEvent(currentMessage);
this.onDataCurrentId++;
currentMessage = source.incomingDataPackets[this.onDataCurrentId];
}
}
}
}
7 changes: 0 additions & 7 deletions udsp/request/onHead.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { progress } from '@universalweb/acid';
export async function onHead(message) {
console.log('On Head event');
if (this.totalIncomingHeadSize) {
if (this.currentIncomingHeadSize > 0) {
this.incomingProgress = progress(this.totalIncomingHeadSize, this.currentIncomingHeadSize);
}
console.log('Incoming Progress', this.incomingProgress);
}
if (this.events.head) {
this.events.head(message.head, message.packetId);
}
Expand Down
18 changes: 9 additions & 9 deletions udsp/request/onPacket.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export async function onPacket(packet) {
if (this.missingHeadPackets.has(packetId)) {
this.missingHeadPackets.delete(packetId);
}
this.onHeadProgress();
if (this.onHead) {
await this.onHead(message);
}
Expand All @@ -71,6 +72,7 @@ export async function onPacket(packet) {
if (this.missingPathPackets.has(packetId)) {
this.missingPathPackets.delete(packetId);
}
this.onPathProgress();
if (this.onPath) {
await this.onPath(message);
}
Expand All @@ -88,10 +90,8 @@ export async function onPacket(packet) {
if (this.missingParametersPackets.has(packetId)) {
this.missingParametersPackets.delete(packetId);
}
if (this.onParameters) {
await this.onParameters(message);
}
console.log(this, this.currentIncomingParametersSize);
this.onParametersProgress();
await this.onParameters(message);
if (this.totalIncomingParametersSize === this.currentIncomingParametersSize) {
this.assembleParameters();
}
Expand All @@ -109,14 +109,14 @@ export async function onPacket(packet) {
if (this.missingDataPackets.has(packetId)) {
this.missingDataPackets.delete(packetId);
}
if (this.onData) {
await this.onData(message);
}
console.log(`DATA PROGRESS current:${this.currentIncomingDataSize}`, this.totalIncomingDataSize);
if (this.currentIncomingDataSize === this.totalIncomingDataSize) {
console.log('Last packet received', this.currentIncomingDataSize, this.totalIncomingDataSize);
message.last = true;
this.totalIncomingUniqueDataPackets = packetId;
}
this.onDataProgress();
this.onData(message);
this.onDataSync(message);
if (message.last) {
this.checkData();
}
}
Expand Down
6 changes: 6 additions & 0 deletions udsp/request/onParameters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export async function onParameters(message) {
console.log('On Params event');
if (this.events.params) {
this.events.params(message.params, message.pid);
}
}
13 changes: 0 additions & 13 deletions udsp/request/onParams.js

This file was deleted.

7 changes: 0 additions & 7 deletions udsp/request/onPath.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { progress } from '@universalweb/acid';
export async function onPath(message) {
console.log('On Path event');
if (this.totalIncomingPathSize) {
if (this.currentIncomingPathSize > 0) {
this.incomingProgress = progress(this.totalIncomingPathSize, this.currentIncomingPathSize);
}
console.log('Incoming Progress', this.incomingProgress);
}
if (this.events.path) {
this.events.path(message.path, message.pid);
}
Expand Down

0 comments on commit db5300c

Please sign in to comment.