@@ -68,6 +68,20 @@ public ErrorMsgEventArgs(int code, string messageError)
68
68
public string MessageError { get ; set ; }
69
69
}
70
70
71
+ // event to inform about headset connect
72
+ public class HeadsetConnectEventArgs
73
+ {
74
+ public HeadsetConnectEventArgs ( bool isSuccess , string message , string headsetId )
75
+ {
76
+ IsSuccess = isSuccess ;
77
+ Message = message ;
78
+ HeadsetId = headsetId ;
79
+ }
80
+ public bool IsSuccess { get ; set ; }
81
+ public string Message { get ; set ; }
82
+ public string HeadsetId { get ; set ; }
83
+ }
84
+
71
85
public sealed class CortexClient
72
86
{
73
87
const string Url = "wss://localhost:6868" ;
@@ -86,8 +100,6 @@ public sealed class CortexClient
86
100
public event EventHandler < ErrorMsgEventArgs > OnErrorMsgReceived ;
87
101
public event EventHandler < StreamDataEventArgs > OnStreamDataReceived ;
88
102
public event EventHandler < List < Headset > > OnQueryHeadset ;
89
- public event EventHandler < string > OnHeadsetConnected ;
90
- public event EventHandler < bool > OnHeadsetDisConnected ;
91
103
public event EventHandler < bool > OnHasAccessRight ;
92
104
public event EventHandler < bool > OnRequestAccessDone ;
93
105
public event EventHandler < bool > OnAccessRightGranted ;
@@ -118,6 +130,8 @@ public sealed class CortexClient
118
130
public event EventHandler < JArray > OnQueryProfile ;
119
131
public event EventHandler < double > OnGetTrainingTime ;
120
132
public event EventHandler < JObject > OnTraining ;
133
+ public event EventHandler < string > SessionClosedNotify ;
134
+ public event EventHandler < HeadsetConnectEventArgs > HeadsetConnectNotify ;
121
135
public event EventHandler < string > HeadsetScanFinished ;
122
136
123
137
// Constructor
@@ -250,29 +264,7 @@ private void HandleResponse(string method, JToken data)
250
264
else if ( method == "controlDevice" )
251
265
{
252
266
string command = ( string ) data [ "command" ] ;
253
- if ( command == "connect" )
254
- {
255
- string message = ( string ) data [ "message" ] ;
256
- string headsetId = "" ;
257
-
258
- Console . WriteLine ( "ConnectHeadset " + message ) ;
259
- if ( message . Contains ( "Start connecting to device" ) )
260
- {
261
- //"Start connecting to device " + headsetId
262
- headsetId = message . Substring ( 27 ) ;
263
- }
264
- else if ( message . Contains ( "The device" ) )
265
- {
266
- //"The device " + headsetId + " has been connected or is connecting";
267
- string tmp = message . Replace ( " has been connected or is connecting" , "" ) ;
268
- headsetId = tmp . Substring ( 11 ) ;
269
- }
270
- OnHeadsetConnected ( this , headsetId ) ;
271
- }
272
- else if ( command == "disconnect" )
273
- {
274
- OnHeadsetDisConnected ( this , true ) ;
275
- }
267
+ Console . WriteLine ( "controlDevice response for command " + command ) ;
276
268
}
277
269
else if ( method == "getUserLogin" )
278
270
{
@@ -468,6 +460,36 @@ private void HandleWarning(int code, JToken messageData)
468
460
string message = messageData [ "behavior" ] . ToString ( ) ;
469
461
HeadsetScanFinished ( this , message ) ;
470
462
}
463
+ else if ( code == WarningCode . StreamStop )
464
+ {
465
+ string sessionId = messageData [ "sessionId" ] . ToString ( ) ;
466
+ SessionClosedNotify ( this , sessionId ) ;
467
+ }
468
+ else if ( code == WarningCode . SessionAutoClosed )
469
+ {
470
+ string sessionId = messageData [ "sessionId" ] . ToString ( ) ;
471
+ SessionClosedNotify ( this , sessionId ) ;
472
+ }
473
+ else if ( code == WarningCode . HeadsetConnected )
474
+ {
475
+ string headsetId = messageData [ "headsetId" ] . ToString ( ) ;
476
+ string message = messageData [ "behavior" ] . ToString ( ) ;
477
+ Console . WriteLine ( "handleWarning:" + message ) ;
478
+ HeadsetConnectNotify ( this , new HeadsetConnectEventArgs ( true , message , headsetId ) ) ;
479
+ }
480
+ else if ( code == WarningCode . HeadsetWrongInformation ||
481
+ code == WarningCode . HeadsetCannotConnected ||
482
+ code == WarningCode . HeadsetConnectingTimeout )
483
+ {
484
+ string headsetId = messageData [ "headsetId" ] . ToString ( ) ;
485
+ string message = messageData [ "behavior" ] . ToString ( ) ;
486
+ HeadsetConnectNotify ( this , new HeadsetConnectEventArgs ( false , message , headsetId ) ) ;
487
+ }
488
+ else if ( code == WarningCode . CortexAutoUnloadProfile )
489
+ {
490
+ // the current profile is unloaded automatically
491
+ OnUnloadProfile ( this , true ) ;
492
+ }
471
493
472
494
}
473
495
private void WebSocketClient_Closed ( object sender , EventArgs e )
@@ -580,6 +602,7 @@ public void QueryHeadsets(string headsetId)
580
602
// mappings is required if connect to epoc flex
581
603
public void ControlDevice ( string command , string headsetId , JObject mappings )
582
604
{
605
+ Console . WriteLine ( "ControlDevice " + command + " headsetId:" + headsetId ) ;
583
606
JObject param = new JObject ( ) ;
584
607
param . Add ( "command" , command ) ;
585
608
if ( ! String . IsNullOrEmpty ( headsetId ) )
@@ -622,7 +645,7 @@ public void UpdateSession(string cortexToken, string sessionId, string status)
622
645
// CreateRecord
623
646
// Required params: session, title, cortexToken
624
647
public void CreateRecord ( string cortexToken , string sessionId , string title ,
625
- JToken description = null , JToken subjectName = null , JToken tags = null )
648
+ JToken description = null , JToken subjectName = null , List < string > tags = null )
626
649
{
627
650
JObject param = new JObject ( ) ;
628
651
param . Add ( "session" , sessionId ) ;
@@ -638,7 +661,7 @@ public void CreateRecord(string cortexToken, string sessionId, string title,
638
661
}
639
662
if ( tags != null )
640
663
{
641
- param . Add ( "tags" , tags ) ;
664
+ param . Add ( "tags" , JArray . FromObject ( tags ) ) ;
642
665
}
643
666
SendTextMessage ( param , "createRecord" , true ) ;
644
667
}
0 commit comments