opentok / Opentok-.NET-SDK

Official .NET Server SDK for OpenTok
https://tokbox.com/developer/sdks/dot-net/
MIT License
57 stars 94 forks source link

Start Audio Connector returns 400 - Bad Request #222

Closed Tr00d closed 1 year ago

Tr00d commented 1 year ago

When calling the StartAudioConnectorAsync method, a well-formed request will always return a 400 - Bad request.

The problem happens during the request's serialization. The serialized request should look like this:

{
  "sessionId": "OpenTok session ID",
  "token": "A valid OpenTok token",
  "websocket": {
    "uri": "wss://service.com/ws-endpoint",
    "streams": [
      "streamId-1",
      "streamId-2"
    ],
    "headers": {
      "headerKey": "headerValue"
    },
    "audioRate" : 8000
  }
}

But it looks like this:

{
  "sessionId": "OpenTok session ID",
  "token": "A valid OpenTok token",
  "webSocket": {
    "Uri": "wss://service.com/ws-endpoint",
    "Streams": [
      "streamId-1",
      "streamId-2"
    ],
    "Headers": {
      "headerKey": "headerValue"
    },
    "AudioRate" : 8000
  }
}

Code snippet:

OpenTok openTok = new OpenTok(Config.GetApiKey(), Config.GetApiSecret());
openTok.StartBroadcast(sessionId);
StreamList streams = openTok.ListStreams(sessionId);
string token = openTok.GenerateToken(sessionId);
var webSocket = new AudioConnectorStartRequest.WebSocket(new Uri("wss://xxx/"), streams.Select(s => s.Name).ToArray());
var startRequest = new AudioConnectorStartRequest(sessionId, token, webSocket);
AudioConnector response = await openTok.StartAudioConnectorAsync(startRequest);