Skip to content

Commit ae5561f

Browse files
committed
fix(lib): Job.cancel() wasn't sending "XDCC CANCEL" message
fix 494
1 parent 6c90881 commit ae5561f

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# Changelog
2+
## [v4.4.21](https://github.com/jipaix/xdccjs/tree/v4.4.21)
3+
### Feat(lib)
4+
* Job.cancel() is now always defined
5+
### Fix(lib)
6+
* Job.cancel() wasn't sending "XDCC CANCEL" message
7+
---
28
## [v4.4.20](https://github.com/jipaix/xdccjs/tree/v4.4.20)
39
### Fix(lib)
410
* expose xdccJS events

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xdccjs",
3-
"version": "4.4.20",
3+
"version": "4.4.21",
44
"description": "download files from XDCC bots on IRC, complete implementation of the XDCC protocol",
55
"engines": {
66
"node": ">=14.0.0"

src/addjob.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ export default class AddJob extends TimeOut {
4040
};
4141
}
4242

43-
protected makeCancelable(candidate: Job, client?: net.Socket): () => void {
43+
protected makeCancelable(candidate: Candidate, client?: net.Socket): () => void {
4444
const fn = (): void => {
4545
candidate.timeout.clear();
46+
this.say(candidate.cancelNick, 'XDCC CANCEL');
4647
if (client) {
4748
const cancel = new Error('cancel');
4849
client.destroy(cancel);
@@ -59,9 +60,9 @@ export default class AddJob extends TimeOut {
5960
let candidate = this.getCandidate(target);
6061
if (!candidate) {
6162
const base = AddJob.constructCandidate(target, range);
63+
base.cancel = this.makeCancelable(base);
6264
const newCand = new Job(base);
6365
AddJob.makeClearable(newCand);
64-
newCand.cancel = this.makeCancelable(newCand);
6566
this.candidates.push(newCand);
6667
candidate = this.getCandidate(target);
6768
} else {

src/interfaces/job.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class Job extends (EventEmitter as new () => TypedEmitter<JobMessageEvent
8787
* })
8888
* ```
8989
*/
90-
cancel?: () => void;
90+
cancel: () => void;
9191

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

0 commit comments

Comments
 (0)