@@ -4,6 +4,7 @@ import ballerina/io;
44import ballerina /log ;
55
66import maryamzi /sound ;
7+ import ballerina /lang .'string ;
78
89boolean wantJson = false ;
910boolean wantXml = false ;
@@ -164,6 +165,10 @@ service resultDataOnlyClientService = @http:WebSocketServiceConfig {} service {
164165 resource function onClose(http : WebSocketClient wsEp , int statusCode , string reason ) {
165166 log : printInfo (string ` Connection closed: statusCode: ${statusCode }, reason: ${reason }` );
166167 }
168+
169+ resource function onPing(http : WebSocketClient wsEp , byte [] data ) {
170+ logPingIfRequired (wsEp , data );
171+ }
167172};
168173
169174service awaitAndResultDataClientService = @http:WebSocketServiceCon fig {} service {
@@ -191,6 +196,10 @@ service awaitAndResultDataClientService = @http:WebSocketServiceConfig {} servic
191196 resource function onClose(http : WebSocketClient wsEp , int statusCode , string reason ) {
192197 log : printInfo (string ` Connection closed: statusCode: ${statusCode }, reason: ${reason }` );
193198 }
199+
200+ resource function onPing(http : WebSocketClient wsEp , byte [] data ) {
201+ logPingIfRequired (wsEp , data );
202+ }
194203};
195204
196205service imageAndResultDataClientService = @http:WebSocketServiceCon fig {} service {
@@ -220,6 +229,10 @@ service imageAndResultDataClientService = @http:WebSocketServiceConfig {} servic
220229 resource function onClose(http : WebSocketClient wsEp , int statusCode , string reason ) {
221230 log : printInfo (string ` Connection closed: statusCode: ${statusCode }, reason: ${reason }` );
222231 }
232+
233+ resource function onPing(http : WebSocketClient wsEp , byte [] data ) {
234+ logPingIfRequired (wsEp , data );
235+ }
223236};
224237
225238
@@ -257,6 +270,10 @@ service allClientService = @http:WebSocketServiceConfig {} service {
257270 resource function onClose(http : WebSocketClient wsEp , int statusCode , string reason ) {
258271 log : printInfo (string ` Connection closed: statusCode: ${statusCode }, reason: ${reason }` );
259272 }
273+
274+ resource function onPing(http : WebSocketClient wsEp , byte [] data ) {
275+ logPingIfRequired (wsEp , data );
276+ }
260277};
261278
262279function notifyAwait() {
@@ -265,3 +282,10 @@ function notifyAwait() {
265282 log : printError (" Error pinging on await notification" , pingStatus );
266283 }
267284}
285+
286+ function logPingIfRequired(http : WebSocketClient wsEp , byte [] data ) {
287+ log : printDebug (function () returns string {
288+ string | error res = 'string : fromBytes (data );
289+ return " onPing: " + (res is string ? res : data .toString ());
290+ });
291+ }
0 commit comments