Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Kitsukey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kio!
Kitsukey
Commits
e8c85692
Commit
e8c85692
authored
3 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
✌️
parent
e1317ce0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+63
-5
63 additions, 5 deletions
README.md
src/streaming.ts
+1
-1
1 addition, 1 deletion
src/streaming.ts
with
64 additions
and
6 deletions
README.md
+
63
−
5
View file @
e8c85692
...
...
@@ -48,19 +48,77 @@ mainChannel.on('notification', notification => {
});
```
### `useSharedConnection(channel: string): SharedConnection`
使いまわし可能なチャンネル(=パラメータを持たないチャンネル)に接続します。
このメソッドを用いて接続したチャンネル接続は内部的に使いまわされるため、プログラム上の複数の場所から呼び出してもコネクションを無駄に増やさずに済みます。
### チャンネルへの接続(使いまわす場合)
使いまわし可能なチャンネル(=パラメータを持たないチャンネル)に接続するときは、
`useSharedConnection`
メソッドを使用します。
### `connectToChannel(channel: string, params?: any): NonSharedConnection`
チャンネルに接続します。返り値はそのチャンネルへのコネクションインスタンスです。
```
ts
const
stream
=
new
Misskey
.
Stream
(
'
https://misskey.test
'
,
{
token
:
'
TOKEN
'
});
const
mainChannel
=
stream
.
useSharedConnection
(
'
main
'
);
```
このメソッドを用いてチャンネルに接続することで、(同じStreamインスタンスを共有している場合)プログラム上の複数個所から呼び出しても内部的にまとめられます。
### チャンネルへの接続(使いまわし不可の場合)
パラメータを持つチャンネルへの接続は
`connectToChannel`
メソッドを使用します。
```
ts
const
stream
=
new
Misskey
.
Stream
(
'
https://misskey.test
'
,
{
token
:
'
TOKEN
'
});
const
messagingChannel
=
stream
.
connectToChannel
(
'
messaging
'
,
{
otherparty
:
'
xxxxxxxxxx
'
,
});
```
### チャンネルから切断
`dispose`
メソッドを呼び出します。
```
ts
const
stream
=
new
Misskey
.
Stream
(
'
https://misskey.test
'
,
{
token
:
'
TOKEN
'
});
const
mainChannel
=
stream
.
useSharedConnection
(
'
main
'
);
mainChannel
.
dispose
();
```
### メッセージの受信
チャンネル接続インスタンスはEventEmitterを継承しており、メッセージがサーバーから受信されると受け取ったイベント名でペイロードをemitします。
```
ts
import
*
as
Misskey
from
'
misskey-js
'
;
const
stream
=
new
Misskey
.
Stream
(
'
https://misskey.test
'
,
{
token
:
'
TOKEN
'
});
const
mainChannel
=
stream
.
useSharedConnection
(
'
main
'
);
mainChannel
.
on
(
'
notification
'
,
notification
=>
{
console
.
log
(
'
notification received
'
,
notification
);
});
```
### メッセージの送信
チャンネル接続インスタンスの
`send`
メソッドを使用してメッセージをサーバーに送信することができます。
```
ts
import
*
as
Misskey
from
'
misskey-js
'
;
const
stream
=
new
Misskey
.
Stream
(
'
https://misskey.test
'
,
{
token
:
'
TOKEN
'
});
const
messagingChannel
=
stream
.
connectToChannel
(
'
messaging
'
,
{
otherparty
:
'
xxxxxxxxxx
'
,
});
messagingChannel
.
send
(
'
read
'
,
{
id
:
'
xxxxxxxxxx
'
});
```
### Reference
#### `useSharedConnection(channel: string): SharedConnection`
使いまわし可能なチャンネル(=パラメータを持たないチャンネル)に接続します。
このメソッドを用いて接続したチャンネル接続は内部的に使いまわされるため、プログラム上の複数の場所から呼び出してもコネクションを無駄に増やさずに済みます。
#### `connectToChannel(channel: string, params?: any): NonSharedConnection`
チャンネルに接続します。返り値はそのチャンネルへのコネクションインスタンスです。
---
<div
align=
"center"
>
...
...
This diff is collapsed.
Click to expand it.
src/streaming.ts
+
1
−
1
View file @
e8c85692
...
...
@@ -52,7 +52,7 @@ type ChannelDef = {
message
:
(
payload
:
MessagingMessage
)
=>
void
;
deleted
:
(
payload
:
MessagingMessage
[
'
id
'
])
=>
void
;
read
:
(
payload
:
MessagingMessage
[
'
id
'
][])
=>
void
;
typ
ing
:
(
payload
:
User
[
'
id
'
])
=>
void
;
typ
ers
:
(
payload
:
User
[])
=>
void
;
};
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment