author | Edouard Tisserant |
Wed, 02 Oct 2019 11:31:02 +0200 | |
branch | svghmi |
changeset 2789 | ba0dd2ec6dc4 |
parent 2788 | 2ed9ff826d03 |
child 2798 | ddb2c4668a6b |
permissions | -rw-r--r-- |
2783
5ee6967f721d
SVGHMI: Starting to define JS side more in details.
Edouard Tisserant
parents:
2780
diff
changeset
|
1 |
// svghmi.js |
5ee6967f721d
SVGHMI: Starting to define JS side more in details.
Edouard Tisserant
parents:
2780
diff
changeset
|
2 |
|
2780
e468f18df200
SVGHMI: moved static JS code to a separate file included at xhtml generation time
Edouard Tisserant
parents:
diff
changeset
|
3 |
(function(){ |
2783
5ee6967f721d
SVGHMI: Starting to define JS side more in details.
Edouard Tisserant
parents:
2780
diff
changeset
|
4 |
// Open WebSocket to relative "/ws" address |
5ee6967f721d
SVGHMI: Starting to define JS side more in details.
Edouard Tisserant
parents:
2780
diff
changeset
|
5 |
var ws = new WebSocket(window.location.href.replace(/^http(s?:\/\/[^\/]*)\/.*$/, 'ws$1/ws')); |
5ee6967f721d
SVGHMI: Starting to define JS side more in details.
Edouard Tisserant
parents:
2780
diff
changeset
|
6 |
|
5ee6967f721d
SVGHMI: Starting to define JS side more in details.
Edouard Tisserant
parents:
2780
diff
changeset
|
7 |
// Register message reception handler |
2780
e468f18df200
SVGHMI: moved static JS code to a separate file included at xhtml generation time
Edouard Tisserant
parents:
diff
changeset
|
8 |
ws.onmessage = function (evt) { |
2783
5ee6967f721d
SVGHMI: Starting to define JS side more in details.
Edouard Tisserant
parents:
2780
diff
changeset
|
9 |
// TODO : dispatch and cache hmi tree updates |
5ee6967f721d
SVGHMI: Starting to define JS side more in details.
Edouard Tisserant
parents:
2780
diff
changeset
|
10 |
|
2780
e468f18df200
SVGHMI: moved static JS code to a separate file included at xhtml generation time
Edouard Tisserant
parents:
diff
changeset
|
11 |
var received_msg = evt.data; |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2783
diff
changeset
|
12 |
// TODO : check for hmitree hash header |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2783
diff
changeset
|
13 |
// if not matching, reload page |
2780
e468f18df200
SVGHMI: moved static JS code to a separate file included at xhtml generation time
Edouard Tisserant
parents:
diff
changeset
|
14 |
alert("Message is received..."+received_msg); |
e468f18df200
SVGHMI: moved static JS code to a separate file included at xhtml generation time
Edouard Tisserant
parents:
diff
changeset
|
15 |
}; |
2783
5ee6967f721d
SVGHMI: Starting to define JS side more in details.
Edouard Tisserant
parents:
2780
diff
changeset
|
16 |
|
5ee6967f721d
SVGHMI: Starting to define JS side more in details.
Edouard Tisserant
parents:
2780
diff
changeset
|
17 |
// Once connection established |
2780
e468f18df200
SVGHMI: moved static JS code to a separate file included at xhtml generation time
Edouard Tisserant
parents:
diff
changeset
|
18 |
ws.onopen = function (evt) { |
2783
5ee6967f721d
SVGHMI: Starting to define JS side more in details.
Edouard Tisserant
parents:
2780
diff
changeset
|
19 |
// TODO : enable the HMI (was previously offline, or just starts) |
5ee6967f721d
SVGHMI: Starting to define JS side more in details.
Edouard Tisserant
parents:
2780
diff
changeset
|
20 |
// show main page |
5ee6967f721d
SVGHMI: Starting to define JS side more in details.
Edouard Tisserant
parents:
2780
diff
changeset
|
21 |
|
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2783
diff
changeset
|
22 |
|
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2783
diff
changeset
|
23 |
// TODO : prefix with hmitree hash header |
2780
e468f18df200
SVGHMI: moved static JS code to a separate file included at xhtml generation time
Edouard Tisserant
parents:
diff
changeset
|
24 |
ws.send("test"); |
e468f18df200
SVGHMI: moved static JS code to a separate file included at xhtml generation time
Edouard Tisserant
parents:
diff
changeset
|
25 |
}; |
e468f18df200
SVGHMI: moved static JS code to a separate file included at xhtml generation time
Edouard Tisserant
parents:
diff
changeset
|
26 |
})(); |