Created
October 20, 2021 10:39
-
-
Save velotiotech/6b1acefc9c45a06097ffef0889dddca7 to your computer and use it in GitHub Desktop.
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
console.log(`Route ${route} - data from ${connectionId}`); | |
if (!event.body) { | |
return response; | |
} | |
let body = JSON.parse(event.body); | |
const topic = body.topic; | |
if (body.type === 'subscribe') { | |
connection.subscribe({ topic }); | |
console.log(`Client subscribing for topic: ${topic}`); | |
} | |
if (body.type === 'message') { | |
await new Topic(topic).publishMessage({ data: body.message }); | |
console.error(`Published messages to subscribers`); | |
return response; | |
} | |
return response; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment