PhonecallController

struct PhonecallController : APIRouteCollection

The collection of /api/v3/phone/* route endpoints and handler functions related to phone call management..

  • Declaration

    Swift

    static let logger: <<error type>>
  • Declaration

    Swift

    var encoder: JSONEncoder { get }
  • Required. Registers routes to the incoming router.

    Declaration

    Swift

    func registerRoutes(_ app: Application) throws
  • POST /api/v3/phone/initiate/:call_id/to/:user_id

    The requester is trying to start a phone call to the given user. Notify the target user of the incoming phone call via their notification socket and provide the IP address(es) of the caller. The callee is then expected to open a socket to the caller for moving audio.

    Throws

    BadRequest if malformed. notFound if user can’t be notified of call.

    Declaration

    Swift

    func initiateCallHandler(_ req: Request) async throws -> HTTPStatus

    Parameters

    callID

    in URL path. Caller-provided UUID for this call. Callee needs to send this to caller to verify the socket is for the correct call.

    userID

    The userID of the user to call.

    Return Value

    200 OK on success

  • GET /api/v3/phone/socket/initiate/:call_id/to/:user_id

    The requester is trying to start a phone call to the given user. Notify the target user of the incoming phone call via their notification socket and save the caller socket. The callee should open a phone socket to the server using answerPhoneSocket at which point the server will start forwarding websocket packets between the caller and callee sockets.

    This is the server-mediated phone call path.

    Throws

    BadRequest if malformed. notFound if user can’t be notified of call.

    Declaration

    Swift

    func shouldCreatePhoneSocket(_ req: Request) async throws -> HTTPHeaders?

    Parameters

    callID

    in URL path. Caller-provided UUID for this call. Callee needs to send this to caller to verify the socket is for the correct call.

    userID

    The userID of the user to call.

    Return Value

    200 OK on success

  • WS /api/v3/phone/socket/initiate/:call_id/to/:user_id

    The requester is trying to start a phone call to the given user. Notify the target user of the incoming phone call via their notification socket and save the caller socket. The callee should open a phone socket to the server using answerPhoneSocket at which point the server will start forwarding websocket packets between the caller and callee sockets.

    This is the server-mediated phone call path.

    Throws

    BadRequest if malformed. notFound if user can’t be notified of call.

    Declaration

    Swift

    func createPhoneSocket(_ req: Request, _ ws: WebSocket) async

    Parameters

    callID

    in URL path. Caller-provided UUID for this call. Callee needs to send this to caller to verify the socket is for the correct call.

    userID

    The userID of the user to call.

    Return Value

    200 OK on success

  • GET /api/v3/phone/socket/answer/:call_id

    The requester is trying to answer an incoming phone call. This is the server-mediated phone call path.

    Throws

    BadRequest if malformed. NotFound if callID doesn’t exist.

    Declaration

    Swift

    func shouldAnswerPhoneSocket(_ req: Request) async throws -> HTTPHeaders?

    Parameters

    callID

    in URL path. Caller-provided UUID for this call. Callee needs to send this to caller to verify the socket is for the correct call.

    Return Value

    200 OK on success

  • WS /api/v3/phone/socket/answer/:call_id

    The requester is trying to answer an incoming phone call. This is the server-mediated phone call path.

    Throws

    BadRequest if malformed. NotFound if callID doesn’t exist.

    Declaration

    Swift

    func answerPhoneSocket(_ req: Request, _ ws: WebSocket) async

    Parameters

    callID

    in URL path. Caller-provided UUID for this call. Callee needs to send this to caller to verify the socket is for the correct call.

    Return Value

    200 OK on success

  • answerPhoneCall(_:) Asynchronous

    POST /api/v3/phone/answer/:call_ID

    The answering party should call this when they answer the incoming call; this notifies other devices where that user is logged in to stop ringing. Only necessary for the direct-socket path.

    Throws

    BadRequest if malformed. NotFound if callID doesn’t exist.

    Declaration

    Swift

    func answerPhoneCall(_ req: Request) async throws -> HTTPStatus

    Parameters

    callID

    in URL path. UUID for this call.

    Return Value

    200 OK on success

  • declinePhoneCall(_:) Asynchronous

    POST /api/v3/phone/decline/:call_ID

    Either party may call this to end a server-mediated phone call. But, if you have an open socket for the call, it’s easier to just close the socket–the server will detect this and close the other socket and clean up. Requester must be a party to the call.

    This route is for when a phone call needs to be ended and the client does not have a socket connection. May be used for both direct and server-mediated calls.

    Throws

    BadRequest if malformed. NotFound if callID doesn’t exist.

    Declaration

    Swift

    func declinePhoneCall(_ req: Request) async throws -> HTTPStatus

    Parameters

    callID

    in URL path. Caller-provided UUID for this call. Callee needs to send this to caller to verify the socket is for the correct call.

    Return Value

    200 OK on success

Utilities