This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4923 from trufflesuite/dashboard/events
Hook up example events -> dashboard communication
- Loading branch information
Showing
5 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const { | ||
connectToMessageBusWithRetries, | ||
createMessage, | ||
getMessageBusPorts, | ||
sendAndAwait, | ||
MessageBusConnectionError | ||
} = require("@truffle/dashboard-message-bus"); | ||
|
||
module.exports = class DashboardMessageBusClient { | ||
constructor(config) { | ||
this.config = config.dashboard || { | ||
host: "localhost", | ||
port: 24012 | ||
}; | ||
} | ||
|
||
async _getSocket() { | ||
if (this._socket) { | ||
return this._socket; | ||
} | ||
|
||
const { publishPort } = await getMessageBusPorts( | ||
this.config.port, | ||
this.config.host | ||
); | ||
|
||
this._socket = await connectToMessageBusWithRetries( | ||
publishPort, | ||
this.config.host | ||
); | ||
|
||
return this._socket; | ||
} | ||
|
||
async sendAndAwait({ type, payload }) { | ||
try { | ||
const socket = await this._getSocket(); | ||
const message = createMessage(type, payload); | ||
|
||
return await sendAndAwait(socket, message); | ||
} catch (err) { | ||
if (!(err instanceof MessageBusConnectionError)) { | ||
throw err; | ||
} else return; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters