-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from rpitv/sync
- Loading branch information
Showing
42 changed files
with
4,064 additions
and
620 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 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
Large diffs are not rendered by default.
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
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 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 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 |
---|---|---|
@@ -1,15 +1,33 @@ | ||
type ListenerFn = (argument?: any, ack?: (error: Error, returnVal: any) => void) => void; | ||
|
||
export class MessageComposable { | ||
|
||
public channel: string; | ||
public namespace: string; | ||
|
||
private listeners: ListenerFn[] = []; | ||
|
||
public constructor(channel: string, namespace?: string) { | ||
this.channel = channel; | ||
this.namespace = namespace ?? ""; | ||
} | ||
|
||
public async send(argument?: any): Promise<void> { | ||
public async send(argument?: any): Promise<any> { | ||
// @ts-ignore | ||
await nodecg.sendMessage(this.namespace + '.' + this.channel, argument) | ||
return await nodecg.sendMessage(this.namespace + '.' + this.channel, argument); | ||
} | ||
|
||
public listen(callback: ListenerFn): void { | ||
this.listeners.push(callback); | ||
// @ts-ignore | ||
nodecg.listenFor(this.namespace + '.' + this.channel, callback) | ||
} | ||
|
||
public destroy(): void { | ||
for(const listener of this.listeners) { | ||
// @ts-ignore | ||
nodecg.unlisten(this.namespace + '.' + this.channel, listener); | ||
} | ||
this.listeners = []; | ||
} | ||
} |
Oops, something went wrong.