0

I am trying to connect my project on VueJS 3 using websocket in Yandex Cloud Api Gateway. Here is the instruction https://cloud.yandex.com/en-ru/docs/api-gateway/tutorials/api-gw-websocket The example shows the connection method via wscat. Everything works. But when connecting via the browser, the following happens: The connection is normal, but when sending a message it gives an error

WebSocket connection to 'wss://d5dao5nnb9dr9t11nt2b.apigw.yandexcloud.net/connections' failed: Could not decode a text frame as UTF-8.

Can you tell me how to normally implement a connection to the Yandex Cloud Api Gateway via websocket?

API GATEWAY CODE

openapi: 3.0.0
info:
  title: Test API
  version: 1.0.0
paths:
  /connections:
    x-yc-apigateway-websocket-message:
      summary: Get connection identifier
      operationId: getConnectionID
      parameters:
        - name: X-Yc-Apigateway-Websocket-Connection-Id
          in: header
          description: Websocket connection identifier
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Connection identifier
          content:
            text/plain:
              schema:
                type: string
      x-yc-apigateway-integration:
        type: dummy
        http_code: 200
        http_headers:
          Content-Type: application/json
        content:
          text/plain: '{"connection_id":"{X-Yc-Apigateway-Websocket-Connection-Id}"}'

JS CONNECTION CODE

let socket = new WebSocket("wss://d5dao5nnb9dr9t11nt2b.apigw.yandexcloud.net/connections");
socket.onopen = function() {
  console.log("[open] Connection established");
  socket.send('TestMessage');
};

Console Result

[open] Connection established
Sending to server
WebSocket connection to 'wss://d5dao5nnb9dr9t11nt2b.apigw.yandexcloud.net/connections' failed: Could not decode a text frame as UTF-8.
dindev
  • 23
  • 1
  • 2

0 Answers0