Skip to content

Commit fa5ccaa

Browse files
Merge pull request #1 from thedumbterminal/reconnect
Reconnect when connection drops
2 parents 8a6353b + 48d78b0 commit fa5ccaa

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Changelog
2+
3+
## v1.1.0
4+
(16/07/2017)
5+
6+
* Will now reconnect when the websocket is closed.
7+
8+
## v1.0.4
9+
(07/03/2017)
10+
11+
* Secure websockets now supported.
12+
13+
## v1.0.3
14+
(07/03/2017)
15+
16+
* Websocket connection will now use correct hostname.
17+
18+
## v1.0.2
19+
(07/03/2017)
20+
21+
* Added dist directory to npm release.
22+
23+
## v1.0.1
24+
(05/03/2017)
25+
26+
* Documentation updated.
27+
28+
## v1.0.0
29+
(05/03/2017)
30+
31+
* Initial release

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
Tiny browser web framework, which communicates to the server via a websocket. All DOM changes are performed using HTML provided by the server.
77

8-
Minified size is **2.32** Kb which when transmitted compressed is **883** Bytes!
8+
Minified size is **2.56** Kb which when transmitted compressed is **945** Bytes!
99

1010
## Usage
1111

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tiny-browser-framework",
33
"description": "Minimal Client JS Framework",
4-
"version": "1.0.4",
4+
"version": "1.1.0",
55
"homepage": "https://github.com/thedumbterminal/TinyBrowserFramework",
66
"author": {
77
"name": "thedumbterminal",

src/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ TBF.prototype._setupWebsocket = function(){
99
var socketUrl = window.location.protocol.replace('http', 'ws') + '//' + window.location.host + '/websocket';
1010
this._websocket = new WebSocket(socketUrl);
1111
var self = this;
12+
this._websocket.onclose = function(event){
13+
setTimeout(function(){
14+
self._websocket.readyState > 1 && self._setupWebsocket();
15+
}, 1000)
16+
}
1217
this._websocket.onmessage = function(event){
1318
var jsons = JSON.parse(event.data);
1419
jsons.forEach(function(json){
@@ -24,9 +29,8 @@ TBF.prototype._augmentInterface = function(){
2429
}
2530
tags = document.getElementsByTagName('FORM');
2631
for(var i = 0; i < tags.length; i++){
27-
this._augmentForm(tags.item(i))
32+
this._augmentForm(tags.item(i));
2833
}
29-
3034
};
3135

3236
TBF.prototype._augmentButton = function(ele){
@@ -105,6 +109,9 @@ TBF.prototype._setupListeners = function(){
105109
document.addEventListener('DOMSubtreeModified', function(event) {
106110
self._augmentInterface();
107111
});
112+
window.onbeforeunload = function(){
113+
self._websocket && self._websocket.close();
114+
};
108115
};
109116

110117
window.tbfInstance = new TBF();

0 commit comments

Comments
 (0)