Skip to content

Commit

Permalink
feat: quit command before closing connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Balte de Wit committed Sep 2, 2019
1 parent 9219b87 commit ece4982
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/commands/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ export class PingCommand extends AbstractCommandNoResponse {
return res
}
}

export class QuitCommand extends AbstractCommandNoResponse {
serialize () {
const res: NamedMessage = {
name: 'quit',
params: {}
}

return res
}
}
5 changes: 3 additions & 2 deletions src/hyperdeck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ResponseCodeType, GetResponseCodeType, AsynchronousCode } from './codes
import { AbstractCommand, ErrorResponse } from './commands'
import * as AsyncHandlers from './asyncHandlers'
import { ResponseMessage } from './message'
import { DummyConnectCommand, WatchdogPeriodCommand, PingCommand } from './commands/internal'
import { DummyConnectCommand, WatchdogPeriodCommand, PingCommand, QuitCommand } from './commands/internal'
import { buildMessageStr, MultilineParser } from './parser'

export interface HyperdeckOptions {
Expand Down Expand Up @@ -110,8 +110,9 @@ export class Hyperdeck extends EventEmitter {

if (!this._connected) return Promise.resolve()

return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
try {
await this.sendCommand(new QuitCommand())
this.socket.end()
return resolve()
} catch (e) {
Expand Down

0 comments on commit ece4982

Please sign in to comment.