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 #711 from dherault/websocket-fixes
Websocket
- Loading branch information
Showing
44 changed files
with
4,292 additions
and
1,297 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 |
---|---|---|
@@ -1,4 +1 @@ | ||
manual_test_nodejs | ||
manual_test_python | ||
manual_test_ruby | ||
manual_test_websocket | ||
**/node_modules |
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
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
'use strict'; | ||
|
||
const { exec } = require('child_process'); | ||
|
||
|
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 @@ | ||
/**/serverless.yml |
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,31 @@ | ||
const AWS = require('aws-sdk'); | ||
|
||
const successfullResponse = { | ||
statusCode: 200, | ||
body: 'Request is OK.', | ||
}; | ||
|
||
module.exports.echo = async (event, context) => { | ||
const action = JSON.parse(event.body); | ||
|
||
await sendToClient(action.message, event.requestContext.connectionId, newAWSApiGatewayManagementApi(event, context)); | ||
|
||
return successfullResponse; | ||
}; | ||
|
||
const newAWSApiGatewayManagementApi = event => { | ||
let endpoint = event.apiGatewayUrl; | ||
|
||
if (!endpoint) endpoint = `${event.requestContext.domainName}/${event.requestContext.stage}`; | ||
const apiVersion = '2018-11-29'; | ||
|
||
return new AWS.ApiGatewayManagementApi({ apiVersion, endpoint }); | ||
}; | ||
|
||
const sendToClient = (data, connectionId, apigwManagementApi) => { | ||
// console.log(`sendToClient:${connectionId}`); | ||
let sendee = data; | ||
if (typeof data === 'object') sendee = JSON.stringify(data); | ||
|
||
return apigwManagementApi.postToConnection({ ConnectionId: connectionId, Data: sendee }).promise(); | ||
}; |
Oops, something went wrong.