File duilder.conf changed (mode: 100644) (index 199f3a1..c26f37a) |
... |
... |
CONFIG_H="Conn_config.h" |
17 |
17 |
RELEASE_SCRIPT="./duilder_release" |
RELEASE_SCRIPT="./duilder_release" |
18 |
18 |
RELEASE_SCRIPT="/usr/local/bin/duilder_release" |
RELEASE_SCRIPT="/usr/local/bin/duilder_release" |
19 |
19 |
|
|
20 |
|
CC_SWITCHES="-fstack-reuse=all -flto -Wtrampolines -Wl,-z,noexecstack" |
|
|
20 |
|
CC_SWITCHES="-O3 -fstack-reuse=all -flto -Wtrampolines -Wl,-z,noexecstack" |
21 |
21 |
CC_SWITCHES="${CC_SWITCHES} -Wl,-z,now -Wl,-z,relro -Wl,-O1 -Wl,-z,noexecstack" |
CC_SWITCHES="${CC_SWITCHES} -Wl,-z,now -Wl,-z,relro -Wl,-O1 -Wl,-z,noexecstack" |
22 |
22 |
CC_SWITCHES="${CC_SWITCHES} -fPIE -pie -fstack-protector-all" |
CC_SWITCHES="${CC_SWITCHES} -fPIE -pie -fstack-protector-all" |
23 |
23 |
CC_SWITCHES="${CC_SWITCHES} -Wcast-align -Wformat=2" |
CC_SWITCHES="${CC_SWITCHES} -Wcast-align -Wformat=2" |
|
... |
... |
CC_SWITCHES="${CC_SWITCHES} -Wmissing-prototypes -Wmissing-declarations" |
26 |
26 |
CC_SWITCHES="${CC_SWITCHES} -Wstrict-overflow -Wstrict-prototypes" |
CC_SWITCHES="${CC_SWITCHES} -Wstrict-overflow -Wstrict-prototypes" |
27 |
27 |
CC_SWITCHES="${CC_SWITCHES} -D _FORTIFY_SOURCES=2" |
CC_SWITCHES="${CC_SWITCHES} -D _FORTIFY_SOURCES=2" |
28 |
28 |
CC_SWITCHES="${CC_SWITCHES} -fno-guess-branch-probability -fbounds-check" |
CC_SWITCHES="${CC_SWITCHES} -fno-guess-branch-probability -fbounds-check" |
29 |
|
CC_SWITCHES="${CC_SWITCHES} -Wl,-O2 -Wpadded" |
|
|
29 |
|
CC_SWITCHES="${CC_SWITCHES} -Wl,-O3 -Wpadded" |
|
30 |
|
CC_SWITCHES="${CC_SWITCHES} -ftree-loop-distribution -ftree-vectorize -ftree-loop-if-convert" |
|
31 |
|
CC_SWITCHES="${CC_SWITCHES} -ftree-loop-im -ftree-parallelize-loops=4" |
30 |
32 |
|
|
31 |
33 |
# TODO |
# TODO |
32 |
34 |
#CC_SWITCHES="${CC_SWITCHES} -Wconversion" |
#CC_SWITCHES="${CC_SWITCHES} -Wconversion" |
File examples/websocket1.data/index.html added (mode: 100644) (index 0000000..0468a14) |
|
1 |
|
<!DOCTYPE html> |
|
2 |
|
<html> |
|
3 |
|
|
|
4 |
|
<head> |
|
5 |
|
<title>Websocket demo</title> |
|
6 |
|
<meta charset="utf-8" /> |
|
7 |
|
<meta name="viewport" content="width=device-width, initial-scale=1" /> |
|
8 |
|
<script type="text/javascript" src="main.js"></script> |
|
9 |
|
<link rel="stylesheet" href="main.css"> |
|
10 |
|
</head> |
|
11 |
|
|
|
12 |
|
<body onLoad="my_start()"> |
|
13 |
|
|
|
14 |
|
<!-- |
|
15 |
|
// This file is part of Conn project |
|
16 |
|
// https://rocketgit.com/user/catalinux/Conn |
|
17 |
|
// License: LGPLv3+ |
|
18 |
|
// Copyright: Catalin(ux) M. BOIE |
|
19 |
|
--> |
|
20 |
|
|
|
21 |
|
<div>Welcome to <a href="https://rocketgit.com/user/catalinux/Conn" target="_new">Conn</a> chat!</div> |
|
22 |
|
|
|
23 |
|
<div class="block"> |
|
24 |
|
Name: <input type="text" id="name" value="Anonymous" /> |
|
25 |
|
<button onClick="set_name();">Set name</button> |
|
26 |
|
</div> |
|
27 |
|
|
|
28 |
|
<div class="block"> |
|
29 |
|
Status: <span id="my_status">Status</span> |
|
30 |
|
</div> |
|
31 |
|
|
|
32 |
|
<div class="block"> |
|
33 |
|
<div id="chat"> |
|
34 |
|
Chat will show here!<br /> |
|
35 |
|
</div> |
|
36 |
|
</div> |
|
37 |
|
|
|
38 |
|
<div class="block"> |
|
39 |
|
<textarea id="msg" rows="3" placeholder="Type your message (press Enter or the Send button to send the message, Shift+Enter for new line)"></textarea> |
|
40 |
|
<button id="button_send" onClick="send_msg();">Send</button> |
|
41 |
|
</div> |
|
42 |
|
|
|
43 |
|
</body> |
|
44 |
|
|
|
45 |
|
</html> |
File examples/websocket1.data/main.js added (mode: 100644) (index 0000000..c5b8629) |
|
1 |
|
// This file is part of Conn project |
|
2 |
|
// https://rocketgit.com/user/catalinux/Conn |
|
3 |
|
// License: LGPLv3+ |
|
4 |
|
// Copyright: Catalin(ux) M. BOIE |
|
5 |
|
|
|
6 |
|
// TODO: escape html to avoid injecting scrpts in chat |
|
7 |
|
// TODO: Will the keepalive do its job? Or should I check if I got an answer for |
|
8 |
|
// the keepalive message and re-connect if not received? |
|
9 |
|
|
|
10 |
|
var my_ws_url = 'ws://' + window.location.host + '/ws'; |
|
11 |
|
var version = '1'; // version of the javascript code |
|
12 |
|
var timer, ka; |
|
13 |
|
var ws; |
|
14 |
|
var div_status, div_chat, div_msg, div_name; |
|
15 |
|
var reconnect_time_ms = 3000; |
|
16 |
|
var keep_alive_time_ms = 10000; |
|
17 |
|
var notify_perm; |
|
18 |
|
var last_msg = ''; |
|
19 |
|
|
|
20 |
|
function set_name() |
|
21 |
|
{ |
|
22 |
|
var data = { |
|
23 |
|
op: 'set_name', |
|
24 |
|
name: div_name.value |
|
25 |
|
}; |
|
26 |
|
//console.log('set_name...'); |
|
27 |
|
ws.send(JSON.stringify(data)); |
|
28 |
|
} |
|
29 |
|
|
|
30 |
|
function send_msg() |
|
31 |
|
{ |
|
32 |
|
var data = { |
|
33 |
|
op: 'msg', |
|
34 |
|
text: div_msg.value |
|
35 |
|
}; |
|
36 |
|
|
|
37 |
|
//console.log('send_msg...'); |
|
38 |
|
ws.send(JSON.stringify(data)); |
|
39 |
|
last_msg = div_msg.value; |
|
40 |
|
div_msg.value = ''; |
|
41 |
|
} |
|
42 |
|
|
|
43 |
|
function keep_alive() |
|
44 |
|
{ |
|
45 |
|
var data = { op: 'ka' }; |
|
46 |
|
|
|
47 |
|
//console.log('keep_alive...'); |
|
48 |
|
ws.send(JSON.stringify(data)); |
|
49 |
|
} |
|
50 |
|
|
|
51 |
|
function reconnect() |
|
52 |
|
{ |
|
53 |
|
div_status.innerHTML = 'Connecting...'; |
|
54 |
|
|
|
55 |
|
// We do not want the re-connect timer to trigger now, when |
|
56 |
|
// the connection is in progress. |
|
57 |
|
if (timer != undefined) // TODO: check if this is correct |
|
58 |
|
clearInterval(timer); |
|
59 |
|
|
|
60 |
|
if (ka != undefined) // TODO: check if this is correct |
|
61 |
|
clearInterval(ka); |
|
62 |
|
|
|
63 |
|
console.log('connecting...'); |
|
64 |
|
ws = new WebSocket(my_ws_url); |
|
65 |
|
|
|
66 |
|
ws.onopen = function(ev) |
|
67 |
|
{ |
|
68 |
|
var data = { |
|
69 |
|
op: 'init', |
|
70 |
|
version: version |
|
71 |
|
}; |
|
72 |
|
|
|
73 |
|
console.log('onopen: sending init...'); |
|
74 |
|
ws.send(JSON.stringify(data)); |
|
75 |
|
|
|
76 |
|
// Arm keep-alive timer |
|
77 |
|
clearInterval(ka); |
|
78 |
|
ka = setInterval(keep_alive, keep_alive_time_ms); |
|
79 |
|
|
|
80 |
|
div_status.innerHTML = 'Connected'; |
|
81 |
|
} |
|
82 |
|
|
|
83 |
|
ws.onerror = function(ev) |
|
84 |
|
{ |
|
85 |
|
console.log('onerror: ' + ev.reason); |
|
86 |
|
div_status.innerHTML = 'Error: ' + ev.reason + '!'; |
|
87 |
|
} |
|
88 |
|
|
|
89 |
|
ws.onmessage = function(ev) |
|
90 |
|
{ |
|
91 |
|
var j; |
|
92 |
|
|
|
93 |
|
//console.log('onmessage: data: ' + ev.data); |
|
94 |
|
j = JSON.parse(ev.data); |
|
95 |
|
|
|
96 |
|
if (j.op == 'ka') { |
|
97 |
|
//console.log('got a ka answer from server'); |
|
98 |
|
} else if (j.op == 'init') { |
|
99 |
|
//console.log('got answer to init command'); |
|
100 |
|
div_status.innerHTML = 'OK (id ' + j.id + ')'; |
|
101 |
|
} else if (j.op == 'msg') { |
|
102 |
|
div_chat.innerHTML += j.from + ': ' + j.msg + '<br />\n'; |
|
103 |
|
div_chat.scrollTop = div_chat.scrollHeight; |
|
104 |
|
|
|
105 |
|
// TODO: This only works on Firefox (mobile and desktop) |
|
106 |
|
// TODO: It does not work on Chrome 63 mobile |
|
107 |
|
if (notify_perm == 'granted') { |
|
108 |
|
var not = new Notification( |
|
109 |
|
'New message from ' + j.from, |
|
110 |
|
{ body: j.msg }); |
|
111 |
|
} |
|
112 |
|
} else { |
|
113 |
|
console.log('invalid op [' + j.op + '] [' + ev.data + ']'); |
|
114 |
|
} |
|
115 |
|
|
|
116 |
|
// re-arm the keep-alive timer |
|
117 |
|
clearInterval(ka); |
|
118 |
|
ka = setInterval(keep_alive, keep_alive_time_ms); |
|
119 |
|
} |
|
120 |
|
|
|
121 |
|
ws.onclose = function(ev) |
|
122 |
|
{ |
|
123 |
|
console.log('onclose: [' + ev.reason + '] ' + ev.code); |
|
124 |
|
timer = setInterval(reconnect, reconnect_time_ms); |
|
125 |
|
|
|
126 |
|
div_status.innerHTML = 'Connection closed: [' |
|
127 |
|
+ ev.reason + '] ' + ev.code + '!'; |
|
128 |
|
} |
|
129 |
|
|
|
130 |
|
//console.log('ws.readyState=' + ws.readyState); |
|
131 |
|
} |
|
132 |
|
|
|
133 |
|
function msg_key_event(e) |
|
134 |
|
{ |
|
135 |
|
//console.log('msg_key_event: e.keycode=' + e.keyCode); |
|
136 |
|
|
|
137 |
|
if (e.shiftKey) { |
|
138 |
|
// We want Shift+ENTER to be just a CR |
|
139 |
|
} else { |
|
140 |
|
switch (e.keyCode) { |
|
141 |
|
case 13: send_msg(); e.preventDefault(); return false; // enter - send message |
|
142 |
|
case 27: div_msg.value = ''; e.preventDefault(); return false; // escape cleans line |
|
143 |
|
case 38: div_msg.value = last_msg; e.preventDefault(); return false; // edit line |
|
144 |
|
} |
|
145 |
|
} |
|
146 |
|
} |
|
147 |
|
|
|
148 |
|
function my_start() |
|
149 |
|
{ |
|
150 |
|
div_name = document.getElementById('name'); |
|
151 |
|
div_status = document.getElementById('my_status'); |
|
152 |
|
div_chat = document.getElementById('chat'); |
|
153 |
|
div_msg = document.getElementById('msg'); |
|
154 |
|
|
|
155 |
|
// Ask permission for notifications (if not already granted) |
|
156 |
|
Notification.requestPermission().then(function(r) { notify_perm = r; }); |
|
157 |
|
|
|
158 |
|
// Add a listener for msg div |
|
159 |
|
div_msg.addEventListener('keydown', msg_key_event, false); |
|
160 |
|
|
|
161 |
|
reconnect(); |
|
162 |
|
} |
|
163 |
|
|
|
164 |
|
//ws.close(); |