Skip to content

Commit eb56a26

Browse files
blackspherefollowerqdot
authored andcommitted
ButtplugWSClient now requests the device list on connect
This means that during Connect() any devices already connected to the buttplug server will cause DeviceAdded events to be fired. This will include any devices that may have already been seen in the case of a reconnect (if the connection has dropped anything could have happened to the server, therefore the device list is purged and all devices are readded from scratch). As this is now called for you, the RequestDeviceList() method has been removed. The internal device list is now accessible via a C# style getter Devices rather than the previous getDevices() method. The nextMsgId getter has also been renamed to NextMsgId for consistency.
1 parent 104d021 commit eb56a26

3 files changed

Lines changed: 97 additions & 127 deletions

File tree

Buttplug.Apps.ExampleClientGUI/ExampleClientPanel.xaml.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ private async void Connect()
6868
if (_client != null)
6969
{
7070
await _client.Connect(new Uri(AdressTextBox.Text), true);
71-
await _client.RequestDeviceList();
7271

73-
foreach (var dev in _client.getDevices())
72+
foreach (var dev in _client.Devices)
7473
{
7574
devControl.DeviceAdded(new ButtplugDeviceInfo(dev.Index, dev.Name, dev.AllowedMessages));
7675
}
@@ -142,7 +141,7 @@ private void SendLinear_Click(object sender, RoutedEventArgs e)
142141
new FleshlightLaunchFW12Cmd(dev.Index,
143142
Convert.ToUInt32(LinearSpeed.Value),
144143
Convert.ToUInt32(LinearPosition.Value),
145-
_client.nextMsgId));
144+
_client.NextMsgId));
146145
}
147146
}
148147
}
@@ -168,7 +167,7 @@ private void SendVibrate_Click(object sender, RoutedEventArgs e)
168167
new VibrateCmd(dev.Index,
169168
new List<VibrateCmd.VibrateSubcommand>
170169
{ new VibrateCmd.VibrateSubcommand(i, VibrateSpeed.Value) },
171-
_client.nextMsgId));
170+
_client.NextMsgId));
172171
}
173172
}
174173
catch
@@ -200,7 +199,7 @@ private void SendRotate_Click(object sender, RoutedEventArgs e)
200199
new RotateCmd(dev.Index,
201200
new List<RotateCmd.RotateSubcommand>
202201
{ new RotateCmd.RotateSubcommand(i, RotateSpeed.Value * (clockwise ? 1 : -1), clockwise) },
203-
_client.nextMsgId));
202+
_client.NextMsgId));
204203
}
205204
}
206205
catch
@@ -227,7 +226,7 @@ private void SendLinear2_Click(object sender, RoutedEventArgs e)
227226
new LinearCmd.VectorSubcommands(0,
228227
Convert.ToUInt32(LinearDuration.Text),
229228
Linear2Position.Value),
230-
}, _client.nextMsgId));
229+
}, _client.NextMsgId));
231230
}
232231
}
233232
}

Buttplug.Client.Test/ButtPlugClientTests.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void CleanUp()
5757
[Test]
5858
public void TestConnection()
5959
{
60-
AutoResetEvent eEvent = new AutoResetEvent(false);
60+
var eEvent = new AutoResetEvent(false);
6161

6262
_subtypeMgr.AddDevice(new TestDevice(_logMgr, "A", "1"));
6363
_server = new ButtplugWebsocketServer();
@@ -66,7 +66,7 @@ public void TestConnection()
6666
_client = new ButtplugTestClient("Test client");
6767
_client.Connect(new Uri("ws://localhost:12345/buttplug")).Wait();
6868

69-
var msgId = _client.nextMsgId;
69+
var msgId = _client.NextMsgId;
7070
var res = _client.SendMsg(new Core.Messages.Test("Test string", msgId)).GetAwaiter().GetResult();
7171
Assert.True(res != null);
7272
Assert.True(res is Core.Messages.Test);
@@ -76,7 +76,7 @@ public void TestConnection()
7676
// Check ping is working
7777
Thread.Sleep(400);
7878

79-
msgId = _client.nextMsgId;
79+
msgId = _client.NextMsgId;
8080
res = _client.SendMsg(new Core.Messages.Test("Test string", msgId)).GetAwaiter().GetResult();
8181
Assert.True(res != null);
8282
Assert.True(res is Core.Messages.Test);
@@ -89,10 +89,10 @@ public void TestConnection()
8989
Assert.True(((Core.Messages.Test)res).TestString == "Test string");
9090
Assert.True(((Core.Messages.Test)res).Id > msgId);
9191

92-
Assert.True(_client.nextMsgId > 5);
92+
Assert.True(_client.NextMsgId > 5);
9393

9494
// Test that events are raised
95-
bool scanningFinished = false;
95+
var scanningFinished = false;
9696
ButtplugClientDevice lastAdded = null;
9797
ButtplugClientDevice lastRemoved = null;
9898
_client.ScanningFinished += (aSender, aArg) =>
@@ -126,12 +126,9 @@ public void TestConnection()
126126
eEvent.Reset();
127127
Assert.True(scanningFinished);
128128

129-
Assert.AreEqual(1, _client.getDevices().Length);
130-
Assert.AreEqual("B", _client.getDevices()[0].Name);
131-
_client.RequestDeviceList().Wait();
132-
Assert.AreEqual(2, _client.getDevices().Length);
133-
Assert.AreEqual("A", _client.getDevices()[0].Name);
134-
Assert.AreEqual("B", _client.getDevices()[1].Name);
129+
Assert.AreEqual(2, _client.Devices.Length);
130+
Assert.AreEqual("A", _client.Devices[0].Name);
131+
Assert.AreEqual("B", _client.Devices[1].Name);
135132

136133
eEvent.Reset();
137134
Assert.Null(lastRemoved);
@@ -147,8 +144,8 @@ public void TestConnection()
147144
eEvent.Reset();
148145
Assert.NotNull(lastRemoved);
149146
Assert.AreEqual("B", lastRemoved.Name);
150-
Assert.AreEqual(1, _client.getDevices().Length);
151-
Assert.AreEqual("A", _client.getDevices()[0].Name);
147+
Assert.AreEqual(1, _client.Devices.Length);
148+
Assert.AreEqual("A", _client.Devices[0].Name);
152149

153150
// Shut it down
154151
_client.Disconnect().Wait();
@@ -164,7 +161,7 @@ public void TestSSLConnection()
164161
_client = new ButtplugTestClient("Test client");
165162
_client.Connect(new Uri("wss://localhost:12346/buttplug"), true).Wait();
166163

167-
var msgId = _client.nextMsgId;
164+
var msgId = _client.NextMsgId;
168165
var res = _client.SendMsg(new Core.Messages.Test("Test string", msgId)).GetAwaiter().GetResult();
169166
Assert.True(res != null);
170167
Assert.True(res is Core.Messages.Test);
@@ -174,16 +171,14 @@ public void TestSSLConnection()
174171
// Check ping is working
175172
Thread.Sleep(400);
176173

177-
msgId = _client.nextMsgId;
174+
msgId = _client.NextMsgId;
178175
res = _client.SendMsg(new Core.Messages.Test("Test string", msgId)).GetAwaiter().GetResult();
179176
Assert.True(res != null);
180177
Assert.True(res is Core.Messages.Test);
181178
Assert.True(((Core.Messages.Test)res).TestString == "Test string");
182179
Assert.True(((Core.Messages.Test)res).Id > msgId);
183180

184-
Assert.True(_client.nextMsgId > 4);
185-
186-
_client.RequestDeviceList().Wait();
181+
Assert.True(_client.NextMsgId > 4);
187182

188183
// Shut it down
189184
_client.Disconnect().Wait();

0 commit comments

Comments
 (0)