Swift Client SDK Drop in Audio Chat Server

Nexmo is now known as Vonage

This is a Swift project that uses Vapor to create a HTTP server for the Vonage Conversation API. This project was built to be used with an accompanying app, learn more about both projects on our blog.

A JavaScript version of this server is available on GitHub.

Welcome to Vonage

If you're new to Vonage, you can sign up for a Vonage API account and get some free credit to get you started.

Prerequisites

  • A Vonage API account.

  • Xcode 12 and Swift 5 or greater.

  • Vapor 4.0 installed on your machine.

Running the project

After cloning the project to your machine change into the project directory. Add your private.key file to the project directory under Sources/App/.

Open it in Xcode by running vapor xcode and wait for Xcode to download the packages.

Set a custom working directory for your project. Go to Product > Scheme > Edit Scheme... and set the working directory to the root folder of your project.

Add your Vonage Application ID to routes.swift

Once done, build and run (CMD + R) and the server will be accessible on port 8080.

Endpoints

The project serves to 3 endpoints:

  • /auth (POST):

This returns a JWT to log the Client SDK in.

Request Body:

{
  "name": "value" // String - username
}

Request Reponse:

{
  "name": "value", // String - username
  "jwt": "value" // String - JWT for the username
}
  • /rooms (GET):

This returns a list of open chat rooms.

Request Reponse:

[
  {
    "id": "value", // String - ID for the room/conversation
    "display_name": "value" // String - Name for the room/conversation
  },
  {
    "id": "value", // String - ID for the room/conversation
    "display_name": "value" // String - Name for the room/conversation
  }
]
  • /rooms (POST):

This allows the app to create a new room.

Request Body:

{
  "display_name": "value" // String - Name for the room/conversation
}

Request Reponse:

{
  "id": "value" // String - ID for the room/conversation
}

Getting Help

We love to hear from you so if you have questions, comments or find a bug in the project, let us know! You can either:

Further Reading