Skip to content

Commit

Permalink
Refactor PTPDevice class and update method names with hard-private sy…
Browse files Browse the repository at this point in the history
…ntax
  • Loading branch information
baku89 committed Sep 17, 2024
1 parent 0b308c0 commit c8c94b2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions core/src/PTPDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ export class PTPDevice extends EventEmitter<EventTypes> {
this.#endpointNumberBulkIn = endpointIn.endpointNumber
this.#endpointerNumberInterruptIn = endpointEvent.endpointNumber

this.listenInterruptIn()
this.listenDisconnect()
this.#listenInterruptIn()
this.#listenDisconnect()

this.#opened = true
}
Expand Down Expand Up @@ -211,7 +211,7 @@ export class PTPDevice extends EventEmitter<EventTypes> {
}

for (let i = 0; i < PTPTryCount; i++) {
const id = this.generateTransactionId()
const id = this.#generateTransactionId()

await this.#transferOutCommand(opcode, id, parameters)

Expand Down Expand Up @@ -258,7 +258,7 @@ export class PTPDevice extends EventEmitter<EventTypes> {
}

for (let i = 0; i < PTPTryCount; i++) {
const id = this.generateTransactionId()
const id = this.#generateTransactionId()

await this.#transferOutCommand(opcode, id, parameters)
await this.#transferOutData(opcode, id, data)
Expand Down Expand Up @@ -309,7 +309,7 @@ export class PTPDevice extends EventEmitter<EventTypes> {
}

for (let i = 0; i < PTPTryCount; i++) {
const id = this.generateTransactionId()
const id = this.#generateTransactionId()

await this.#transferOutCommand(opcode, id, parameters)
const res1 = await this.#waitBulkIn(id, maxByteLength)
Expand Down Expand Up @@ -493,7 +493,7 @@ export class PTPDevice extends EventEmitter<EventTypes> {
}
}

private listenInterruptIn = async () => {
#listenInterruptIn = async () => {
if (!this.usb || !this.usb.opened) {
throw new Error('Device is not opened')
}
Expand Down Expand Up @@ -544,19 +544,19 @@ export class PTPDevice extends EventEmitter<EventTypes> {
}
throw err
} finally {
setTimeout(this.listenInterruptIn, 0)
setTimeout(this.#listenInterruptIn, 0)
}
}

private listenDisconnect() {
#listenDisconnect() {
navigator.usb.addEventListener('disconnect', ev => {
if (ev.device === this.usb) {
this.emit('disconnect')
}
})
}

private generateTransactionId = (): number => {
#generateTransactionId = (): number => {
this.#transactionId += 1
if (this.#transactionId > 0xfffffffe) {
this.#transactionId = 1
Expand Down

0 comments on commit c8c94b2

Please sign in to comment.