Skip to content

Commit edfa9ae

Browse files
committed
update
1 parent 5b03129 commit edfa9ae

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

extension.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export default class Extension {
2626
#name = null
2727
#parameters = []
2828
#softwareVersion = null
29+
#started = false
30+
#token = null
2931
#website = null
3032

3133
#publisher = null
@@ -35,9 +37,12 @@ export default class Extension {
3537
* @returns {Extension} The created extension instance.
3638
*/
3739
constructor(token) {
38-
token = token || process.argv[2] || process.env.TALKOPS_TOKEN
39-
if (token) {
40-
const mercure = JSON.parse(Buffer.from(token, 'base64').toString())
40+
this.#token = token || process.argv[2] || process.env.TALKOPS_TOKEN
41+
}
42+
43+
async #setup() {
44+
if (this.#token) {
45+
const mercure = JSON.parse(Buffer.from(this.#token, 'base64').toString())
4146
this.#publisher = new Publisher(
4247
() => {
4348
return {
@@ -99,6 +104,16 @@ export default class Extension {
99104
}
100105
}
101106

107+
/**
108+
* @returns {Extension} The starting extension instance.
109+
*/
110+
start() {
111+
if (this.#started) return
112+
this.#started = true
113+
setTimeout(() => this.#setup(), 500)
114+
return this
115+
}
116+
102117
/**
103118
* @param {String} eventType - The event type.
104119
* @param {Function} cb - The callback function.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "talkops",
33
"description": "TalkOps SDK",
4-
"version": "2.14.1",
4+
"version": "2.15.0",
55
"author": "PicoUX",
66
"license": "MIT",
77
"main": "index.mjs",

publisher.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ export default class Publisher {
99
constructor(useConfig, useState) {
1010
this.#useConfig = useConfig
1111
this.#useState = useState
12-
setTimeout(() => this.#publishData(JSON.stringify({ type: 'init' })), 900)
13-
setTimeout(() => this.#publishState(), 1000)
1412

1513
const originalStdoutWrite = process.stdout.write
1614
process.stdout.write = (chunk) => {
@@ -28,6 +26,8 @@ export default class Publisher {
2826
})
2927
originalStderrWrite.call(process.stderr, chunk)
3028
}
29+
this.#publishData(JSON.stringify({ type: 'init' }))
30+
setTimeout(() => this.#publishState(), 100)
3131
}
3232

3333
async publishState() {

readme.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ A TalkOps Extension made to work with [TalkOps](https://talkops.app).
1616

1717
1. Sign in to [TalkOps](https://talkops.app).
1818
2. Search for the `<%= extension.name %>` extension.
19-
3. Add the extension and follow the instructions.
19+
3. Add the extension and follow the instructions.

0 commit comments

Comments
 (0)