Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 665dd32

Browse files
committed
Merge branch 'release'
2 parents 1b6661d + 752e305 commit 665dd32

File tree

12 files changed

+184
-26
lines changed

12 files changed

+184
-26
lines changed

‎BouyomiPlugin/IpcTalker.cs‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using FNF.Utility;
2+
using System;
3+
using System.Runtime.Remoting;
4+
using System.Runtime.Remoting.Contexts;
5+
using System.Runtime.Remoting.Messaging;
6+
7+
namespace BouyomiPlugin
8+
{
9+
class IpcTalker : ITalker
10+
{
11+
public void Dispose()
12+
{
13+
_bouyomiChanClient.Dispose();
14+
}
15+
16+
public void TalkText(string text)
17+
{
18+
_bouyomiChanClient.AddTalkTask2(text);
19+
}
20+
21+
public void TalkText(string text, Int16 voiceSpeed, Int16 voiceTone, Int16 voiceVolume, VoiceType voiceType)
22+
{
23+
try
24+
{
25+
_bouyomiChanClient.AddTalkTask2(
26+
text,
27+
voiceSpeed,
28+
voiceTone,
29+
voiceVolume,
30+
voiceType
31+
);
32+
}
33+
catch (RemotingException ex)
34+
{
35+
throw new TalkException("", ex);
36+
}
37+
}
38+
private readonly BouyomiChanClient _bouyomiChanClient = new FNF.Utility.BouyomiChanClient();
39+
}
40+
}

‎BouyomiPlugin/TcpTalker.cs‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
using System.IO;
3+
using System.Net.Sockets;
4+
using System.Text;
5+
6+
namespace BouyomiPlugin
7+
{
8+
class TcpTalker : ITalker
9+
{
10+
private bool _disposedValue;
11+
12+
const Int16 COMMAND = 0x0001;
13+
const byte CHARCODE_UTF8 = 0;
14+
15+
public string IpAddr { get; set; }
16+
public int Port { get; set; }
17+
18+
public void TalkText(string text)
19+
{
20+
//-1を指定すると棒読みちゃん画面上の設定を使用する
21+
TalkText(text, -1, -1, -1, FNF.Utility.VoiceType.Default);
22+
}
23+
public void TalkText(string text, Int16 voiceSpeed, Int16 voiceTone, Int16 voiceVolume, FNF.Utility.VoiceType voiceTypeIndex)
24+
{
25+
var ipAddr = "127.0.0.1";
26+
var port = 50001;
27+
var messageBytes = Encoding.UTF8.GetBytes(text);
28+
29+
try
30+
{
31+
using (var tc = new TcpClient(ipAddr, port))
32+
using (NetworkStream ns = tc.GetStream())
33+
using (var bw = new BinaryWriter(ns))
34+
{
35+
bw.Write(COMMAND); //コマンド( 0:メッセージ読み上げ)
36+
bw.Write((Int16)voiceSpeed); //速度 (-1:棒読みちゃん画面上の設定)
37+
bw.Write((Int16)voiceTone); //音程 (-1:棒読みちゃん画面上の設定)
38+
bw.Write((Int16)voiceVolume); //音量 (-1:棒読みちゃん画面上の設定)
39+
bw.Write((Int16)voiceTypeIndex); //声質 ( 0:棒読みちゃん画面上の設定、1:女性1、2:女性2、3:男性1、4:男性2、5:中性、6:ロボット、7:機械1、8:機械2、10001〜:SAPI5)
40+
bw.Write(CHARCODE_UTF8); //文字列のbyte配列の文字コード(0:UTF-8, 1:Unicode, 2:Shift-JIS)
41+
bw.Write((Int32)messageBytes.Length); //文字列のbyte配列の長さ
42+
bw.Write(messageBytes); //文字列のbyte配列
43+
}
44+
}
45+
catch (Exception ex)
46+
{
47+
throw new TalkException("", ex);
48+
}
49+
}
50+
51+
protected virtual void Dispose(bool disposing)
52+
{
53+
if (!_disposedValue)
54+
{
55+
if (disposing)
56+
{
57+
// TODO: dispose managed state (managed objects)
58+
}
59+
60+
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
61+
// TODO: set large fields to null
62+
_disposedValue = true;
63+
}
64+
}
65+
66+
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
67+
// ~TcpTalker()
68+
// {
69+
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
70+
// Dispose(disposing: false);
71+
// }
72+
73+
public void Dispose()
74+
{
75+
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
76+
Dispose(disposing: true);
77+
GC.SuppressFinalize(this);
78+
}
79+
public TcpTalker(string ipAddr, int port)
80+
{
81+
IpAddr = ipAddr;
82+
Port = port;
83+
}
84+
}
85+
}

‎BouyomiPlugin/main.cs‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
using System.Collections.Generic;
1515
using System.ComponentModel.Composition;
1616
using System.Diagnostics;
17-
using System.Runtime.Remoting.Contexts;
18-
using System.Runtime.Remoting.Messaging;
1917
using TwicasSitePlugin;
2018
using TwitchSitePlugin;
2119
using WhowatchSitePlugin;
@@ -40,7 +38,7 @@ public static string ToTextWithImageAlt(this IEnumerable<IMessagePart> parts)
4038
{
4139
s += image.Alt;
4240
}
43-
else if(part is IMessageRemoteSvg remoteSvg)
41+
else if(part is IMessageRemoteSvg remoteSvg)
4442
{
4543
s += remoteSvg.Alt;
4644
}
@@ -53,10 +51,28 @@ public static string ToTextWithImageAlt(this IEnumerable<IMessagePart> parts)
5351
return s;
5452
}
5553
}
54+
interface ITalker : IDisposable
55+
{
56+
void TalkText(string text);
57+
58+
void TalkText(string text, Int16 voiceSpeed, Int16 voiceTone, Int16 voiceVolume, FNF.Utility.VoiceType voiceType);
59+
}
60+
61+
[Serializable]
62+
public class TalkException : Exception
63+
{
64+
public TalkException() { }
65+
public TalkException(string message) : base(message) { }
66+
public TalkException(string message, Exception inner) : base(message, inner) { }
67+
protected TalkException(
68+
System.Runtime.Serialization.SerializationInfo info,
69+
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
70+
}
5671
[Export(typeof(IPlugin))]
5772
public class BouyomiPlugin : IPlugin, IDisposable
5873
{
59-
private readonly FNF.Utility.BouyomiChanClient _bouyomiChanClient;
74+
//private readonly FNF.Utility.BouyomiChanClient _bouyomiChanClient;
75+
private readonly ITalker _talker;
6076
private Options _options;
6177
Process _bouyomiChanProcess;
6278
public string Name => "棒読みちゃん連携";
@@ -695,7 +711,7 @@ public void OnMessageReceived(ISiteMessage message, IMessageMetadata messageMeta
695711
}
696712
TalkText(dataToRead);
697713
}
698-
catch (System.Runtime.Remoting.RemotingException)
714+
catch (TalkException)
699715
{
700716
//多分棒読みちゃんが起動していない。
701717
if (_bouyomiChanProcess == null && System.IO.File.Exists(_options.BouyomiChanPath))
@@ -720,21 +736,17 @@ public void OnMessageReceived(ISiteMessage message, IMessageMetadata messageMeta
720736
}
721737
}
722738

723-
private int TalkText(string text)
739+
private void TalkText(string text)
724740
{
725741
if (_options.IsVoiceTypeSpecfied)
726742
{
727-
return _bouyomiChanClient.AddTalkTask2(
728-
text,
729-
_options.VoiceSpeed,
730-
_options.VoiceTone,
731-
_options.VoiceVolume,
732-
(FNF.Utility.VoiceType)Enum.ToObject(typeof(FNF.Utility.VoiceType), _options.VoiceTypeIndex)
733-
);
743+
_talker.TalkText(text, (Int16)_options.VoiceSpeed,
744+
(Int16)_options.VoiceTone,
745+
(Int16)_options.VoiceVolume, (FNF.Utility.VoiceType)Enum.ToObject(typeof(FNF.Utility.VoiceType), _options.VoiceTypeIndex));
734746
}
735747
else
736748
{
737-
return_bouyomiChanClient.AddTalkTask2(text);
749+
_talker.TalkText(text);
738750
}
739751
}
740752

@@ -763,7 +775,7 @@ public void ShowSettingView()
763775
}
764776
public BouyomiPlugin()
765777
{
766-
_bouyomiChanClient = new FNF.Utility.BouyomiChanClient();
778+
_talker = new IpcTalker();
767779
_options = new Options();
768780
}
769781

@@ -777,7 +789,7 @@ protected virtual void Dispose(bool disposing)
777789
if (disposing)
778790
{
779791
}
780-
_bouyomiChanClient.Dispose();
792+
_talker.Dispose();
781793
if (_bouyomiChanProcess != null)
782794
{
783795
_bouyomiChanProcess.Close();

‎Common/Websocket.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public Task ReceiveAsync(string url)
2929
var tcs = new TaskCompletionSource<object>();
3030
_tcs = tcs;
3131
var cookies = new List<KeyValuePair<string, string>>();
32-
var ws = new WebSocket(url, SubProtocol, cookies, null, UserAgent, Origin)
32+
var ws = new WebSocket(url, SubProtocol, cookies, null, UserAgent, Origin,WebSocketVersion.None,null,System.Security.Authentication.SslProtocols.Tls12)
3333
{
3434
EnableAutoSendPing = EnableAutoSendPing,
3535
AutoSendPingInterval = AutoSendPingInterval,

‎MultiCommentViewer/Properties/AssemblyInfo.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
[assembly: InternalsVisibleTo("MultiCommentViewerTests")]
55

6-
[assembly: AssemblyVersion("0.6.28")]
6+
[assembly: AssemblyVersion("0.6.29")]

‎ShowRoomSitePlugin/MessageProvider.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public static IInternalMessage ParseMsg(string raw)
173173
switch (type)
174174
{
175175
case "1":
176-
internalMessage = newT1(raw);
176+
internalMessage = T1.Parse(raw);
177177
break;
178178
case "2"://throwGifts
179179
internalMessage = new T2(raw);

‎TwicasSitePlugin/API.cs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ public class Item
4747
}
4848
static class API
4949
{
50-
public static async Task<string> GetWebsocketUrl(IDataServer server, long movie_id, CookieContainer cc)
50+
public static async Task<string> GetWebsocketUrl(IDataServer server, long movie_id, longunixMillisec,CookieContainer cc)
5151
{
5252
var url = "https://twitcasting.tv/eventpubsuburl.php";
5353
var data = new Dictionary<string, string>
5454
{
55-
{"movie_id", movie_id.ToString()}
55+
{"movie_id", movie_id.ToString()},
56+
{"__n", unixMillisec.ToString() }
5657
};
57-
var res = await server.PostAsync(url, data, cc);
58+
var res = await server.PostMultipartFormdataAsync(url, data, cc);
5859
var d = DynamicJson.Parse(res);
60+
//ブラウザだとurlの属性に"n=cce425f940dea58b"のようなものが付加されるけど、これだと無い。なんで?multipart/form-dataの形式がおかしい?
5961
if (d.IsDefined("url"))
6062
{
6163
return d.url;

‎TwicasSitePlugin/IDataServer.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ interface IDataServer
1010
Task<string> GetAsync(string url);
1111
Task<string> GetAsync(string url, string userAgent, CookieContainer cc);
1212
Task<string> PostAsync(string url, Dictionary<string, string> data, CookieContainer cc);
13+
Task<string> PostMultipartFormdataAsync(string url, Dictionary<string, string> data, CookieContainer cc);
1314
}
1415
}

‎TwicasSitePlugin/TwicasAutoReconnector.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Common;
22
using SitePluginCommon.AutoReconnection;
3+
using System;
34
using System.Collections.Generic;
45
using System.Net;
56
using System.Threading.Tasks;
@@ -36,6 +37,8 @@ public async Task AutoReconnectAsync()
3637
_p1.Cc = _cc;
3738
_p1.BroadcasterId = _broadcasterId;
3839
_p1.LiveId = _currentLiveId ?? liveId;
40+
var nowUnixMillisec = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds();
41+
_p1.WebsocketUrl = await API.GetWebsocketUrl(_server, _p1.LiveId, nowUnixMillisec, _cc) + "&gift=1";
3942
_p1.Master = _p2;
4043
//var p = new WebsocketMessageProvider(new Common.Websocket());
4144
//p.MessageReceived += (sender, e) => { Debug.WriteLine(e.Raw); };

‎TwicasSitePlugin/TwicasServer.cs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public Task<string> GetAsync(string url)
3535
{
3636
return GetAsync(url, null);
3737
}
38-
public async Task<string> PostAsync(string url, Dictionary<string,string> data, CookieContainer cc)
38+
public async Task<string> PostAsync(string url, Dictionary<string,string> data, CookieContainer cc)
3939
{
4040
var content = new FormUrlEncodedContent(data);
4141
var result = await PostInternalAsync(new HttpOptions
@@ -46,5 +46,20 @@ public async Task<string> PostAsync(string url, Dictionary<string,string> data,
4646
var str = await result.Content.ReadAsStringAsync();
4747
return str;
4848
}
49+
public async Task<string> PostMultipartFormdataAsync(string url, Dictionary<string, string> data, CookieContainer cc)
50+
{
51+
var content = new MultipartFormDataContent();
52+
foreach (var kv in data)
53+
{
54+
content.Add(new StringContent(kv.Value), kv.Key);
55+
}
56+
var result = await PostInternalAsync(new HttpOptions
57+
{
58+
Url = url,
59+
Cc = cc,
60+
}, content);
61+
var str = await result.Content.ReadAsStringAsync();
62+
return str;
63+
}
4964
}
5065
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /