Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
add reconnect debug method #256
Browse files Browse the repository at this point in the history
  • Loading branch information
fomkin committed Jun 3, 2019
1 parent 7682a08 commit 99ecb4b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -11,7 +11,7 @@ branches:
- /.*-fixes/
scala:
- 2.11.12
- 2.12.4
- 2.12.8
cache:
directories:
- $HOME/.sbt
Expand Down
2 changes: 1 addition & 1 deletion bin/sauce_setup.sh
Expand Up @@ -2,7 +2,7 @@

OSNAME=`uname -s`
OSARCH=`uname -m`
SC_VERSION="4.4.10"
SC_VERSION="4.5.3"

mkdir target
cd target
Expand Down
25 changes: 25 additions & 0 deletions docs/user-guide.adoc
Expand Up @@ -622,3 +622,28 @@ class Config[F[_]: Effect] {
------------------------------

https://github.com/fomkin/korolev/blob/v0.8.0/examples/monix/src/main/scala/MonixExample.scala[See full example]

== Troubleshooting

=== Debug mode

You view Korolev's client-server exchange. Enter in developer console of your browser and execute this.

[source,javascript]
------------------------------
Korolev.setProtocolDebugEnabled(true)
------------------------------

Now you can see something like this.

------------------------------
-> [0,0 ]
-> [2,"click",false ]
<- [0,"0:1_3_1_1:click"]
-> [6,"/tab2" ]
-> [4,3,"1_3_1_1",0,"class","checkbox checkbox__checked",false,0,"1_3_1","1_3_1_2",0,"strike",1,"1_3_1_2","1_3_1_2_1","This is TODO #0" ]
-> [0,1 ]
------------------------------

Message starting with `->` is commands from server. Message started with `<-` is callback and client side events.
First number is always an procedure or callback code. You can protocol description https://github.com/fomkin/korolev/blob/v0.10.0/korolev/src/main/protocol.md[here].
22 changes: 16 additions & 6 deletions korolev/src/main/es6/connection.js
Expand Up @@ -28,6 +28,7 @@ export class Connection {
this._useSSL = location.protocol === "https:";

this._reconnectTimeout = MIN_RECONNECT_TIMEOUT;
this._webSocket = null;
this._webSocketsSupported = window.WebSocket !== undefined;
this._connectionType = ConnectionType.LONG_POLLING;
this._wasConnected = false;
Expand Down Expand Up @@ -80,15 +81,15 @@ export class Connection {
let url = (this._useSSL ? "wss://" : "ws://") + this._hostPort;
let path = this._serverRootPath + `bridge/web-socket/${this._deviceId}/${this._sessionId}`;
let uri = url + path;
let webSocket = new WebSocket(uri);

this._send = (data) => webSocket.send(data);
this._webSocket = new WebSocket(uri);
this._send = (data) => this._webSocket.send(data);
this._connectionType = ConnectionType.WEB_SOCKET;

webSocket.addEventListener('open', (event) => this._onOpen());
webSocket.addEventListener('close', (event) => this._onClose());
webSocket.addEventListener('error', (event) => this._onError());
webSocket.addEventListener('message', (event) => this._onMessage(event.data));
this._webSocket.addEventListener('open', (event) => this._onOpen());
this._webSocket.addEventListener('close', (event) => this._onClose());
this._webSocket.addEventListener('error', (event) => this._onError());
this._webSocket.addEventListener('message', (event) => this._onMessage(event.data));

console.log(`Trying to open connection to ${uri} using WebSocket`);
}
Expand Down Expand Up @@ -201,6 +202,15 @@ export class Connection {
this._send(data);
}

disconnect() {
if (this._webSocket != null) {
this._webSocket.close();
this._onClose();
} else {
console.log("Disconnect allowed only for WebSocket connections")
}
}

connect() {

if (this._wasConnected)
Expand Down
8 changes: 6 additions & 2 deletions korolev/src/main/es6/launcher.js
Expand Up @@ -4,8 +4,9 @@ import { ConnectionLostWidget, getDeviceId } from './utils.js';

// Export `setProtocolDebugEnabled` function
// to global scope
window['Bridge'] = {
'setProtocolDebugEnabled': setProtocolDebugEnabled
window['Korolev'] = {
'setProtocolDebugEnabled': setProtocolDebugEnabled,
'reconnect': () => console.log("Connection is not ready")
};

window.document.addEventListener("DOMContentLoaded", () => {
Expand All @@ -19,6 +20,9 @@ window.document.addEventListener("DOMContentLoaded", () => {
window.location
);

// Set reconnect handler
window['Korolev']['reconnect'] = () => connection.disconnect();

connection.dispatcher.addEventListener('open', () => {
clw.hide();
let bridge = new Bridge(config, connection);
Expand Down

0 comments on commit 99ecb4b

Please sign in to comment.