Skip to content

Commit

Permalink
[task] enable getTimeSinceLastMessage
Browse files Browse the repository at this point in the history
:100644 100644 29ae60b d2b44d6 M	src/connection/socket-factory.ts
  • Loading branch information
jaime-ez committed May 8, 2020
1 parent 772810d commit 388506e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/connection/connection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ describe('connection', () => {
await recieveConnectionClose()
})

it('send pong when ping received across all states', async () => {
it('send ping and recieve pong across all states', async () => {
await openConnection()
sendPong()
receivePing()
sendPing()
receivePong()
})

it('miss heartbeat once', async () => {
Expand Down Expand Up @@ -504,20 +504,20 @@ describe('connection', () => {
await PromiseDelay(0)
}

function receivePing () {
function receivePong () {
socket.simulateMessages([{
topic: TOPIC.CONNECTION,
action: CONNECTION_ACTION.PING
action: CONNECTION_ACTION.PONG
}])
}

function sendPong () {
function sendPing () {
socketMock
.expects('sendParsedMessage')
.once()
.withExactArgs({
topic: TOPIC.CONNECTION,
action: CONNECTION_ACTION.PONG
action: CONNECTION_ACTION.PING
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/connection/socket-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const socketFactory: SocketFactory = (url, options = { jsonTransportMode:
socket.onparsedmessages(parseResults)
}
socket.getTimeSinceLastMessage = () => {
return 0
// return Date.now() - lastRecievedMessageTimestamp
if (lastRecievedMessageTimestamp < 0) return 0
return Date.now() - lastRecievedMessageTimestamp
}
socket.sendParsedMessage = (message: Message): void => {
if (message.topic === TOPIC.CONNECTION && message.action === CONNECTION_ACTION.CLOSING) {
Expand Down

0 comments on commit 388506e

Please sign in to comment.