Skip to content

Instantly share code, notes, and snippets.

@erkanarslan
Last active November 13, 2018 13:30
Show Gist options
  • Save erkanarslan/acdcb25e08aa3fceb1501fb333a8be3a to your computer and use it in GitHub Desktop.
Save erkanarslan/acdcb25e08aa3fceb1501fb333a8be3a to your computer and use it in GitHub Desktop.

General API Structure

All request endpoint urls start with api/. Data is sent and received as JSON objects. All request data is sent in the request body if not specified otherwise. You should return 200 for success responses and any code that starts with 4 for error responses.

Date values should be sent and received as unix timestamps in milliseconds.

Websocket

All live data sent over websocket. We will have a single connection. Thus a data format is necessary to differentiate the data. This is the data format:

{
	type : string,		// camera-stream, firmware-update, etc. We should decide on these.
	data : any		// Put data here. It can by anything: number, string, object etc.
}

Camera Stream

Camera stream is sent in this format. I assume that frame/image encoding is JPEG. Data format:

{
	type : 'camera-stream',
	data : string		// base64 string
}

Device Info

System statistics are shown in this format.

{
	type : 'device-info',
	data : {
		cpu : number,		// CPU usage. 0 to 100
		ram : number,		// RAM usage in KB
		ramMax : number,	// RAM capacity in KB
		swap : number,		// RAM usage in KB
		swapMax : number,	// Swap capacity in KB
		disk : number,		// Disk usage in KB
		diskMax : number,	// Disk capacity in KB
		systemTime : number,	// Timestamp in ms,
		systemUptime : number,	// In seconds
	}
}

Process Info

Process statistics are shown in this format.

{
	type : 'process-info',
	data : [{
		id : number,
		serviceUptime : number,		// In seconds
		isRunning : boolean
	}]
}

Firmware Update

You can send update related activity logs in these objects. I will show them directly in the ui.

{
	type : 'firmware-update',
	data : string
}

Session Management

Login

POST : api/login

Request Data:

{
	username : string,
	password : string
}

Response Data: No data needed. Just send session id in cookie with sessionID key.

Logout (Not urgent)

POST : api/logout

Request Data: none

Response Data: none

Home Page

Get Home Page Details

GET : api/home/page

Request Data: none

Response Data:

{
	version : string,		// Firmware version
	city : string,
	junction : string,		// Junction name
	cameras : [{
		id : number,		// Camera process id
		direction : string,	// Name of the direction/street
	}]
}

Camera Stream

Get Camera Stream List

Get the list of stream names and their translations for all processes.

GET : api/stream/list

Request Data: none

Response Data:

[{
	processId : number,
	streamId : number,
	name : string,
	label : {
		tr : string,	// This will be shown in the UI if language is Turkish
		en : string
		...
	}
}]

Start Stream

You should allow stream from only one process. If there is an active stream when a start request is sent, stop it.

POST : api/stream/start

Request Data:

{
	processId : number,
	streamId : number,
	name : string		// Name of the stream
}

Stop Stream

If a user closes the browser, I cannot send a stop request. You need to end the stream when websocket connection ends.

POST : api/stream/stop

Request Data: no data

Response Data: no data

Set Stream Quality

Set quality for current session. I may start and stop streams. All of them should use the same quality value until websocket connection ends.

PUT : api/stream/quality

Request Data:

{
	value : number		// From 0 to 100
}

Response Data: no data

Settings

Get Network Settings

GET : api/settings/network

Request Data: none

Response Data: An object containing all network settings or array of them

Get Time Settings

GET : api/settings/time

Request Data: none

Response Data: An object containing all time settings or array of them

Set Time Settings

PUT : api/settings/time

Request Data: An object containing time settings

Response Data: none

Set Network Settings

PUT : api/settings/network

Request Data: An object containing network settings

Response Data: none

Reset to Factory Settings

POST : api/settings/reset

Request Data: none

Response Data: none

Services

Get Services and Their Statuses

GET : api/services/list

Request Data: none

Response Data:

[{
	id : number,
	alias : string,
	isRunning : bool,
	isEnabled : bool
}]

Restart Service

POST : api/services/:serviceId/restart

Request Data: none

Response Data: none

Enable Service

POST : api/services/:serviceId/enable

Request Data: none

Response Data: none

Disable Service

POST : api/services/:serviceId/disable

Request Data: none

Response Data: none

Device Management

Upload New Firmware

Uploads given file as firmware

PUT : api/firmware

Request Data:

Data format is FormData. File is sent in file property.

Response Data: none

Start System Status Stream

POST : api/device/start-live-device-info

Request Data: none

Response Data: no data

Stop System Status Stream

POST : api/device/stop-live-device-info

Request Data: no data

Response Data: no data

Restart Device

It would be better if you send the response first, then restart the device. Otherwise I cannot know if operation failed or succeeded.

POST : api/device/restart

Request Data: none

Response Data: none

Logs

Get Log Stream List

There are multiple streams where logs can be sent. This request gets the list of stream names with their labels in different languages.

GET : api/logs/streams

Request Data: none

Response Data:

[{
	name : string,		// Name of the string
	label : {
		tr : string,	// This is the title that user will see in Turkish
		en : string,	// Title in English
		<language code> : string	// You can add labels for other languages as well.
	}
}]

Get Logs

You can view or download logs by using this endpoint. download parameter will decide this.

GET : api/logs/process/:processId

Request Data: none

Response Data: A file download response should be sent

General Endpoints

Check If Device Can Access to an NTP Server

POST : api/app/check-ntp-server-access

Request Data:

{
	ip : string
}

Response Data:

{
	hasAccess : boolean
}

Get General Device Info

GET : api/app/device-info

Request Data: none

Response Data:

{
	system : 'chaos' | 'pts' | 'epics'
}

Cameras (Physcial Cameras)

Get List of Physical Cameras

GET : api/cameras/list

Request Data: none

Response Data:

[{
	id : number,
	direction : string	// Direction of the camera so that we can know which one is which.
}]

Get Camera Settings

GET : api/cameras/:id/settings

Request Data: none

Response Data: An object described in meta-data

Update Camera Settings

PUT : api/cameras/:id/settings

Request Data: An object described in meta-data

Response Data: none

Processes (Camera Processes)

This is the ROI data format. Point coordinates are not pixel values. They are relative values between 0 and 1. 0 corresponds to left or top of the frame and 1 corresponds to right or bottom of the frame.

{
	id : number,
	regions : [{
		points : [ [x1, y1], [x2, y2] ... ],
		weight : number,
		laneCount : number
	}],
	countingLine : [ [x1, y1], [x2, y2] ]
}

Get Process Details and Settings

GET : api/processes/list

Request Data: None

Response Data:

[{
	id : number,
	direction : string,	// Name of the camera direction,
	settings : object	// An object defined in meta-data file,
	rois : ROI[]
}]

Create Process

POST : api/processes/list

Request Data:

{
	vieroId : number
}

Response Data:

{
	id : number,
	vieroId : number,
	direction : string
}

Delete Process

DELETE : api/processes/list/:processId

Request Data: None

Response Data: None

Update Process Settings

PUT : api/processes/:processId/settings

Request Data: An object containing process settings

Response Data: An object containing processff settings

Update Process ROIs

ROIs are updated as a whole. When a ROI is deleted or a new one added, we update whole roi list.

PUT : api/processes/:processId/rois

Request Data: A list of objects which contain roi details

Response Data: none

Get Process Photos

GET : api/processes/:processId/photos

Request Data: Sent as query parameters

{
	limit : number,		// Number of photos to return, for pagination
	skip : number,		// Number of photos to skip, for pagination
}

Response Data:

[{
	id : number,
	plate : string,
	date : string,		// Unix timestamp in milliseconds
	path : string,		// Path relative to root public directory
}]

Delete Process Photo

DELETE : api/processes/:processId/photos/:photoId

Request Data: none

Response Data: none

Get Process Videos

GET : api/processes/:processId/videos

Request Data: Sent as query parameters

{
	limit : number,		// Number of videos to return, for pagination
	skip : number,		// Number of videos to skip, for pagination
}

Response Data:

[{
	id : number,
	start : number,		// Video start date in ms
	end : number,		// Video end date in ms
	path : string,
	type : string		// processed, unprocessed etc.
}]

Delete Process Video

DELETE : api/processes/:processId/videos/:videoId

Request Data: none

Response Data: none

Get Video Record Schedule

GET : api/processes/:processId/video-schedule

Request Data: None

Response Data:

[{
	id : number,		// You should put id or any idendification info on these so that we can delete or update them
	start : number,
	end : number,
	type : number
}]

Create Scheduled Task to Record Video

POST : api/processes/:processId/video-schedule

Request Data:

{
	start : number,		// timestamp in ms. recording should start at this moment
	end : number,		// timestamp in ms. recording should stop at this moment
	type : string		// Recording type
}

Response Data:

{
	id : number,		// You should put id or any idendification info on these so that we can delete or update them
	start : number,
	end : number,
	type : string
}

Delete Scheduled Recording

Can we delete a scheduled recording while video is being recorded at that time?

DELETE : api/processes/:processId/video-schedule/:taskId

Request Data: none

Response Data: none

Start Process Status Stream

POST : api/processes/start-live-status-stream

Request Data: none

Response Data: no data

Stop Process Status Stream

POST : api/processes/stop-live-status-stream

Request Data: no data

Response Data: no data

Stream Sources

Stream sources for chaos processes. Get list, create, update, delete. Stream sources are update via meta-data forms. Because of that properties of streams aren't listed here. You can define them as you like.

Get Stream List

GET : api/streams/list

Request Data : none

Response Data : List of objects. Results should contain id, resourceType and resource properties to show them in the list.

Create Stream

POST : api/streams/list

Request Data : An object containing stream details.

Response Data : none

Update Stream

PUT : api/streams/list/:streamId

Request Data : An object containing stream details.

Response Data : none

Delete Stream

DELETE : api/streams/list/:streamId

Request Data : none

Response Data : none

Centris Settings

Get IP, Port and Viero List for each Centris

GET : api/centris-settings/page

Request Data : none

Response Data : Centris and Viero lists. Centris list is a list of centris ip and ports. Each record contains the list of vieros which send data to that centris.

{
	centrises : [{
		ip : string,		// IP of the centris
		port : number,		// Port of the centris
		vieros : number[]	// List of ids of vieros which send data to this centris
	}],
	vieros : [{
		id : number,
		direction : string	// Direction/name of viero
	}]
}

Save IP, Port and Viero List for each Centris

PUT : api/centris-settings

Request Data :

[{
	ip : string,		// IP of the centris
	port : number,		// Port of the centris
	vieros : number[]	// List of ids of vieros which send data to this centris
}]

Response Data : none

PTS Settings

Get PTS Settings

GET : api/pts-settings

Request Data : none

Response Data :

{
	ftpSettings : object,		// An object containing ftp settings
	processes : [{
		id : number,		// Viero/process id
		direction : string,	// Name of the viero/process direction
		processorSettings : object,	// An object containing processor settings
		typeBrandSettings : object	// An object containing type-brand settings
	}]
}

Set PTS FTP Settings

PUT : api/pts-settings/ftp-settings

Request Data : An object containing ftp settings

Response Data : None

Set PTS Processor Settings

PUT : api/pts-settings/processes/:processId/processor

Request Data : An object containing processor settings

Response Data : none

Set PTS Type-Brand Settings

PUT : api/pts-settings/processes/:processId/type-brand

Request Data : An object containing type-brand settings

Response Data : none

Meta Data

Get Meta Data For a Form

Form name is sent in the url. It can be one of these values : time, network, process, centris, pts. I will create the initial versions of these pages. You can modify them whenever you need.

GET : api/meta-data/:formName

Request Data : none

Response Data : An object containing form metadata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment