atem-connection
Advanced tools
Comparing version 0.1.7 to 0.2.0
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="0.2.0"></a> | ||
# [0.2.0](https://github.com/nrkno/tv-automation-atem-connection/compare/0.1.7...0.2.0) (2018-07-01) | ||
### Features | ||
* disconnect method ([54dfa15](https://github.com/nrkno/tv-automation-atem-connection/commit/54dfa15)) | ||
<a name="0.1.7"></a> | ||
@@ -7,0 +17,0 @@ ## [0.1.7](https://github.com/nrkno/tv-automation-atem-connection/compare/0.1.6...0.1.7) (2018-06-21) |
@@ -28,2 +28,3 @@ /// <reference types="node" /> | ||
connect(address: string, port?: number): void; | ||
disconnect(): Promise<void>; | ||
sendCommand(command: AbstractCommand): Promise<any>; | ||
@@ -30,0 +31,0 @@ changeProgramInput(input: number, me?: number): Promise<any>; |
@@ -37,2 +37,7 @@ "use strict"; | ||
} | ||
disconnect() { | ||
return new Promise((resolve, reject) => { | ||
this.socket.disconnect().then(() => resolve()).catch(reject); | ||
}); | ||
} | ||
sendCommand(command) { | ||
@@ -39,0 +44,0 @@ const nextPacketId = this.socket.nextPacketId; |
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
import AbstractCommand from './AbstractCommand'; | ||
@@ -7,4 +6,4 @@ export declare class InitCompleteCommand extends AbstractCommand { | ||
properties: null; | ||
deserialize(rawCommand: Buffer): void; | ||
deserialize(): void; | ||
applyToState(): void; | ||
} |
@@ -9,5 +9,4 @@ "use strict"; | ||
} | ||
deserialize(rawCommand) { | ||
console.log(rawCommand); | ||
console.log('Initialized :D'); | ||
deserialize() { | ||
// | ||
} | ||
@@ -14,0 +13,0 @@ applyToState() { |
@@ -10,3 +10,2 @@ "use strict"; | ||
deserialize(rawCommand) { | ||
console.log('PrgI', rawCommand); | ||
this.mixEffect = rawCommand[0]; | ||
@@ -13,0 +12,0 @@ this.properties = { |
@@ -7,2 +7,4 @@ /// <reference types="node" /> | ||
private _debug; | ||
private _reconnectTimer; | ||
private _retransmitTimer; | ||
private _localPacketId; | ||
@@ -27,5 +29,7 @@ private _maxPacketID; | ||
connect(address?: string, port?: number): void; | ||
disconnect(): Promise<{}>; | ||
log(..._args: any[]): void; | ||
readonly nextPacketId: number; | ||
_sendCommand(command: AbstractCommand): void; | ||
private _createSocket(); | ||
private _receivePacket(packet, rinfo); | ||
@@ -32,0 +36,0 @@ private _parseCommand(buffer, packetId?); |
@@ -26,20 +26,25 @@ "use strict"; | ||
this.log = options.log || this.log; | ||
this._socket = dgram_1.createSocket('udp4'); | ||
this._socket.bind(1024 + Math.floor(Math.random() * 64511)); | ||
this._socket.on('message', (packet, rinfo) => this._receivePacket(packet, rinfo)); | ||
setInterval(() => { | ||
if (this._lastReceivedAt + this._reconnectInterval > Date.now()) | ||
return; | ||
if (this._connectionState === enums_1.ConnectionState.Established) { | ||
this._connectionState = enums_1.ConnectionState.Closed; | ||
this.emit('disconnect', null, null); | ||
} | ||
this._localPacketId = 1; | ||
this._sessionId = 0; | ||
this.log('reconnect'); | ||
this.connect(this._address, this._port); | ||
}, this._reconnectInterval); | ||
setInterval(() => this._checkForRetransmit(), 50); | ||
this._createSocket(); | ||
} | ||
connect(address, port) { | ||
if (!this._reconnectTimer) { | ||
this._reconnectTimer = setInterval(() => { | ||
if (this._lastReceivedAt + this._reconnectInterval > Date.now()) | ||
return; | ||
if (this._connectionState === enums_1.ConnectionState.Established) { | ||
this._connectionState = enums_1.ConnectionState.Closed; | ||
this.emit('disconnect', null, null); | ||
} | ||
this._localPacketId = 1; | ||
this._sessionId = 0; | ||
this.log('reconnect'); | ||
if (this._address && this._port) { | ||
this._sendPacket(atemUtil_1.Util.COMMAND_CONNECT_HELLO); | ||
this._connectionState = enums_1.ConnectionState.SynSent; | ||
} | ||
}, this._reconnectInterval); | ||
} | ||
if (!this._retransmitTimer) { | ||
this._retransmitTimer = setInterval(() => this._checkForRetransmit(), 50); | ||
} | ||
if (address) { | ||
@@ -54,2 +59,21 @@ this._address = address; | ||
} | ||
disconnect() { | ||
return new Promise((resolve) => { | ||
if (this._connectionState !== enums_1.ConnectionState.Established) { | ||
this._socket.close(() => { | ||
clearInterval(this._retransmitTimer); | ||
clearInterval(this._reconnectTimer); | ||
this._retransmitTimer = undefined; | ||
this._reconnectTimer = undefined; | ||
this._connectionState = enums_1.ConnectionState.Closed; | ||
this._createSocket(); | ||
this.emit('disconnect'); | ||
resolve(); | ||
}); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
}); | ||
} | ||
log(..._args) { | ||
@@ -85,2 +109,7 @@ // Will be re-assigned by the top-level ATEM class. | ||
} | ||
_createSocket() { | ||
this._socket = dgram_1.createSocket('udp4'); | ||
this._socket.bind(1024 + Math.floor(Math.random() * 64511)); | ||
this._socket.on('message', (packet, rinfo) => this._receivePacket(packet, rinfo)); | ||
} | ||
_receivePacket(packet, rinfo) { | ||
@@ -87,0 +116,0 @@ if (this._debug) |
{ | ||
"name": "atem-connection", | ||
"version": "0.1.7", | ||
"version": "0.2.0", | ||
"description": "Typescript Node.js library for connecting with an ATEM switcher.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
246937
3851