@@ -17,7 +17,7 @@ public abstract class UnityWebSocket : MonoBehaviour {
17
17
protected string WebSocketUri ;
18
18
protected List < UnityKeyValue > Headers ;
19
19
20
- private IWebSocket _ws ;
20
+ protected IWebSocket _ws ;
21
21
22
22
protected bool isAttached = false ;
23
23
@@ -41,9 +41,6 @@ protected virtual void OnWebSocketOpen (object sender, EventArgs e) {
41
41
42
42
protected virtual void OnWebSocketClose ( object sender , WebSocketCloseEventArgs e ) {
43
43
Debug . Log ( "Web socket closed with reason: " + e . Reason ) ;
44
- if ( ! e . WasClean ) {
45
- DisconnectWebSocket ( ) ;
46
- }
47
44
DettachHandlers ( ) ;
48
45
}
49
46
@@ -75,7 +72,7 @@ public void SendUTF8Text (string text, Action<bool> callback = null) {
75
72
SendBytes ( data , callback ) ;
76
73
}
77
74
78
- public void SendInputText ( InputField inputField ) {
75
+ public virtual void SendInputText ( InputField inputField ) {
79
76
SendText ( inputField . text ) ;
80
77
}
81
78
@@ -93,17 +90,19 @@ protected void ConnectWebSocket () {
93
90
return ;
94
91
}
95
92
96
- if ( _ws == null ) {
93
+ if ( _ws == null || ! _ws . IsConfigured ( ) ) {
97
94
var customHeaders = new List < KeyValuePair < string , string > > ( ) ;
98
- foreach ( UnityKeyValue header in Headers ) {
99
- customHeaders . Add ( new KeyValuePair < string , string > ( header . key , header . value ) ) ;
95
+ if ( Headers != null ) {
96
+ foreach ( UnityKeyValue header in Headers ) {
97
+ customHeaders . Add ( new KeyValuePair < string , string > ( header . key , header . value ) ) ;
98
+ }
100
99
}
101
100
102
101
Debug . Log ( "Create Web Socket: " + WebSocketUri ) ;
103
102
#if ENABLE_WINMD_SUPPORT
104
103
Debug . Log ( "Using UWP Web Socket" ) ;
105
104
_ws = new WebSocketUWP ( ) ;
106
- #else
105
+ #elif UNITY_EDITOR || ENABLE_MONO
107
106
Debug . Log ( "Using Mono Web Socket" ) ;
108
107
_ws = new WebSocketMono ( ) ;
109
108
#endif
0 commit comments