Replace updatestate event with connect
Instead of exposing all the internal connection states, the RFB module will now only send events on connect and on disconnect. This makes it simpler for the application and gets rid of the double events that were being sent on disconnect (previously updatestate and disconnect).
This commit is contained in:
+16
-15
@@ -512,8 +512,6 @@ RFB.prototype = {
|
||||
// State change actions
|
||||
|
||||
this._rfb_connection_state = state;
|
||||
var event = new CustomEvent("updatestate", { detail: { state: state } });
|
||||
this.dispatchEvent(event);
|
||||
|
||||
var smsg = "New state '" + state + "', was '" + oldstate + "'.";
|
||||
Log.Debug(smsg);
|
||||
@@ -528,23 +526,15 @@ RFB.prototype = {
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case 'disconnected':
|
||||
// Fire disconnected event after updatestate event since
|
||||
// we don't know if the UI only displays the latest message
|
||||
if (this._rfb_disconnect_reason !== "") {
|
||||
event = new CustomEvent("disconnect",
|
||||
{ detail: { reason: this._rfb_disconnect_reason } });
|
||||
} else {
|
||||
// No reason means clean disconnect
|
||||
event = new CustomEvent("disconnect", { detail: {} });
|
||||
}
|
||||
this.dispatchEvent(event);
|
||||
break;
|
||||
|
||||
case 'connecting':
|
||||
this._connect();
|
||||
break;
|
||||
|
||||
case 'connected':
|
||||
var event = new CustomEvent("connect", { detail: {} });
|
||||
this.dispatchEvent(event);
|
||||
break;
|
||||
|
||||
case 'disconnecting':
|
||||
this._disconnect();
|
||||
|
||||
@@ -553,6 +543,17 @@ RFB.prototype = {
|
||||
this._updateConnectionState('disconnected');
|
||||
}.bind(this), DISCONNECT_TIMEOUT * 1000);
|
||||
break;
|
||||
|
||||
case 'disconnected':
|
||||
if (this._rfb_disconnect_reason !== "") {
|
||||
event = new CustomEvent("disconnect",
|
||||
{ detail: { reason: this._rfb_disconnect_reason } });
|
||||
} else {
|
||||
// No reason means clean disconnect
|
||||
event = new CustomEvent("disconnect", { detail: {} });
|
||||
}
|
||||
this.dispatchEvent(event);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user