-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewritten the entire transfer manager s.t. it handles clips correctly
- Loading branch information
Balte de Wit
authored and
Alex Van Camp
committed
Sep 11, 2018
1 parent
683d83b
commit e3e69a1
Showing
11 changed files
with
375 additions
and
622 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Commands, Enums } from '..' | ||
|
||
import DataTransfer from './dataTransfer' | ||
|
||
export default class DataLock { | ||
storeId: number | ||
state: number | ||
transfer: DataTransfer | undefined | ||
queue: Array<DataTransfer> = [] | ||
|
||
commandQueue: Array<Commands.AbstractCommand> = [] | ||
|
||
constructor (storeId: number, commandQueue: Array<Commands.AbstractCommand>) { | ||
this.storeId = storeId | ||
this.commandQueue = commandQueue | ||
} | ||
|
||
enqueue (transfer: DataTransfer) { | ||
this.queue.push(transfer) | ||
this.dequeueAndRun() | ||
} | ||
|
||
dequeueAndRun () { | ||
if (this.transfer === undefined && this.queue.length > 0) { | ||
this.transfer = this.queue.shift() | ||
// obtain lock | ||
const command = new Commands.LockStateCommand() | ||
command.updateProps({ | ||
index: this.storeId, | ||
locked: true | ||
}) | ||
this.commandQueue.push(command) | ||
} | ||
} | ||
|
||
lockObtained () { | ||
this.state = 1 | ||
if (this.transfer && this.transfer.state === Enums.TransferState.Queued) { | ||
this.transfer.gotLock() | ||
} | ||
} | ||
|
||
lostLock () { | ||
this.state = 0 | ||
if (this.transfer && this.transfer.state === Enums.TransferState.Finished) { | ||
this.transfer.finish(this.transfer) | ||
} else if (this.transfer) { | ||
// @todo: dequeue any old commands | ||
this.transfer.fail() | ||
} | ||
this.transfer = undefined | ||
this.dequeueAndRun() | ||
} | ||
|
||
updateLock (locked: boolean) { | ||
this.state = locked ? 1 : 0 | ||
} | ||
|
||
transferFinished () { | ||
if (this.queue.length > 0) { | ||
this.dequeueAndRun() | ||
} else { // unlock | ||
const command = new Commands.LockStateCommand() | ||
command.updateProps({ | ||
index: this.storeId, | ||
locked: false | ||
}) | ||
this.commandQueue.push(command) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Commands, Enums } from '..' | ||
|
||
export default abstract class DataTransfer { | ||
startedAt: Date | ||
state: Enums.TransferState = Enums.TransferState.Queued | ||
transferId: number | ||
storeId: number | ||
|
||
commandQueue: Array<Commands.AbstractCommand> | ||
|
||
finish: (transfer: DataTransfer) => void | ||
fail: () => void | ||
abstract start (): void | ||
|
||
abstract handleCommand (command: Commands.AbstractCommand): void | ||
abstract gotLock (): void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Commands, Enums } from '..' | ||
|
||
import DataTransferFrame from './dataTransferFrame' | ||
|
||
export default class DataTransferAudio extends DataTransferFrame { | ||
description: { name: string } | ||
|
||
start () { | ||
const command = new Commands.DataTransferUploadRequestCommand() | ||
command.updateProps({ | ||
transferId: this.transferId, | ||
transferStoreId: this.storeId, | ||
transferIndex: 0, | ||
size: this.data.length, | ||
mode: Enums.TransferMode.WriteAudio | ||
}) | ||
this.commandQueue.push(command) | ||
} | ||
|
||
sendDescription () { | ||
const command = new Commands.DataTransferFileDescriptionCommand() | ||
command.updateProps({ ...this.description, fileHash: this.hash, transferId: this.transferId }) | ||
this.commandQueue.push(command) | ||
} | ||
} |
Oops, something went wrong.