Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real-time: Extend socket state events with current status #107

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/real-time-client-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@speechmatics/real-time-client-react",
"version": "0.0.3",
"version": "0.0.4",
"description": "React hooks for interacting with the Speechmatics Real-Time API",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down
7 changes: 1 addition & 6 deletions packages/real-time-client/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@

# Speechmatics real-time client 🎤

> [!WARNING]
> This package is still in beta. It should be as functional as the legacy package, but some behaviour may have changed.

Official JS client for the Speechmatics batch jobs API.
Official JS client for the Speechmatics real-time transcription API.

API documentation can be found here: https://docs.speechmatics.com/rt-api-ref

Expand All @@ -19,8 +16,6 @@ npm i @speechmatics/real-time-client

## Usage



More examples will be available soon. For now, you can checkout the [NodeJS example](/examples/nodejs/real-time-file-example.ts).

### API keys 🔑
Expand Down
2 changes: 1 addition & 1 deletion packages/real-time-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@speechmatics/real-time-client",
"version": "5.0.7",
"version": "5.0.8",
"description": "Client for the Speechmatics real-time API",
"main": "dist/index.js",
"browser": "dist/index.browser.js",
Expand Down
19 changes: 9 additions & 10 deletions packages/real-time-client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,16 @@ export type RealtimeServerMessage =
| Warning
| ModelError;

export type ConnectionState =
| 'idle'
| 'connecting'
| 'starting'
| 'running'
| 'stopping';
export class SocketStateChangeEvent extends Event {
constructor(public readonly socketState: RealtimeClient['socketState']) {
super('socketStateChange');
}
}

export interface RealtimeClientEventMap {
sendMessage: MessageEvent<RealtimeClientMessage>;
receiveMessage: MessageEvent<RealtimeServerMessage>;
socketStateChange: Event;
socketStateChange: SocketStateChangeEvent;
}

export interface RealtimeClientOptions {
Expand Down Expand Up @@ -116,7 +115,7 @@ export class RealtimeClient extends TypedEventTarget<RealtimeClientEventMap> {
this.socket = new WebSocket(url.toString());
this.dispatchTypedEvent(
'socketStateChange',
new Event('socketStateChange'),
new SocketStateChangeEvent(this.socketState),
);

this.socket.addEventListener(
Expand All @@ -130,7 +129,7 @@ export class RealtimeClient extends TypedEventTarget<RealtimeClientEventMap> {
this.socket.addEventListener('error', (error) => {
this.dispatchTypedEvent(
'socketStateChange',
new Event('socketStateChange'),
new SocketStateChangeEvent(this.socketState),
);
// In case the above hasn't resolved, we can reject here rather than waiting
// If the above has resolved, this will be ignored
Expand All @@ -140,7 +139,7 @@ export class RealtimeClient extends TypedEventTarget<RealtimeClientEventMap> {
this.socket.addEventListener('close', () => {
this.dispatchTypedEvent(
'socketStateChange',
new Event('socketStateChange'),
new SocketStateChangeEvent(this.socketState),
);
});

Expand Down