Skip to content

Commit

Permalink
fix(lib): Job.cancel() wasn't sending "XDCC CANCEL" message
Browse files Browse the repository at this point in the history
fix 494
  • Loading branch information
JiPaix committed Jun 5, 2022
1 parent 6c90881 commit ae5561f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog
## [v4.4.21](https://github.com/jipaix/xdccjs/tree/v4.4.21)
### Feat(lib)
* Job.cancel() is now always defined
### Fix(lib)
* Job.cancel() wasn't sending "XDCC CANCEL" message
---
## [v4.4.20](https://github.com/jipaix/xdccjs/tree/v4.4.20)
### Fix(lib)
* expose xdccJS events
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xdccjs",
"version": "4.4.20",
"version": "4.4.21",
"description": "download files from XDCC bots on IRC, complete implementation of the XDCC protocol",
"engines": {
"node": ">=14.0.0"
Expand Down
5 changes: 3 additions & 2 deletions src/addjob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ export default class AddJob extends TimeOut {
};
}

protected makeCancelable(candidate: Job, client?: net.Socket): () => void {
protected makeCancelable(candidate: Candidate, client?: net.Socket): () => void {
const fn = (): void => {
candidate.timeout.clear();
this.say(candidate.cancelNick, 'XDCC CANCEL');
if (client) {
const cancel = new Error('cancel');
client.destroy(cancel);
Expand All @@ -59,9 +60,9 @@ export default class AddJob extends TimeOut {
let candidate = this.getCandidate(target);
if (!candidate) {
const base = AddJob.constructCandidate(target, range);
base.cancel = this.makeCancelable(base);
const newCand = new Job(base);
AddJob.makeClearable(newCand);
newCand.cancel = this.makeCancelable(newCand);
this.candidates.push(newCand);
candidate = this.getCandidate(target);
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class Job extends (EventEmitter as new () => TypedEmitter<JobMessageEvent
* })
* ```
*/
cancel?: () => void;
cancel: () => void;

/** @ignore */
failures: number[];
Expand Down Expand Up @@ -130,6 +130,7 @@ export class Job extends (EventEmitter as new () => TypedEmitter<JobMessageEvent
constructor(candidate: Candidate) {
// eslint-disable-next-line constructor-super
super();
if (!candidate.cancel) throw new Error('candidate must be passed to makeCancelable first');
this.cancel = candidate.cancel;
this.failures = candidate.failures;
this.nick = candidate.nick;
Expand Down

0 comments on commit ae5561f

Please sign in to comment.