Skip to main content

Web Socket Integration

Overview

This section outlines the capabilities of the WebSocket integration, which facilitates seamless integration with the Android Aladdin application. Intent integration provides a sophisticated communication model, enabling developers to efficiently receive and manage scanned data. With built-in functionalities for two-way communication between the server and client, developers gain a professional and adaptable solution for incorporating scanned data into their applications.

WebSocket Integration in Aladdin

The Aladdin server runs on localhost and provides a configurable port address.

  1. Select the Web socket option in the Integration UI of Aladdin app.

  2. A dialog box asking for port address will appear. You must enter a valid port number. Please use a port address between 1024 to 65535. Default port address is 8000.

  3. Tap "Done" to initialize the server.

Events / Messages

Events / messages will be communicated between the Aladdin app and the client app using JSON protocol. Below is a description of the events and JSON structure supported in Aladdin.

Event: connection_status

The connection status event is used to notify the client about the connection state between the scanner and the Aladdin app (status can be requested by client).

JSON fields:

NameTypeDescription
event_typeStringThe event type
statusBooleanThe connection status of the CODiScan to the Aladdin app

Example:

{
"event_type": "connection_status",
"status": true,
}

Event: scan

The Scan event is used to notify the client of a barcode scan from Aladdin (latest scanned barcode data can be requested by client).

JSON fields:

NameTypeDescription
event_typeStringThe event type ()
scan_timeLongThe time in milliseconds of the scan event (based on current device time)
scan_codeStringThe barcode content
scan_code_typeStringThe barcode type

Example:

{
"event_type": "scan",
"scan_time": 1705048949979,
"scan_code": "ABC",
"scan_code_type": "Code-128"
}

Message: connectionState

The client can request the latest scanned barcode data by sending a JSON object to the server in the following form:

{ "event_type": "connectionState" }

This will result in the server responding with a connection status event message.

Message: lastBarcode

The client can request the latest scanned barcode data by sending a JSON object to the server in the following form:

{ "event_type": "lastBarcode" }

This will result in the server responding with a scan event message.

WebSocket Sample Client

The Aladdin WebSocket client is a purposefully crafted sample application designed to showcase the dynamic capabilities of the WebSocket integration.

info

The client APK and source code can be found in the Aladdin samples repository on Github.

  1. Open the WebSocket client application and tap Connect to server. A dialog box asking for port address will appear. Please, enter the same port address you entered in Aladdin application.

  2. Once connected to the server, you can receive events whenever a barcode is scanned by the CODiScan and the CODiScan is connected to the Aladdin app.

  3. Tap Get latest barcode to get the last barcode scanned by the CODiScan.

  4. Tap Get scanner status to get the CODiScan connection status with the Aladdin app. Status value will be true if CODiScan is connected to Aladdin, false if it is not connected.

  5. Tap Disconnect from server to close the socket and stop the communication between the client and the Aladdin app.