Skip to content

feat: Cast client#2680

Open
mbellehumeur wants to merge 20 commits into
cornerstonejs:mainfrom
mbellehumeur:feat/cast
Open

feat: Cast client#2680
mbellehumeur wants to merge 20 commits into
cornerstonejs:mainfrom
mbellehumeur:feat/cast

Conversation

@mbellehumeur
Copy link
Copy Markdown
Contributor

@mbellehumeur mbellehumeur commented Mar 30, 2026

Context

Cast package - @cornerstonejs/cast

Cast hub networking for browser-based viewers: OAuth client-credentials token, HTTP subscribe/unsubscribe, WebSocket receive, and publish. This package contains transport only; application-specific message handling stays in the host app to implement FHIRcast or other messaging. Handles token acquisition, subscribe/unsubscribe lifecycle, websocket message processing, publish, websocket heartbeats , message echo and optional auto-reconnect of the websocket.

Example

The Cast client example under examples/castClient mirrors the python Slicer Cast test-client.html flow (subscribe, log incoming events, publish) using CastClient for all network calls.

From the monorepo root:

yarn example castClient

Optional query parameter: ?topic=your-topic pre-fills the topic fields.

Example:

const client = new CastClient({
  hub: {
    name: 'demo',
    version: '1',
    hub_endpoint: 'https://host/api/hub',
    token_endpoint: 'https://host/oauth/token',
    client_id: 'client_id',
    client_secret: 'client_secret',
  },
  session: {
    events: ['*'],
    lease: 7200,
    subscriberName: 'CS3D-EXAMPLE',
    topic: 'my-topic',
  },
  autoReconnect: true,
});

client.onMessage((message) => {
  console.log(message);
});

 const tokenOk = await client.getToken();
 if (tokenOk) {
   await client.subscribe();
   await client.publish({
     event: {
       'hub.event': 'custom',
       'hub.topic': 'my-topic',
       context: [],
     },
   });
 }

Changes & Results

Testing

yarn run example castClient

online test:

https://cs3d-castclientexample-anczasf2c7fghhgp.westeurope-01.azurewebsites.net/castClient

Screen.Recording.2026-04-05.175423.mp4
  • Click Authenticate to obtain a user id and access token (use ?topic= to choose a mock user id).
  • Click Subscribe to open a WebSocket connection and start receiving events from the hub.
  • Click Open viewer with this topic button to open an image display in the workflow.
  • Click Publish to send an ImagingStudy-open event to the hub -> the study opens in the image display.
  • Change the event to dicom-send and click Publish to send an AI result SEG object to the hub -> the result is displayed in the image display.
  • Use Get to fetch context from a FHIRCast hub or other data from cast compliant IHE actors (in this case the worklist-client).
  • Change the event to ImagingStudy-close and click Publish to send an ImagingStudy-close event to the hub -> the image display goes back to home screen.
  • Use Collaborate to open a conference client to create a multi-topic session.

Checklist

PR

  • My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

  • My code has been well-documented (function documentation, inline comments,
    etc.)

Public Documentation Updates

  • The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • "OS: Windows/Chrome

…dling

- Updated the title and description in the setTitleAndDescription function for consistency.
- Changed the casing of "Cast Client" to "Cast client" for uniformity.
- Replaced direct DOM element retrieval with stored references for button elements to enhance readability and maintainability.
- Removed unused 'agfa' hub configuration and related code.
- Improved the refreshDerivedUrls function comment for clarity.
…ibe actors

- Updated the default subscribe actors JSON to include "WATCHER".
- Refactored the header layout for improved visual structure and consistency.
- Adjusted CSS styles for better alignment and spacing of elements.
- Enhanced the connection controls section for a more intuitive user experience.
- Redesigned the header layout to utilize a grid structure for better alignment.
- Increased font size and weight for the header title for improved visibility.
- Introduced a new center section in the header for status display.
- Enhanced the connection controls section with a more intuitive grid layout for authentication options.
- Updated CSS styles for better spacing and responsiveness across elements.
…UI structure

- Renamed CSS classes from `.cast-demo` to `.cast` for better clarity and consistency.
- Maintained existing styles while enhancing the overall UI layout.
- Ensured that the new class structure aligns with previous design improvements for a cohesive user experience.
…ences

- Added a new info section with detailed instructions for users on selecting a hub and authenticating.
- Updated the variable names for clarity, changing 'root' to 'content' for better readability.
- Improved CSS class structure while maintaining existing styles for a cohesive UI experience.
…d session settings

- Introduced a new `SessionConfig` interface to manage session-specific values separately from hub configurations.
- Updated `CastClient` to utilize the new configuration structure, enhancing clarity and maintainability.
- Modified example usage in README and code to reflect the new configuration format, improving user guidance.
- Revised README to clarify the role of the package and specify the example's relation to the Python Slicer Cast.
- Simplified comments in CastClient to enhance understanding of its functionality.
- Updated the token handling logic to set the topic and subscriber name based on the received data.
- Introduced a check for a trimmed topic string before assigning the subscriber name, improving clarity and functionality.
- Bumped versions of several packages from 4.19.2 to 4.20.0 for consistency.
- Added configVersion to the lockfile for improved configuration management.
… to version 4.20.0

- Updated peer dependencies for multiple packages to ensure consistency with the latest version of @cornerstonejs libraries.
- Introduced a new dependency 'all' with version ^0.0.0 in both package.json and bun.lock for improved package management.
…n and bun.lock

- Upgraded multiple dependencies to their latest versions for improved performance and security.
- Ensured consistency across package.json and bun.lock files by aligning dependency versions.
- Removed outdated versions of Babel packages and consolidated to the latest versions for improved performance and compatibility.
- Ensured consistency in dependency versions across the lockfile.
…ctor keyword

- Changed the default actor keyword for Get requests from 'HUB' to 'WORKLIST_CLIENT' for consistency.
- Enhanced the handling of Get responses by introducing a structured payload that includes subscriber name and response data.
- Improved the subscription actor handling by consolidating actor strings into a JSON array format for better data management.
…he UI

- Introduced 'dicom-update' as a new event type in the publish section dropdown.
- Added 'DICOM' as a selectable data type in the get section dropdown.
- Updated instructions for authentication to clarify the use of a mock user ID.
@mbellehumeur mbellehumeur changed the title [WIP] Feat/Cast client Feat/Cast client Mar 31, 2026
@mbellehumeur mbellehumeur changed the title Feat/Cast client feat: Cast client Mar 31, 2026
@sedghi
Copy link
Copy Markdown
Member

sedghi commented Apr 5, 2026

I'm not sure why this is in cornerstone. Cornerstone scope is limited and described here https://www.cornerstonejs.org/docs/getting-started/scope

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants