Skip to content

Commit f4a5c60

Browse files
committed
Fix compatibility with latest SkyChat client & Publish v0.4.0
1 parent 10663c3 commit f4a5c60

6 files changed

Lines changed: 150 additions & 103 deletions

File tree

package-lock.json

Lines changed: 127 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "skychat-cli",
3-
"version": "0.3.1",
3+
"version": "0.4.0",
44
"description": "Connect to a SkyChat instance using CLI",
55
"main": "lib/index.js",
66
"type": "module",
@@ -24,7 +24,7 @@
2424
"fs-extra": "^11.2.0",
2525
"minimist": "^1.2.8",
2626
"risibank-web-api": "^1.1.0",
27-
"skychat": "^1.3.0",
27+
"skychat": "^2.0.1",
2828
"slugify": "^1.6.6"
2929
},
3030
"devDependencies": {

src/index.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { SkyChatClient } from 'skychat';
22
import { getOptions } from './options.js';
33
import { SkyChatCLI } from './render/SkyChatCLI.js';
4-
import { connect, getEndPointUrl } from './skychat.js';
54
import { loadToken } from './token.js';
65
import { SkyChatOption, SkyChatOptions } from './types.js';
76

7+
export function getEndPointUrl(protocol: string, host: string): string {
8+
return `${protocol}://${host}/ws`;
9+
}
10+
811
export async function main() {
912
const options = getOptions();
1013

@@ -21,25 +24,24 @@ export async function main() {
2124
}
2225

2326
async function autoConnect(client: SkyChatClient, options: SkyChatOptions) {
27+
// Wait for the client to connect
28+
await new Promise<void>((resolve) => {
29+
client.connect();
30+
client.once('update', resolve);
31+
});
32+
2433
if (options[SkyChatOption.User] && options[SkyChatOption.Password]) {
25-
await connect(client, {
26-
mode: 'credentials',
27-
user: options[SkyChatOption.User],
28-
password: options[SkyChatOption.Password],
29-
});
34+
client.login(options[SkyChatOption.User], options[SkyChatOption.Password]);
3035
return;
3136
}
3237

3338
const token = await loadToken();
3439
if (token) {
35-
await connect(client, {
36-
mode: 'token',
40+
client.authenticate({
3741
token,
3842
});
3943
return;
4044
}
4145

42-
await connect(client, {
43-
mode: 'guest',
44-
});
46+
client.authAsGuest();
4547
}

src/render/SkyChatCLI.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { SkyChatClient } from 'skychat';
2-
import { Page } from './page/Page.js';
3-
import { LogInPage } from './page/LogInPage.js';
4-
import { ChatPage } from './page/ChatPage.js';
5-
import { saveToken } from '../token.js';
61
import blessed from 'blessed';
2+
import { SkyChatClient } from 'skychat';
73
import { SCREEN_TITLE } from '../constants.js';
4+
import { saveToken } from '../token.js';
5+
import { ChatPage } from './page/ChatPage.js';
6+
import { LogInPage } from './page/LogInPage.js';
7+
import { Page } from './page/Page.js';
88

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

2424
this.currentPage = new LogInPage(client, this.screen);
25-
this.render();
2625

2726
this._bind();
2827
}

src/render/component/MessageList.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import blessed from 'blessed';
2-
import { BOX_DEFAULT_OPTIONS } from '../../constants.js';
3-
import { Component } from './Component.js';
42
import { SanitizedMessage } from 'skychat/build/server';
5-
import { Page } from '../page/Page.js';
3+
import { BOX_DEFAULT_OPTIONS } from '../../constants.js';
64
import { renderMessage } from '../helper/message.js';
5+
import { Page } from '../page/Page.js';
6+
import { Component } from './Component.js';
77

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

0 commit comments

Comments
 (0)