-
Notifications
You must be signed in to change notification settings - Fork 47
RSDK-3015 - Fix streamStatus #80
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems okay - just some minor changes.
In addition, let's codify your testing example as a unit test:
let stream = robot.streamStatus([], new Duration().setNanos(500_000_000));
stream.on('data', (response: VIAM.robotApi.Status[]) => {
console.log(response);
});
stream.on('status', (newStatus?: { details: unknown }) => {
console.error('error streaming robot status', newStatus);
});
stream.on('end', () => {
console.error('done streaming robot status');
});
src/responses.ts
Outdated
import type { ResponseStream } from './gen/robot/v1/robot_pb_service'; | ||
|
||
export class IResponseStream<T> extends EventDispatcher { | ||
private stream: ResponseStream<any>; | ||
|
||
constructor(stream: ResponseStream<any>) { | ||
super(); | ||
this.stream = stream; | ||
} | ||
|
||
override on( | ||
type: string, | ||
handler: (message: any) => void | ||
): IResponseStream<T> { | ||
super.on(type, handler); | ||
return this; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import type { ResponseStream } from './gen/robot/v1/robot_pb_service'; | |
export class IResponseStream<T> extends EventDispatcher { | |
private stream: ResponseStream<any>; | |
constructor(stream: ResponseStream<any>) { | |
super(); | |
this.stream = stream; | |
} | |
override on( | |
type: string, | |
handler: (message: any) => void | |
): IResponseStream<T> { | |
super.on(type, handler); | |
return this; | |
} | |
import type { ResponseStream as ProtoResponseStream } from './gen/robot/v1/robot_pb_service'; | |
export class ResponseStream<T> extends EventDispatcher { | |
private stream: ProtoResponseStream<any>; | |
constructor(stream: ProtoResponseStream<any>) { | |
super(); | |
this.stream = stream; | |
} | |
override on( | |
type: string, | |
handler: (message: any) => void | |
): ResponseStream<T> { | |
super.on(type, handler); | |
return this; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this isn't an interface, let's just call it ResponseStream
and alias the raw proto version. if you agree let's follow this pattern for the rest of this PR.
Also, we should export this type in main to make it available to users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed the class to ViamResponseStream
(but did not export) and added alias for RobotStatusStream
Co-authored-by: maximpertsov <[email protected]>
Co-authored-by: maximpertsov <[email protected]>
@maximpertsov this was tested using the sample code from app and adding the bit I wrote above |
@@ -1,4 +1,4 @@ | |||
export type { Robot } from './robot/robot'; | |||
export type { Robot, RobotStatusStream } from './robot/robot'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should export this in src/main.ts
as well so users have access to this type
status stream used to not work at all, reworked so it works? maybe.
pretty open to suggestions as to where I should be putting the new class, and its name, but all it is is a concrete impl of ResponseStream leveraging the existing EventDispatcher class.
tested using the below block