Skip to content

Commit

Permalink
Fix compatibility with latest SkyChat client & Publish v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
7PH committed May 15, 2024
1 parent 10663c3 commit f4a5c60
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 103 deletions.
134 changes: 127 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "skychat-cli",
"version": "0.3.1",
"version": "0.4.0",
"description": "Connect to a SkyChat instance using CLI",
"main": "lib/index.js",
"type": "module",
Expand All @@ -24,7 +24,7 @@
"fs-extra": "^11.2.0",
"minimist": "^1.2.8",
"risibank-web-api": "^1.1.0",
"skychat": "^1.3.0",
"skychat": "^2.0.1",
"slugify": "^1.6.6"
},
"devDependencies": {
Expand Down
24 changes: 13 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { SkyChatClient } from 'skychat';
import { getOptions } from './options.js';
import { SkyChatCLI } from './render/SkyChatCLI.js';
import { connect, getEndPointUrl } from './skychat.js';
import { loadToken } from './token.js';
import { SkyChatOption, SkyChatOptions } from './types.js';

export function getEndPointUrl(protocol: string, host: string): string {
return `${protocol}://${host}/ws`;
}

export async function main() {
const options = getOptions();

Expand All @@ -21,25 +24,24 @@ export async function main() {
}

async function autoConnect(client: SkyChatClient, options: SkyChatOptions) {
// Wait for the client to connect
await new Promise<void>((resolve) => {
client.connect();
client.once('update', resolve);
});

if (options[SkyChatOption.User] && options[SkyChatOption.Password]) {
await connect(client, {
mode: 'credentials',
user: options[SkyChatOption.User],
password: options[SkyChatOption.Password],
});
client.login(options[SkyChatOption.User], options[SkyChatOption.Password]);
return;
}

const token = await loadToken();
if (token) {
await connect(client, {
mode: 'token',
client.authenticate({
token,
});
return;
}

await connect(client, {
mode: 'guest',
});
client.authAsGuest();
}
11 changes: 5 additions & 6 deletions src/render/SkyChatCLI.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { SkyChatClient } from 'skychat';
import { Page } from './page/Page.js';
import { LogInPage } from './page/LogInPage.js';
import { ChatPage } from './page/ChatPage.js';
import { saveToken } from '../token.js';
import blessed from 'blessed';
import { SkyChatClient } from 'skychat';
import { SCREEN_TITLE } from '../constants.js';
import { saveToken } from '../token.js';
import { ChatPage } from './page/ChatPage.js';
import { LogInPage } from './page/LogInPage.js';
import { Page } from './page/Page.js';

enum CurrentPage {
login = 'login',
Expand All @@ -22,7 +22,6 @@ export class SkyChatCLI {
this.screen = blessed.screen({ title: SCREEN_TITLE });

this.currentPage = new LogInPage(client, this.screen);
this.render();

this._bind();
}
Expand Down
6 changes: 3 additions & 3 deletions src/render/component/MessageList.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import blessed from 'blessed';
import { BOX_DEFAULT_OPTIONS } from '../../constants.js';
import { Component } from './Component.js';
import { SanitizedMessage } from 'skychat/build/server';
import { Page } from '../page/Page.js';
import { BOX_DEFAULT_OPTIONS } from '../../constants.js';
import { renderMessage } from '../helper/message.js';
import { Page } from '../page/Page.js';
import { Component } from './Component.js';

export class MessageList extends Component<blessed.Widgets.BoxElement> {
protected readonly messages: SanitizedMessage[] = [];
Expand Down
Loading

0 comments on commit f4a5c60

Please sign in to comment.