Skip to content

Commit

Permalink
feat(protocol): added feature flag properties for channel objects
Browse files Browse the repository at this point in the history
  • Loading branch information
fenying committed Jun 30, 2024
1 parent 59d1e1a commit 2e9eba3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v1.1.0

- feat(protocol): added experimental supports for transports between worker thread.
- feat(protocol): added feature flag properties for channel objects.
- fix(protocol): simplified the ITransporter.end method.
- fix(decoder): should decode protocol error as special error.
- fix(protocol): put protocol-error code in server_internal_server data.
Expand Down
5 changes: 5 additions & 0 deletions src/examples/shared/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export const router: Tv.Servers.IRouter = new Tv.Servers.SimpleJsonApiRouter()

serverLogs.ok(`Channel#${ctx.channel.id} invoked sendMeMessage with message: ${msg}`);

if (!ctx.channel.isMessageSupported) {

throw new Tv.errors.cmd_not_impl();
}

ctx.channel.sendMessage(msg).catch(e => serverLogs.error(`Failed while sending message, error: ${e}`));
})
.registerApi('sendMeMessageAsync', async (ctx, msg: string): Promise<void> => {
Expand Down
4 changes: 4 additions & 0 deletions src/lib/server/LegacyServerChannel.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class TvLegacyServerChannelV1 extends EventEmitter implements Shared.ICha

public get writable(): boolean { return false; }

public get isMessageSupported(): boolean { return false; }

public get isBinaryStreamSupported(): boolean { return false; }

public get id(): number { return 0; }

public get timeout(): number { return 30_000; }
Expand Down
4 changes: 4 additions & 0 deletions src/lib/shared/Channel.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export abstract class AbstractTvChannelV2

public ended: boolean = false;

public get isMessageSupported(): boolean { return true; }

public get isBinaryStreamSupported(): boolean { return this.streams.maxStreams !== 0; }

public get finished(): boolean {

return this._state === EState.ENDED;
Expand Down
10 changes: 10 additions & 0 deletions src/lib/shared/Shared.decl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ export interface IChannelBase<TEvents extends IDefaultEvents> extends IEventList
*/
readonly transporter: ITransporter;

/**
* Whether this channel supports server-push messages or not.
*/
readonly isMessageSupported: boolean;

/**
* Whether this channel supports binary streams or not.
*/
readonly isBinaryStreamSupported: boolean;

/**
* Tells whether this channel is closed on the local side or not.
*/
Expand Down

0 comments on commit 2e9eba3

Please sign in to comment.