-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yoseph Maguire
committed
Aug 6, 2020
1 parent
963e554
commit d21d277
Showing
5 changed files
with
90 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const aedes = require('aedes')() | ||
const httpServer = require('http').createServer() | ||
const WebSocket = require('ws') | ||
const wsPort = 8080 | ||
|
||
// Here we are creating the Websocket Server that is using the HTTP Server... | ||
const wss = new WebSocket.Server({ server: httpServer }) | ||
wss.on('connection', function connection (ws) { | ||
const duplex = WebSocket.createWebSocketStream(ws) | ||
aedes.handle(duplex) | ||
}) | ||
|
||
httpServer.listen(wsPort, function () { | ||
console.log('websocket server listening on port', wsPort) | ||
}) | ||
|
||
aedes.on('clientError', function (client, err) { | ||
console.log('client error', client.id, err.message, err.stack) | ||
}) | ||
|
||
aedes.on('connectionError', function (client, err) { | ||
console.log('client error', client, err.message, err.stack) | ||
}) | ||
|
||
aedes.on('publish', function (packet, client) { | ||
if (packet && packet.payload) { | ||
console.log('publish packet:', packet.payload.toString()) | ||
} | ||
if (client) { | ||
console.log('message from client', client.id) | ||
} | ||
}) | ||
|
||
aedes.on('subscribe', function (subscriptions, client) { | ||
if (client) { | ||
console.log('subscribe from client', subscriptions, client.id) | ||
} | ||
}) | ||
|
||
aedes.on('client', function (client) { | ||
console.log('new client', client.id) | ||
}) |
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