Skip to content

Commit

Permalink
Fixed issue #63
Browse files Browse the repository at this point in the history
  • Loading branch information
bropat committed Nov 17, 2021
1 parent 06aee3b commit e4b78c6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ Please use GitHub issues for this.

## Changelog

### 1.2.4 (2021-11-17)

* (bropat) Fixed issue #63

### 1.2.3 (2021-11-16)

* (bropat) Fixed issue #64
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eufy-security-client",
"version": "1.2.3",
"version": "1.2.4",
"description": "Client to comunicate with Eufy-Security devices",
"author": {
"name": "bropat",
Expand Down
5 changes: 2 additions & 3 deletions src/p2p/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ export interface P2PDataMessageState {
p2pStreamFirstVideoDataReceived: boolean;
p2pStreamMetadata: StreamMetadata;
p2pStreamingTimeout?: NodeJS.Timeout;
rtspStream: boolean;
rtspStreaming: boolean;
rtspStreamChannel: number;
rtspStream: { [index: number]: boolean };
rtspStreaming: { [index: number]: boolean };
waitForSeqNoTimeout?: NodeJS.Timeout;
waitForAudioData?: NodeJS.Timeout;
receivedFirstIFrame: boolean;
Expand Down
38 changes: 16 additions & 22 deletions src/p2p/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,8 @@ export class P2PClientProtocol extends TypedEmitter<P2PClientProtocolEvents> {
videoWidth: 1920,
audioCodec: AudioCodec.NONE
},
rtspStream: false,
rtspStreaming: false,
rtspStreamChannel: -1,
rtspStream: {},
rtspStreaming: {},
receivedFirstIFrame: false,
preFrameVideoData: Buffer.from([])
};
Expand Down Expand Up @@ -231,7 +230,9 @@ export class P2PClientProtocol extends TypedEmitter<P2PClientProtocolEvents> {
if (this.currentMessageState[P2PDataType.BINARY].p2pStreaming) {
this.endStream(P2PDataType.BINARY)
}
this.endRTSPStream();
for (const channel in this.currentMessageState[P2PDataType.DATA].rtspStreaming) {
this.endRTSPStream(Number.parseInt(channel));
}
if (this.connected) {
this.emit("close");
} else if (!this.terminating) {
Expand Down Expand Up @@ -387,7 +388,7 @@ export class P2PClientProtocol extends TypedEmitter<P2PClientProtocolEvents> {
public sendCommandWithIntString(commandType: CommandType, value: number, valueSub = 0, strValue = "", strValueSub = "", channel = 0): void {
const payload = buildIntStringCommandPayload(value, valueSub, strValue, strValueSub, channel);
if (commandType === CommandType.CMD_NAS_TEST) {
this.currentMessageState[P2PDataType.DATA].rtspStream = value === 1 ? true : false;
this.currentMessageState[P2PDataType.DATA].rtspStream[channel] = value === 1 ? true : false;
}
this.sendCommand(commandType, payload, channel);
}
Expand Down Expand Up @@ -552,13 +553,11 @@ export class P2PClientProtocol extends TypedEmitter<P2PClientProtocolEvents> {
} else if (message.commandType === CommandType.CMD_DOWNLOAD_CANCEL) {
this.endStream(P2PDataType.BINARY);
} else if (message.commandType === CommandType.CMD_NAS_TEST) {
//TODO: Verify if starting p2p live stream stopps this or viceversa
if (this.currentMessageState[P2PDataType.DATA].rtspStream) {
this.currentMessageState[P2PDataType.DATA].rtspStreaming = this.currentMessageState[P2PDataType.DATA].rtspStream;
this.currentMessageState[P2PDataType.DATA].rtspStreamChannel = message.channel;
this.emit("rtsp livestream started", this.currentMessageState[P2PDataType.DATA].rtspStreamChannel);
if (this.currentMessageState[P2PDataType.DATA].rtspStream[message.channel]) {
this.currentMessageState[P2PDataType.DATA].rtspStreaming[message.channel] = true;
this.emit("rtsp livestream started", message.channel);
} else {
this.endRTSPStream();
this.endRTSPStream(message.channel);
}
}
}
Expand Down Expand Up @@ -1435,14 +1434,11 @@ export class P2PClientProtocol extends TypedEmitter<P2PClientProtocolEvents> {
}
}

private endRTSPStream(): void {
if (this.currentMessageState[P2PDataType.DATA].rtspStreaming) {
this.currentMessageState[P2PDataType.DATA].rtspStream = false;
this.currentMessageState[P2PDataType.DATA].rtspStreaming = false;

this.emit("rtsp livestream stopped", this.currentMessageState[P2PDataType.DATA].rtspStreamChannel);

this.currentMessageState[P2PDataType.DATA].rtspStreamChannel = -1;
private endRTSPStream(channel: number): void {
if (this.currentMessageState[P2PDataType.DATA].rtspStreaming[channel]) {
this.currentMessageState[P2PDataType.DATA].rtspStream[channel] = false;
this.currentMessageState[P2PDataType.DATA].rtspStreaming[channel] = false;
this.emit("rtsp livestream stopped", channel);
}
}

Expand Down Expand Up @@ -1474,9 +1470,7 @@ export class P2PClientProtocol extends TypedEmitter<P2PClientProtocolEvents> {
}

public isRTSPLiveStreaming(channel: number): boolean {
if (this.currentMessageState[P2PDataType.DATA].rtspStreamChannel === channel)
return this.currentMessageState[P2PDataType.DATA].rtspStreaming;
return false;
return this.currentMessageState[P2PDataType.DATA].rtspStreaming[channel] ? this.currentMessageState[P2PDataType.DATA].rtspStreaming[channel] : false;
}

public isDownloading(channel: number): boolean {
Expand Down

0 comments on commit e4b78c6

Please sign in to comment.