Skip to content

Latest commit

 

History

History
523 lines (421 loc) · 10.2 KB

FORMAT.md

File metadata and controls

523 lines (421 loc) · 10.2 KB

Communicating with the Server

This file contains the guidelines to communicate with the server. Proper response, when possible, is sent by the server.

Table of Contents

Registration

  • The first message sent must be a login/registration request to the server when making a socket connection.
  • Failure to do so will result in error.
  • It should be a valid JSON message.
  • A new request should be made to generate a new OTP.

Client Registration Request

Begin Registration Process

When registering, NONE OF THE KEYS CAN BE NULL.

{
	"type": "registration",
	"details": {
		"email": "[email protected]",
		"password": "md5-hashed-password",
		"username": "xyz"
	}
}

Verify OTP

{
	"type": "verify",
	"otp": "1234"
}

Server Registration Response

OTP Sent

{
	"event": "sent",
	"type": "otp",
	"message": "OTP sent to [email protected]"
}

User is successfully registered

{
	"event": "success",
	"type": "verify"
}

Error why the registration failed

{
	"event": "failed",
	"type": "otp or registration or verify",
	"message": "Reason why the user was not registered"
}

NOTE: After successful registration, the user should be taken back to the login screen. The user will not be logged in after registration.

Login

  • The first message sent must be a login/registration request to the server when making a socket connection.
  • Failure to do so will result in error.
  • It should be a valid JSON message.

Client Login Request

Either the "username" or the "email"  key can be null, both cannot be null.

{
	"type": "login",
	"details": {
		"username": "xyz",
		"email": "[email protected]",
		"password": "md5-hashed-password"
	}
}

Server Login Response

if credentials found

  • The response data will contain the username and email address of the user.
  • The response data will also contain a list of all the users the user has previously contacted or has been contacted by.
{
	"event": "success",
	"type": "login",
	"details": {
		"username": "xyz",
		"email": "[email protected]",
		"friends": [
			{
				"email": "[email protected]",
				"username": "xyz"
			},
			{
				"email": "[email protected]",
				"username": "def"
			}
		]
	}
}

if credentials not found

{
	"event": "failed",
	"type": "login",
	"message": "Reason why user was not logged in"
}

Log-Out

  • The server won't end all I/O connections on logout, the connection should terminate ideally when the client application is not running.

Client Log-Out Request

{
	"type": "logout"
}

Server Log-Out Response

{
	"event": "success",
	"type": "logout"
}

Messages

  • This is the basic message conversation format.
  • The message layout of all messages are similar with some minor but important changes.

Global Message (This feature will be deprecated in the future.)

  • Used to communicate with all the users in the server, these messages are to be sent when the user wants to send the message to everyone.

Sending Message

Without media
{
	"event": "global",
	"type": "message",
	"details": {
		"message": "Hello World",
		"time": 1234567890
	}
}
With media
{
	"event": "global",
	"type": "message",
	"details": {
		"message": "Hello World",
		"media": "https://url-to-firestore/",
		"time": 1234567890
	}
}

Receiving Message

Receiving Messages without Media
{
	"event": "global",
	"type": "message",
	"details": {
		"message": "Hello World",
		"from": "[email protected]",
		"time": 1234567890
	}
}
Receiving Messages with Media
{
	"event": "global",
	"type": "message",
	"details": {
		"message": "Hello World",
		"media": "https://url-to-firstore",
		"from": "[email protected]",
		"time": 1234567890
	}
}

Personal Message

  • Also known as direct messages, these messages are to be sent when the user wants to send the message to only one specific user.

Sending Personal Message

Sending Personal Message without Media
{
	"event": "personal",
	"type": "message",
	"details": {
		"to": "[email protected]",
		"message": "Hello World",
		"time": 1234567890
	}
}
Sending Personal Message with Media
{
	"event": "personal",
	"type": "message",
	"details": {
		"to": "[email protected]",
		"message": "Hello World",
		"media": "https://url-to-firestore/",
		"time": 1234567890
	}
}

Receiving Personal Message

Receving Personal Message without Media
{
	"event": "personal",
	"type": "message",
	"details": {
		"id": "some-id",
		"message": "Hello World",
		"from": "[email protected]",
		"time": 1234567890
	}
}
Receiving Personal Message with Media
{
	"event": "personal",
	"type": "message",
	"details": {
		"id": "some-id",
		"message": "Hello World",
		"media": "https://url-to-firestore",
		"from": "[email protected]",
		"time": 1234567890
	}
}

Server Message Response

  • This is the standard response from the server when a personal message is sent.
  • No response is sent for Global Messages.
{
	"event": "sent",
	"type": "message",
	"id": "id-for-the-message"
}

User List

  • This will return a list of all the users registered to the server

Request

{
	"type": "users"
}

Response

{
	"event": "success",
	"type": "users",
	"details": [
		{
			"username": "xyz",
			"email": "[email protected]"
		},
		"List-of-objects"
	]
}

Audio Call

Placing a call

  • When placing a call, the current user must send the email address of the person he wants to call in the following format.
{
	"type": "voice",
	"event": "call",
	"details": {
		"email": "[email protected]"
	}
}

Receiving a call

  • The server will try to communicate with the recipient of the call by sending the following message.
{
	"type": "voice",
	"event": "request",
	"details": {
		"email": "[email protected]"
	}
}

Accepting a Call

  • For accepting the call, the recipient of the call should send the following response
{
	"type": "voice",
	"event": "accept",
	"details": {
		"email": "[email protected]"
	}
}

Rejecting a Call

  • For accepting the call, the recipient of the call should send the following response
{
	"type": "voice",
	"event": "reject",
	"details": {
		"email": "[email protected]"
	}
}

Call Time Out

  • The server will wait 30 seconds for a response from the recipient of the call.
  • If in that time, no response is received, the server will send the following response to the caller:
{
	"type": "voice",
	"event": "time",
	"details": {
		"email": "[email protected]"
	}
}
  • And the following response to the receiver:
{
	"type": "voice",
	"event": "time",
	"details": {
		"email": "[email protected]"
	}
}

Server Voice Call Response

If Call Accepted

  • When the receiver accepts the call, 2 responses are sent from the server
    1. To do the one who makes the call
    2. To the one who receives the call
  • The message contains the details of the IP Address and port over to which the UDP packets should be sent.
{
	"type": "voice",
	"event": "accept",
	"details": {
		"ip": "x.x.x.x",
		"port": "0000"
	}
}

If Call Rejected

  • If the receiver rejects the call the following response is sent to the caller.
{
	"type": "voice",
	"event": "reject",
	"details": {
		"email": "[email protected]"
	}
}

If Receiver is not Online

  • If the receiver is not available to take your call, the server will send the following response:
{
	"type": "voice",
	"event": "offline",
	"details": {
		"email": "[email protected]"
	}
}

Error

  • Whenever any error occurs, a response in this format will be sent by the server to the person requesting the service.
{
	"event": "invalid or failed",
	"type": "type-of-request-made",
	"message": "A message regarding the event."
}