f9ad127aaf
* wip * wip * wip * wip * wip * wip * wip * wip * fix * fix * fix * fix size * fix register logs * fix img autosize * fix row selection * support delete * fix border rendering * fix display:none * tweak comments * support choose pc file and drive file * support directory drag-drop * fix * fix comment * support context menu on data area * fix autogen * wip イベント整理 * イベントの整理 * refactor grid * fix cell re-render bugs * fix row remove * fix comment * fix validation * fix utils * list maximum * add mimetype check * fix * fix number cell focus * fix over 100 file drop * remove log * fix patchData * fix performance * fix * support update and delete * support remote import * fix layout * heightやめる * fix performance * add list v2 endpoint * support pagination * fix api call * fix no clickable input text * fix limit * fix paging * fix * fix * support search * tweak logs * tweak cell selection * fix range select * block delete * add comment * fix * support import log * fix dialog * refactor * add confirm dialog * fix name * fix autogen * wip * support image change and highlight row * add columns * wip * support sort * add role name * add index to emoji * refine context menu setting * support role select * remove unused buttons * fix url * fix MkRoleSelectDialog.vue * add route * refine remote page * enter key search * fix paste bugs * fix copy/paste * fix keyEvent * fix copy/paste and delete * fix comment * fix MkRoleSelectDialog.vue and storybook scenario * fix MkRoleSelectDialog.vue and storybook scenario * add MkGrid.stories.impl.ts * fix * [wip] add custom-emojis-manager2.stories.impl.ts * [wip] add custom-emojis-manager2.stories.impl.ts * wip * 課題はまだ残っているが、ひとまず完了 * fix validation and register roles * fix upload * optimize import * patch from dev * i18n * revert excess fixes * separate sort order component * add SPDX * revert excess fixes * fix pre test * fix bugs * add type column * fix types * fix CHANGELOG.md * fix lit * lint * tweak style * refactor * fix ci * autogen * Update types.ts * CSS Module化 * fix log * 縦スクロールを無効化 * MkStickyContainer化 * regenerate locales index.d.ts * fix * fix * テスト * ランダム値によるUI変更の抑制 * テスト * tableタグやめる * fix last-child css * fix overflow css * fix endpoint.ts * tweak css * 最新への追従とレイアウト微調整 * ソートキーの指定方法を他と合わせた * fix focus * fix layout * v2エンドポイントのルールに対応 * 表示条件などを微調整 * fix MkDataCell.vue * fix error code * fix error * add comment to MkModal.vue * Update index.d.ts * fix CHANGELOG.md * fix color theme * fix CHANGELOG.md * fix CHANGELOG.md * fix center * fix: テーブルにフォーカスがあり、通常状態であるときはキーイベントの伝搬を止める * fix: ロール選択用のダイアログにてコンディショナルロールを×ボタンで除外できなかったのを修正 * fix remote list folder * sticky footers * chore: fix ci error(just single line-break diff) * fix loading * fix like * comma to space * fix ci * fix ci * removed align-center --------- Co-authored-by: osamu <46447427+sam-osamu@users.noreply.github.com> Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com> Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com> |
||
---|---|---|
.. | ||
docs | ||
etc | ||
generator | ||
src | ||
test | ||
test-d | ||
.swcrc | ||
api-extractor.json | ||
build.js | ||
CONTRIBUTING.md | ||
eslint.config.js | ||
jest.config.cjs | ||
LICENSE | ||
package.json | ||
README.md | ||
tsconfig.json |
misskey.js
Strongly-typed official Misskey SDK for browsers/Node.js.
JavaScript(TypeScript)用の公式MisskeySDKです。ブラウザ/Node.js上で動作します。
以下が提供されています:
- ユーザー認証
- APIリクエスト
- ストリーミング
- ユーティリティ関数
- Misskeyの各種型定義
対応するMisskeyのバージョンは12以上です。
Install
npm i misskey-js
Usage
インポートは以下のようにまとめて行うと便利です。
import * as Misskey from 'misskey-js';
便宜上、以後のコード例は上記のように* as Misskey
としてインポートしている前提のものになります。
ただし、このインポート方法だとTree-Shakingできなくなるので、コードサイズが重要なユースケースでは以下のような個別インポートをお勧めします。
import { api as misskeyApi } from 'misskey-js';
Authenticate
todo
API request
APIを利用する際は、利用するサーバーの情報とアクセストークンを与えてAPIClient
クラスのインスタンスを初期化し、そのインスタンスのrequest
メソッドを呼び出してリクエストを行います。
const cli = new Misskey.api.APIClient({
origin: 'https://misskey.test',
credential: 'TOKEN',
});
const meta = await cli.request('meta', { detail: true });
request
の第一引数には呼び出すエンドポイント名、第二引数にはパラメータオブジェクトを渡します。レスポンスはPromiseとして返ります。
Streaming
misskey.jsのストリーミングでは、二つのクラスが提供されます。
ひとつは、ストリーミングのコネクション自体を司るStream
クラスと、もうひとつはストリーミング上のチャンネルの概念を表すChannel
クラスです。
ストリーミングを利用する際は、まずStream
クラスのインスタンスを初期化し、その後でStream
インスタンスのメソッドを利用してChannel
クラスのインスタンスを取得する形になります。
const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
const mainChannel = stream.useChannel('main');
mainChannel.on('notification', notification => {
console.log('notification received', notification);
});
コネクションが途切れても自動で再接続されます。
チャンネルへの接続
チャンネルへの接続はStream
クラスのuseChannel
メソッドを使用します。
パラメータなし
const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
const mainChannel = stream.useChannel('main');
パラメータあり
const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
const messagingChannel = stream.useChannel('messaging', {
otherparty: 'xxxxxxxxxx',
});
チャンネルから切断
Channel
クラスのdispose
メソッドを呼び出します。
const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
const mainChannel = stream.useChannel('main');
mainChannel.dispose();
メッセージの受信
Channel
クラスはEventEmitterを継承しており、メッセージがサーバーから受信されると受け取ったイベント名でペイロードをemitします。
const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
const mainChannel = stream.useChannel('main');
mainChannel.on('notification', notification => {
console.log('notification received', notification);
});
メッセージの送信
Channel
クラスのsend
メソッドを使用してメッセージをサーバーに送信することができます。
const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
const messagingChannel = stream.useChannel('messaging', {
otherparty: 'xxxxxxxxxx',
});
messagingChannel.send('read', {
id: 'xxxxxxxxxx'
});
コネクション確立イベント
Stream
クラスの_connected_
イベントが利用可能です。
const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
stream.on('_connected_', () => {
console.log('connected');
});
コネクション切断イベント
Stream
クラスの_disconnected_
イベントが利用可能です。
const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
stream.on('_disconnected_', () => {
console.log('disconnected');
});
コネクションの状態
Stream
クラスのstate
プロパティで確認できます。
initializing
: 接続確立前connected
: 接続完了reconnecting
: 再接続中