Overview
Communication between ClearLine’s Customer-Facing Screen (CFS) and third-party POS systems (e.g., Clover, PAX) is implemented via JavaScript iframe events using thewindow.postMessage() API. This enables seamless interaction between the CFS application running in an iframe and the parent POS system.
Event Model
All events follow a standardized TypeScript interface:Event Types
Sending Events
Events are sent using the standard postMessage API:Usage
The target origin is set to
"*" for compatibility across different POS system domains. Implement additional validation in production environments as needed.Output Events (CFS → POS System)
These events are sent from the CFS application to the external POS system.init
Triggered when the CFS application completes initialization. This event signals that the CFS is ready to receive messages.
Event Data
| Field | Type | Description |
|---|---|---|
| projectName | string | Static string “cfs” – identifies the source project |
buttonClick
Emitted when a button is clicked in the CFS application. Commonly used to request external hardware scanner usage (e.g., for customer check-in).
Event Data
| Field | Type | Description |
|---|---|---|
| targetId | string | HTML element ID of the clicked button (e.g., “scan”) |
| buttonId | string | Deprecated. Legacy support only (use targetId instead). |
inputFocus
Emitted when an input field in the CFS gains focus. Use this event to notify the external POS to prepare for login or check-in actions.
Event Data
| Field | Type | Description |
|---|---|---|
| targetId | string | HTML element ID of the input field (e.g., “search”) |
| inputId | string | Deprecated. Legacy support only (use targetId instead). |
inputBlur
Emitted when an input field in the CFS loses focus.
Event Data
| Field | Type | Description |
|---|---|---|
| targetId | string | HTML element ID of the input field (e.g., “search”) |
| inputId | string | Deprecated. Legacy support only (use targetId instead). |
Input Events (POS System → CFS)
These events are sent from the external POS system to the CFS application.formSubmitted
Instructs the CFS to close the current iframe window, typically after a form has been submitted externally (e.g., in a CFS Template iframe).
Event Data
No additional parameters required.userActivity
Used to prolong user activity inside the iframe and prevent inactivity prompts (e.g., “Are you still here?” dialogs).
Event Data
No additional parameters required.setWindowClass
Previously used to set CSS class on the iframe window.
scanCompleted
Delivers the result of an external hardware scan (barcode, QR code, username, email). Commonly used for customer login or check-in workflows.
Event Data
| Field | Type | Description |
|---|---|---|
| data | string | String value representing scan result (username, code, email) |
The CFS application will automatically process the scanned value and populate the appropriate input field or trigger the login/check-in flow.
scanCancelled
Indicates cancellation of a scan request. When received, the CFS typically:
- Shows a toast notification to the user
- Resets the scan state
- May resend a cancellation acknowledgment to the external system
Event Data
No additional parameters required.Event Flow Examples
Customer Check-In Flow
Customer Check-In Flow
Typical event sequence for customer check-in:
- CFS → POS:
buttonClick(user clicks scan button) - POS activates scanner
- POS → CFS:
scanCompleted(with scanned email/phone) - CFS processes check-in
- CFS → POS:
buttonClick(user clicks scan button) - POS activates scanner
- User cancels scan
- POS → CFS:
scanCancelled - CFS shows cancellation message
Form Interaction Flow
Form Interaction Flow
Typical event sequence for form interaction:
- CFS → POS:
inputFocus(user focuses on input field) - POS prepares for input (e.g., shows keyboard)
- User enters data and submits
- POS → CFS:
formSubmitted - CFS closes iframe/modal
Keep-Alive Flow
Keep-Alive Flow
Preventing inactivity timeouts:
- POS → CFS: Send
userActivityevents periodically - CFS resets inactivity timer
- Prevents “Are you still here?” prompts
Implementation Guide
Set Up Event Listener
In your POS system, add a message event listener to receive events from the CFS:
Best Practices
Validate Event Origin
In production, validate the event origin instead of accepting all origins (
"*").Error Handling
Implement robust error handling for message parsing and event processing.
Type Safety
Use TypeScript interfaces to ensure type safety for event data.
Event Logging
Log all events during development to debug integration issues.