-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSONWebSocket仕様の新ニコ実況に対応 #9
base: master
Are you sure you want to change the base?
Changes from 1 commit
b6c8cbb
49dbde5
4141d5c
edcee91
74426de
a877c9d
57d8d46
beb72a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,9 +104,17 @@ public async IAsyncEnumerable<NiconicoCommentXmlTag> Receive(string liveId, [Enu | |
} | ||
// WebSocketAPIに接続 | ||
ClientWebSocket ws = new ClientWebSocket(); | ||
// UAヘッダ追加 | ||
ws.Options.SetRequestHeader("User-Agent", WEBSOCKET_CLIENT_UA); | ||
// Sec-WebSocket-Protocolヘッダ追加 | ||
ws.Options.SetRequestHeader("Sec-WebSocket-Protocol", WEBSOCKET_PROTOCOL); | ||
// Sec-WebSocket-Versionヘッダ追加 | ||
ws.Options.SetRequestHeader("Sec-WebSocket-Extensions", WEBSOCKET_EXTENSIONS); | ||
|
||
var uri = new Uri(msUriStr); | ||
await ws.ConnectAsync(uri, cancellationToken); | ||
var buffer = new byte[1024]; | ||
|
||
// threadId情報を送信 | ||
string body = "[{\"ping\":{\"content\":\"rs:0\"}},{\"ping\":{\"content\":\"ps:0\"}},{\"thread\":{\"thread\":\"" + threadId + "\",\"version\":\"20061206\",\"user_id\":\"guest\",\"res_from\":-10,\"with_global\":1,\"scores\":1,\"nicoru\":0}},{\"ping\":{\"content\":\"pf:0\"}},{\"ping\":{\"content\":\"rf:0\"}}]"; | ||
byte[] bodyEncoded = Encoding.UTF8.GetBytes(body); | ||
|
@@ -178,5 +186,8 @@ public void Dispose() | |
|
||
private readonly HttpClient httpClient; | ||
private readonly NiconicoCommentJsonParser parser = new NiconicoCommentJsonParser(true); | ||
private readonly string WEBSOCKET_CLIENT_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UAは There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @noriokun4649 ニコニコ側が今後、UAでTVTCommentからの通信をブロックするのではないかと少々心配ではありますが、まあ本家のnicojk等はもう長年やっていましたので、おそらく問題ないでしょう。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. むしろUAが付加されてないリクエストやMozilla系のUAわブロックするような変更も過去にあったため、ルールを守った利用方法であれば問題ないと考えています。 |
||
private readonly string WEBSOCKET_PROTOCOL = "msg.nicovideo.jp#json"; | ||
private readonly string WEBSOCKET_EXTENSIONS = "permessage-deflate; client_max_window_bits"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RequestHeaderにUAを付けるのと、サブプロトコルに「msg.nicovideo.jp#json」を指定した方が良さそうです。