AWS Ответ соединения Websocket - PullRequest
0 голосов
/ 19 апреля 2020

Я тихий новичок с AWS Websockets. Я надеюсь, что мой запрос будет иметь смысл. Итак, я управляю своим приложением "чат". Я могу подключаться, отправлять сообщения и отключаться без проблем. Я пытаюсь улучшить ответ от Connect AWS Apigateway. Я хочу видеть "myData" на стороне клиента. Это будет изменено на список объектов в будущем. Заранее спасибо

serveless.yml

  socketConnection:
    handler: ${self:custom.pathFunc}/socketOption.socketConnection
    events:
      - websocket:
          route: $connect
      - websocket:
          route: $disconnect

socketOptions. js

const socketConnection = ( event, context, callback ) => {
  if ( event.requestContext.eventType === 'CONNECT' ) {
    addConnection( event.requestContext.connectionId )
    .then( () => {
      callback( null, {
        statusCode: 200,
        body: {
         myData: "here goes any data I want"
        }
      } );
    } )
  } else if ( event.requestContext.eventType === 'DISCONNECT' ) {
  //  ...
  }
};
module.exports.socketConnection = socketConnection

myComponent. vue

connect(){
  this.connection = new WebSocket(this.wss)

  this.connection.onopen = this.onOpen
  this.connection.onmessage = this.onMessage
  this.connection.onclose = this.onClose
  this.connection.onerror = this.onError
},
onOpen(event){
  console.log("onOpen -> event", event)
}

enter image description here

...