aotrautils-srv 0.0.2016 → 0.0.2017
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
/*utils COMMONS library associated with aotra version : «1_29072022-2359 (
|
|
3
|
+
/*utils COMMONS library associated with aotra version : «1_29072022-2359 (12/10/2026-21:35:03)»*/
|
|
4
4
|
/*-----------------------------------------------------------------------------*/
|
|
5
5
|
|
|
6
6
|
|
|
@@ -5485,7 +5485,7 @@ window.AOTRAUTILS_LIB_IS_LOADED=true;
|
|
|
5485
5485
|
|
|
5486
5486
|
|
|
5487
5487
|
|
|
5488
|
-
/*utils AI library associated with aotra version : «1_29072022-2359 (
|
|
5488
|
+
/*utils AI library associated with aotra version : «1_29072022-2359 (12/10/2026-21:35:03)»*/
|
|
5489
5489
|
/*-----------------------------------------------------------------------------*/
|
|
5490
5490
|
|
|
5491
5491
|
|
|
@@ -5749,7 +5749,7 @@ window.getLLMAPIClient=(modelName, apiURL, agentRole, defaultPrompt, llmProvider
|
|
|
5749
5749
|
|
|
5750
5750
|
|
|
5751
5751
|
|
|
5752
|
-
/*utils CONSOLE library associated with aotra version : «1_29072022-2359 (
|
|
5752
|
+
/*utils CONSOLE library associated with aotra version : «1_29072022-2359 (12/10/2026-21:35:03)»*/
|
|
5753
5753
|
/*-----------------------------------------------------------------------------*/
|
|
5754
5754
|
|
|
5755
5755
|
|
|
@@ -8156,11 +8156,19 @@ window.WebsocketImplementation={
|
|
|
8156
8156
|
useFlatStrings:false,
|
|
8157
8157
|
|
|
8158
8158
|
// COMMON METHODS
|
|
8159
|
-
/*
|
|
8160
|
-
return (!clientsRoomsTag || empty(clientsRoomsTag)
|
|
8159
|
+
/*public static*/isInRoom(clientSocket, clientsRoomsTag){
|
|
8160
|
+
return (!clientsRoomsTag || empty(clientsRoomsTag)
|
|
8161
|
+
|| !clientSocket || !clientSocket.clientRoomTag || empty(clientSocket.clientRoomTag)
|
|
8162
|
+
|| contains(clientsRoomsTag, clientSocket.clientRoomTag));
|
|
8161
8163
|
},
|
|
8162
8164
|
|
|
8163
|
-
|
|
8165
|
+
/*public static*/isInRightChannel(eventOrMessage, channelName){
|
|
8166
|
+
return (!eventOrMessage || empty(eventOrMessage)
|
|
8167
|
+
|| !eventOrMessage.channelName || empty(eventOrMessage.channelName)
|
|
8168
|
+
|| !channelName || empty(channelName)
|
|
8169
|
+
|| eventOrMessage.channelName==channelName);
|
|
8170
|
+
},
|
|
8171
|
+
|
|
8164
8172
|
//
|
|
8165
8173
|
// CONSOLE NODE SERVER/CLIENT
|
|
8166
8174
|
//
|
|
@@ -8462,7 +8470,8 @@ window.WebsocketImplementation={
|
|
|
8462
8470
|
};
|
|
8463
8471
|
|
|
8464
8472
|
|
|
8465
|
-
window.launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, doOnConnectionLost=null,
|
|
8473
|
+
window.launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=null, doOnConnectionLost=null,
|
|
8474
|
+
/*OPTIONAL*/sslOptions=null, httpHandlerParam=null,
|
|
8466
8475
|
addCORSHeader=ADD_CORS_HEADER_BY_DEFAULT){
|
|
8467
8476
|
|
|
8468
8477
|
const EXCLUDED_FILENAMES_PARTS=[".keyHash.",".pem"];
|
|
@@ -8480,28 +8489,32 @@ window.launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=
|
|
|
8480
8489
|
}
|
|
8481
8490
|
|
|
8482
8491
|
|
|
8483
|
-
const
|
|
8484
|
-
|
|
8492
|
+
const EXCLUSION_HANDLER=function(request, response){
|
|
8485
8493
|
const url=request.url;
|
|
8486
|
-
|
|
8487
|
-
|
|
8494
|
+
|
|
8495
|
+
const isURLInExclusionZone=!!foreach(EXCLUDED_FILENAMES_PARTS,(excludedStr)=>{
|
|
8488
8496
|
if(contains(url,excludedStr)){
|
|
8489
8497
|
return true;
|
|
8490
8498
|
}
|
|
8491
8499
|
});
|
|
8492
|
-
|
|
8493
8500
|
if(isURLInExclusionZone){
|
|
8494
|
-
|
|
8495
|
-
|
|
8496
|
-
|
|
8497
|
-
|
|
8498
|
-
|
|
8499
|
-
|
|
8500
|
-
|
|
8501
|
-
|
|
8502
|
-
|
|
8501
|
+
// TRACE
|
|
8502
|
+
lognow("ERROR 403 forbidden access error :");
|
|
8503
|
+
lognow("ERROR : request:",request);
|
|
8504
|
+
lognow("ERROR : response:",response);
|
|
8505
|
+
|
|
8506
|
+
response.writeHead(403);
|
|
8507
|
+
response.end("Sorry, cannot access resource : error: "+error.code+" ..\n");
|
|
8508
|
+
response.end();
|
|
8509
|
+
|
|
8510
|
+
throw new Error("ERROR : Not allowed to access this ressource.");
|
|
8503
8511
|
}
|
|
8512
|
+
};
|
|
8504
8513
|
|
|
8514
|
+
|
|
8515
|
+
const DEFAULT_HANDLER_HTTP_FILE_RETRIEVAL=function(request, response){
|
|
8516
|
+
|
|
8517
|
+
const url=request.url;
|
|
8505
8518
|
const urlFile="." + url;
|
|
8506
8519
|
|
|
8507
8520
|
let filePath=urlFile.indexOf("?")!==-1?urlFile.split("?")[0]:urlFile;
|
|
@@ -8517,26 +8530,26 @@ window.launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=
|
|
|
8517
8530
|
|
|
8518
8531
|
window.fs.readFile(filePath, function(error, fileContent){
|
|
8519
8532
|
if(error){
|
|
8520
|
-
|
|
8521
|
-
|
|
8522
|
-
|
|
8523
|
-
|
|
8524
|
-
|
|
8525
|
-
|
|
8526
|
-
|
|
8527
|
-
|
|
8528
|
-
|
|
8529
|
-
}else {
|
|
8530
|
-
|
|
8531
|
-
// TRACE
|
|
8532
|
-
lognow("ERROR 500 server error :");
|
|
8533
|
-
lognow("ERROR : error:",error);
|
|
8534
|
-
|
|
8535
|
-
response.writeHead(500);
|
|
8536
|
-
response.end("Sorry, check with the site admin for error: "+error.code+" ..\n");
|
|
8537
|
-
response.end();
|
|
8533
|
+
if(error.code=="ENOENT"){
|
|
8534
|
+
// TRACE
|
|
8535
|
+
console.log("ERROR 404 file not found :"+filePath);
|
|
8536
|
+
|
|
8537
|
+
window.fs.readFile("./404.html", function(error, fileContent){
|
|
8538
|
+
response.writeHead(200, headers);
|
|
8539
|
+
response.end(fileContent, "utf-8");
|
|
8540
|
+
});
|
|
8538
8541
|
|
|
8539
|
-
|
|
8542
|
+
}else {
|
|
8543
|
+
|
|
8544
|
+
// TRACE
|
|
8545
|
+
lognow("ERROR 500 server error :");
|
|
8546
|
+
lognow("ERROR : error:",error);
|
|
8547
|
+
|
|
8548
|
+
response.writeHead(500);
|
|
8549
|
+
response.end("Sorry, check with the site admin for error: "+error.code+" ..\n");
|
|
8550
|
+
response.end();
|
|
8551
|
+
|
|
8552
|
+
}
|
|
8540
8553
|
}else {
|
|
8541
8554
|
|
|
8542
8555
|
// TRACE
|
|
@@ -8552,11 +8565,77 @@ window.launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=
|
|
|
8552
8565
|
|
|
8553
8566
|
}
|
|
8554
8567
|
});
|
|
8555
|
-
|
|
8568
|
+
|
|
8556
8569
|
};
|
|
8557
8570
|
|
|
8558
8571
|
|
|
8559
|
-
|
|
8572
|
+
/*private static*/handleHTTPEndpoints=async function(request, response){
|
|
8573
|
+
const url=new URL(request.url, `https://${request.headers.host}`);
|
|
8574
|
+
|
|
8575
|
+
for(const httpEndpoint of handler.httpEndpoints){
|
|
8576
|
+
|
|
8577
|
+
|
|
8578
|
+
// EXPECTED : httpEndpoint={urlPath:"",httpMethod:""}
|
|
8579
|
+
|
|
8580
|
+
if(!httpEndpoint.urlPath || empty(httpEndpoint.urlPath) || url.pathname===httpEndpoint.urlPath){
|
|
8581
|
+
const requestHttpMethod=request.method;
|
|
8582
|
+
|
|
8583
|
+
try{
|
|
8584
|
+
let messageIn=null;
|
|
8585
|
+
if( requestHttpMethod=="GET" &&
|
|
8586
|
+
(!httpEndpoint.httpMethod || empty(httpEndpoint.httpMethod) || httpEndpoint.httpMethod.toUpperCase()=="GET")){
|
|
8587
|
+
|
|
8588
|
+
messageIn={...getRequestURLParameters(request)};
|
|
8589
|
+
|
|
8590
|
+
return true;
|
|
8591
|
+
}else if(requestHttpMethod=="POST"
|
|
8592
|
+
&& contains(["POST","PUT","PATCH","DELETE"],httpEndpoint.httpMethod.toUpperCase())){
|
|
8593
|
+
|
|
8594
|
+
messageIn={...getRequestURLParameters(request), ...(await getRequestBody(request))};
|
|
8595
|
+
}
|
|
8596
|
+
|
|
8597
|
+
if(messageIn){
|
|
8598
|
+
let httpEndpointResultObject={httpStatus:200, body:{}};
|
|
8599
|
+
const serverReceptionEntryPoint=httpEndpoint.serverReceptionEntryPoint;
|
|
8600
|
+
if(serverReceptionEntryPoint){
|
|
8601
|
+
httpEndpointResultObject.body=serverReceptionEntryPoint.execute(messageIn, null, false);
|
|
8602
|
+
}
|
|
8603
|
+
|
|
8604
|
+
response.writeHead(httpEndpointResultObject.httpStatus, { "Content-Type": "application/json" });
|
|
8605
|
+
response.end(JSON.stringify(httpEndpointResultObject.body));
|
|
8606
|
+
}
|
|
8607
|
+
|
|
8608
|
+
|
|
8609
|
+
}catch(error) {
|
|
8610
|
+
response.writeHead(erreur.error || 500, { "Content-Type": "application/json" });
|
|
8611
|
+
response.end(JSON.stringify({ error: erreur.error || "ERROR : HTTPO Endpoints encountered an error" }));
|
|
8612
|
+
}
|
|
8613
|
+
}
|
|
8614
|
+
|
|
8615
|
+
}
|
|
8616
|
+
|
|
8617
|
+
return false;
|
|
8618
|
+
};
|
|
8619
|
+
|
|
8620
|
+
const handler=function(request, response){
|
|
8621
|
+
|
|
8622
|
+
try{
|
|
8623
|
+
EXCLUSION_HANDLER(request, response);
|
|
8624
|
+
handleHTTPEndpoints(request, response).then(httpEndpointHasInterceptedRequest=>{
|
|
8625
|
+
if(!httpEndpointHasInterceptedRequest){
|
|
8626
|
+
nonull(httpHandlerParam, DEFAULT_HANDLER_HTTP_FILE_RETRIEVAL)(request, response);
|
|
8627
|
+
}
|
|
8628
|
+
}).catch(error=>{
|
|
8629
|
+
// TRACE
|
|
8630
|
+
lognow("ERROR : An error occurred when trying to execute HTTP endpoint :error:",error);
|
|
8631
|
+
});
|
|
8632
|
+
}catch(error){
|
|
8633
|
+
// TRACE
|
|
8634
|
+
lognow("ERROR : An error occurred when trying to process request :error:",error);
|
|
8635
|
+
}
|
|
8636
|
+
|
|
8637
|
+
};
|
|
8638
|
+
|
|
8560
8639
|
|
|
8561
8640
|
let listenableServer;
|
|
8562
8641
|
if(sslOptions){
|
|
@@ -8586,6 +8665,12 @@ window.launchNodeHTTPServer=function(port, doOnConnect=null, doOnFinalizeServer=
|
|
|
8586
8665
|
// TRACE
|
|
8587
8666
|
console.log("INFO : SERVER : Generic Nodejs server launched and listening on port:" + port + "!");
|
|
8588
8667
|
|
|
8668
|
+
|
|
8669
|
+
// Endpoints handling :
|
|
8670
|
+
server.httpEndpoints=[];
|
|
8671
|
+
handler.httpEndpoints=server.httpEndpoints;
|
|
8672
|
+
|
|
8673
|
+
|
|
8589
8674
|
return server;
|
|
8590
8675
|
}
|
|
8591
8676
|
|
|
@@ -9249,12 +9334,12 @@ if(typeof(window)==="undefined") window=global;
|
|
|
9249
9334
|
//
|
|
9250
9335
|
//window.WebsocketImplementation.implementationToUse.initOnReceiveBrowserContext(channelNameParam, (eventOrMessage)=>{ });
|
|
9251
9336
|
//
|
|
9252
|
-
//window.WebsocketImplementation.implementationToUse.initOnReceiveNodeContext(channelNameParam, serverReceptionEntryPoint);
|
|
9337
|
+
// //OLD: window.WebsocketImplementation.implementationToUse.initOnReceiveNodeContext(channelNameParam, serverReceptionEntryPoint);
|
|
9253
9338
|
//
|
|
9254
9339
|
//window.WebsocketImplementation.implementationToUse.getServerClients();
|
|
9255
9340
|
//
|
|
9256
9341
|
//if(window.WebsocketImplementation.implementationToUse.isReady(clientSocket)) return;
|
|
9257
|
-
// window.WebsocketImplementation.implementationToUse.initOnMessageReceived(doOnMessage);
|
|
9342
|
+
// //OLD : window.WebsocketImplementation.implementationToUse.initOnMessageReceived(doOnMessage);
|
|
9258
9343
|
// window.WebsocketImplementation.implementationToUse.terminate();
|
|
9259
9344
|
//
|
|
9260
9345
|
//window.WebsocketImplementation.implementationToUse.ping();
|
|
@@ -9431,9 +9516,7 @@ window.ClientReceptionEntryPoint=class ClientReceptionEntryPoint{
|
|
|
9431
9516
|
remove(clientReceptionEntryPoints, this);
|
|
9432
9517
|
|
|
9433
9518
|
if(this.doOnIncomingMessage){
|
|
9434
|
-
|
|
9435
9519
|
const dataRestored=restoreClassesInformation(dataLocal);
|
|
9436
|
-
|
|
9437
9520
|
this.doOnIncomingMessage(dataRestored, clientSocket);
|
|
9438
9521
|
}
|
|
9439
9522
|
|
|
@@ -9525,7 +9608,6 @@ window.ClientInstance=class ClientInstance{
|
|
|
9525
9608
|
return this;
|
|
9526
9609
|
}
|
|
9527
9610
|
|
|
9528
|
-
|
|
9529
9611
|
send(channelNameParam, data, clientsRoomsTag=null){
|
|
9530
9612
|
|
|
9531
9613
|
// // DBG
|
|
@@ -9544,17 +9626,17 @@ window.ClientInstance=class ClientInstance{
|
|
|
9544
9626
|
// CAUTION : WE CAN ONLY SEND STRINGS !!!
|
|
9545
9627
|
// (or else we'll have TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object)
|
|
9546
9628
|
// (Don't worry, the underlying sub-system will turn it back into Objects without you need to do anything!)
|
|
9547
|
-
|
|
9629
|
+
const dataWrappedStr=stringifyObject(dataWrapped);
|
|
9548
9630
|
|
|
9549
9631
|
// if(!window.WebsocketImplementation.useSocketIOImplementation)
|
|
9550
9632
|
if(!window.WebsocketImplementation.implementationToUse){
|
|
9551
|
-
clientSocket.send(
|
|
9633
|
+
clientSocket.send(dataWrappedStr);
|
|
9552
9634
|
}else{
|
|
9553
|
-
window.WebsocketImplementation.implementationToUse.send(
|
|
9635
|
+
window.WebsocketImplementation.implementationToUse.send(dataWrappedStr);
|
|
9554
9636
|
// clientSocket.emit(channelNameParam,dataWrapped);
|
|
9555
9637
|
}
|
|
9556
9638
|
|
|
9557
|
-
return
|
|
9639
|
+
return dataWrapped;
|
|
9558
9640
|
}
|
|
9559
9641
|
|
|
9560
9642
|
|
|
@@ -9654,16 +9736,114 @@ window.ClientInstance=class ClientInstance{
|
|
|
9654
9736
|
|
|
9655
9737
|
// ==================================================================================================================
|
|
9656
9738
|
|
|
9739
|
+
// NEW API :
|
|
9740
|
+
window.ServerReceptionEntryPointsBag=class ServerReceptionEntryPointsBag{
|
|
9741
|
+
|
|
9742
|
+
constructor(channelNameParam, server, clientsRoomsTag=null){
|
|
9743
|
+
this.channelName=channelNameParam;
|
|
9744
|
+
this.server=server;
|
|
9745
|
+
this.clientsRoomsTag=clientsRoomsTag;
|
|
9746
|
+
|
|
9747
|
+
this.serverReceptionEntryPoints=[];
|
|
9748
|
+
this.prerequisiteMethods=[];
|
|
9749
|
+
}
|
|
9750
|
+
|
|
9751
|
+
// Executed whenever any message is received on any channel :
|
|
9752
|
+
executeAll(eventOrMessage, clientSocket=null){ // FOR REAL-TIME ONLY :
|
|
9753
|
+
|
|
9754
|
+
|
|
9755
|
+
const clientsRoomsTag=this.clientsRoomsTag;
|
|
9756
|
+
if(!window.WebsocketImplementation.isInRoom(clientSocket, clientsRoomsTag)) return;
|
|
9757
|
+
|
|
9758
|
+
const channelName=this.channelName;
|
|
9759
|
+
if(!window.WebsocketImplementation.isInRightChannel(eventOrMessage, channelName)) return;
|
|
9760
|
+
|
|
9761
|
+
executeAllPrerequisites(eventOrMessage).then(prequisiteResult=>{
|
|
9762
|
+
const messageModifiedByPrerequisites=prequisiteResult;
|
|
9763
|
+
foreach(this.serverReceptionEntryPoints, (serverReceptionEntryPoint,i)=>{
|
|
9764
|
+
|
|
9765
|
+
// All listeners are executed IN PARALLEL !
|
|
9766
|
+
serverReceptionEntryPoint.execute(messageModifiedByPrerequisites, clientSocket).then((message)=>{
|
|
9767
|
+
/*DO NOTHING*/
|
|
9768
|
+
lognow("SERVER : DEBUG : Server sent message:",message);
|
|
9769
|
+
}).catch(treatmentsChannelError=>{
|
|
9770
|
+
|
|
9771
|
+
const errorMessage="INFO : An error has occured during the processing of a client message on channel treatments.";
|
|
9772
|
+
|
|
9773
|
+
// TRACE
|
|
9774
|
+
lognow(errorMessage, treatmentsChannelError);
|
|
9775
|
+
|
|
9776
|
+
const errorDataWrapped={errorMessage:errorMessage, cause:treatmentsChannelError};
|
|
9777
|
+
self.sendError(errorDataWrapped, clientSocketParam);
|
|
9778
|
+
|
|
9779
|
+
});
|
|
9780
|
+
|
|
9781
|
+
});
|
|
9782
|
+
|
|
9783
|
+
}).catch(error=>{
|
|
9784
|
+
// TRACE
|
|
9785
|
+
lognow("ERROR : (.executeAll()) A prerequisite encountered an error :", error);
|
|
9786
|
+
});
|
|
9787
|
+
|
|
9788
|
+
|
|
9789
|
+
|
|
9790
|
+
}
|
|
9791
|
+
|
|
9792
|
+
addReceiveListenerPrerequisite(prerequisiteMethod){
|
|
9793
|
+
this.prerequisiteMethods.push(prerequisiteMethod);
|
|
9794
|
+
}
|
|
9795
|
+
|
|
9796
|
+
async executeAllPrerequisites(eventOrMessage){
|
|
9797
|
+
let prequisiteResult=eventOrMessage;
|
|
9798
|
+
let i=1;
|
|
9799
|
+
try {
|
|
9800
|
+
for(const prerequisiteMethod of this.prerequisiteMethods) {
|
|
9801
|
+
prequisiteResult=await prerequisiteMethod(prequisiteResult, clientSocket);
|
|
9802
|
+
i++;
|
|
9803
|
+
}
|
|
9804
|
+
}catch(error){
|
|
9805
|
+
// TRACE
|
|
9806
|
+
lognow("ERROR : (.executeAllPrerequisites()) Prerequisite #"+i+" encountered an error :", error);
|
|
9807
|
+
}
|
|
9808
|
+
return prequisiteResult;
|
|
9809
|
+
}
|
|
9810
|
+
|
|
9811
|
+
|
|
9812
|
+
// ASYNC
|
|
9813
|
+
addReceiveListener(messageType, asyncDoOnIncomingMessage, httpEndpointDefinition=null){
|
|
9814
|
+
const channelNameParam=this.channelNameParam;
|
|
9815
|
+
const clientsRoomsTag=this.clientsRoomsTag;
|
|
9816
|
+
const messageTypes=(!messageType || empty(messageType) ? [] :
|
|
9817
|
+
(isArray(messageType) ? messageType : [messageType])
|
|
9818
|
+
);
|
|
9819
|
+
const listenerConfig={listenerMessageTypes:messageTypes, httpEndpointDefinition:httpEndpointDefinition};
|
|
9820
|
+
const serverReceptionEntryPoint=new window.ServerReceptionEntryPoint(channelNameParam, clientsRoomsTag, listenerConfig, asyncDoOnIncomingMessage);
|
|
9821
|
+
this.serverReceptionEntryPoints.push(serverReceptionEntryPoint);
|
|
9822
|
+
|
|
9823
|
+
if(httpEndpointDefinition){
|
|
9824
|
+
// TRACE
|
|
9825
|
+
lognow("INFO : Registered HTTP listener:",httpEndpointDefinition);
|
|
9826
|
+
this.server.httpEndpoints.push(httpEndpointDefinition);
|
|
9827
|
+
}
|
|
9828
|
+
|
|
9829
|
+
}
|
|
9830
|
+
|
|
9831
|
+
|
|
9832
|
+
|
|
9833
|
+
}
|
|
9834
|
+
|
|
9835
|
+
|
|
9836
|
+
|
|
9657
9837
|
window.ServerReceptionEntryPoint=class ServerReceptionEntryPoint{
|
|
9658
9838
|
|
|
9659
|
-
constructor(channelNameParam, clientsRoomsTag, listenerConfig=null,
|
|
9839
|
+
constructor(channelNameParam, clientsRoomsTag, listenerConfig=null, asyncDoOnIncomingMessage){
|
|
9660
9840
|
this.channelName=channelNameParam;
|
|
9661
9841
|
this.clientsRoomsTag=clientsRoomsTag;
|
|
9662
9842
|
this.listenerConfig=listenerConfig;
|
|
9663
|
-
this.
|
|
9843
|
+
this.asyncDoOnIncomingMessage=asyncDoOnIncomingMessage;
|
|
9664
9844
|
}
|
|
9665
9845
|
|
|
9666
|
-
execute(eventOrMessage, clientSocketParam){
|
|
9846
|
+
execute(eventOrMessage, clientSocketParam=null){
|
|
9667
9847
|
|
|
9668
9848
|
if(!eventOrMessage){
|
|
9669
9849
|
// TRACE
|
|
@@ -9671,13 +9851,13 @@ window.ServerReceptionEntryPoint=class ServerReceptionEntryPoint{
|
|
|
9671
9851
|
return;
|
|
9672
9852
|
}
|
|
9673
9853
|
|
|
9674
|
-
|
|
9675
|
-
|
|
9676
|
-
|
|
9677
|
-
|
|
9678
|
-
|
|
9854
|
+
// OLD :
|
|
9855
|
+
// if(!clientSocketParam){
|
|
9856
|
+
// // TRACE
|
|
9857
|
+
// lognow("ERROR : No clientSocket to client ! Cannot do reception treatment.");
|
|
9858
|
+
// return;
|
|
9859
|
+
// }
|
|
9679
9860
|
|
|
9680
|
-
|
|
9681
9861
|
// With «ws» library we have no choive than register message events inside a «connection» event !
|
|
9682
9862
|
|
|
9683
9863
|
const dataWrapped=window.WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
|
|
@@ -9687,28 +9867,23 @@ window.ServerReceptionEntryPoint=class ServerReceptionEntryPoint{
|
|
|
9687
9867
|
|
|
9688
9868
|
// Room information is stored in client socket object :
|
|
9689
9869
|
const isClientInRoom=window.WebsocketImplementation.isInRoom(clientSocketParam, this.clientsRoomsTag);
|
|
9690
|
-
|
|
9691
|
-
// // DBG
|
|
9692
|
-
// lognow("(SERVER) isClientInRoom:",isClientInRoom);
|
|
9693
|
-
|
|
9694
9870
|
if(!isClientInRoom) return;
|
|
9695
9871
|
|
|
9696
|
-
|
|
9697
|
-
if(
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
|
|
9872
|
+
|
|
9873
|
+
if(this.listenerConfig){
|
|
9874
|
+
// (CAUTION : if no message types is configured, then we accept this server listener)
|
|
9875
|
+
if(this.listenerConfig.listenerMessageTypes && !empty(this.listenerConfig.listenerMessageTypes)){
|
|
9876
|
+
// Else we check if the message matches the required message types :
|
|
9877
|
+
if( dataWrapped.data && dataWrapped.data.type
|
|
9878
|
+
&& !contains(this.listenerConfig.listenerMessageTypes, dataWrapped.data.type))
|
|
9879
|
+
return;
|
|
9880
|
+
}
|
|
9701
9881
|
}
|
|
9702
9882
|
|
|
9703
|
-
if(this.
|
|
9704
|
-
// // DBG
|
|
9705
|
-
// lognow("(SERVER) this.doOnIncomingMessage:");
|
|
9706
|
-
|
|
9883
|
+
if(this.asyncDoOnIncomingMessage){
|
|
9707
9884
|
const dataLocal=dataWrapped.data;
|
|
9708
|
-
|
|
9709
9885
|
const dataRestored=restoreClassesInformation(dataLocal);
|
|
9710
|
-
|
|
9711
|
-
this.doOnIncomingMessage(dataRestored, clientSocketParam);
|
|
9886
|
+
this.asyncDoOnIncomingMessage(dataRestored, clientSocketParam);
|
|
9712
9887
|
}
|
|
9713
9888
|
|
|
9714
9889
|
}
|
|
@@ -9727,8 +9902,12 @@ window.NodeServerInstance=class NodeServerInstance{
|
|
|
9727
9902
|
this.serverSocket=serverSocket;
|
|
9728
9903
|
|
|
9729
9904
|
this.listenableServer=listenableServer;
|
|
9905
|
+
|
|
9730
9906
|
this.serverReceptionEntryPoints=[];
|
|
9907
|
+
this.serverReceptionEntryPointsBags=[];
|
|
9731
9908
|
|
|
9909
|
+
this.httpEndpoints=null;
|
|
9910
|
+
|
|
9732
9911
|
}
|
|
9733
9912
|
|
|
9734
9913
|
setPingPongTimeout(clientPingIntervalMillis){
|
|
@@ -9755,34 +9934,54 @@ window.NodeServerInstance=class NodeServerInstance{
|
|
|
9755
9934
|
//sendChainable(channelNameParam, data, clientsRoomsTag=null){
|
|
9756
9935
|
//}
|
|
9757
9936
|
|
|
9758
|
-
// I-
|
|
9937
|
+
// I- (NOT ASYNC)
|
|
9938
|
+
// DEPRECATED, USE THE NEW API INSTEAD :
|
|
9759
9939
|
receive(channelNameParam, doOnIncomingMessage, listenerConfig=null, clientsRoomsTag=null){
|
|
9760
9940
|
|
|
9761
9941
|
// DBG
|
|
9762
|
-
lognow("(SERVER) Registering receive for «"+channelNameParam+"»...");
|
|
9942
|
+
lognow("(SERVER) Registering receive (OLD API) for channel «"+channelNameParam+"»...");
|
|
9763
9943
|
|
|
9764
|
-
const serverReceptionEntryPoint=new window.ServerReceptionEntryPoint(channelNameParam, clientsRoomsTag, listenerConfig
|
|
9944
|
+
const serverReceptionEntryPoint=new window.ServerReceptionEntryPoint(channelNameParam, clientsRoomsTag, listenerConfig
|
|
9945
|
+
,((doOnIncomingMessage && isAsyncFunction(doOnIncomingMessage)) ?
|
|
9946
|
+
doOnIncomingMessage
|
|
9947
|
+
: new Promise((resolve,reject)=>{if(doOnIncomingMessage) doOnIncomingMessage();resolve();}))
|
|
9948
|
+
);
|
|
9765
9949
|
this.serverReceptionEntryPoints.push(serverReceptionEntryPoint);
|
|
9766
9950
|
|
|
9767
|
-
|
|
9951
|
+
//OLD: // SPECIAL FOR THE SOCKETIO IMPLEMENTATION :
|
|
9768
9952
|
// if(window.WebsocketImplementation.useSocketIOImplementation){
|
|
9769
|
-
if(window.WebsocketImplementation.implementationToUse){
|
|
9770
|
-
window.WebsocketImplementation.implementationToUse.initOnReceiveNodeContext(channelNameParam, serverReceptionEntryPoint);
|
|
9953
|
+
//OLD: if(window.WebsocketImplementation.implementationToUse){
|
|
9954
|
+
//OLD: window.WebsocketImplementation.implementationToUse.initOnReceiveNodeContext(channelNameParam, serverReceptionEntryPoint);
|
|
9771
9955
|
// const channelName=serverReceptionEntryPoint.channelName;
|
|
9772
9956
|
// clientSocket.on(channelName, (eventOrMessage)=>{
|
|
9773
9957
|
// serverReceptionEntryPoint.execute(eventOrMessage, clientSocket);
|
|
9774
9958
|
// });
|
|
9775
|
-
}
|
|
9959
|
+
//OLD: }
|
|
9776
9960
|
|
|
9777
9961
|
return this;
|
|
9778
9962
|
}
|
|
9779
9963
|
|
|
9964
|
+
// NEW API :
|
|
9965
|
+
initReceiveListener(channelName, clientsRoomsTag=null){
|
|
9966
|
+
// DBG
|
|
9967
|
+
lognow("(SERVER) Registering receive (NEW API) for channel «"+channelName+"»...");
|
|
9968
|
+
|
|
9969
|
+
const serverReceptionEntryPointsBag=new window.ServerReceptionEntryPointsBag(channelName, this, clientsRoomsTag);
|
|
9970
|
+
this.serverReceptionEntryPointsBags.push(serverReceptionEntryPointsBag);
|
|
9971
|
+
|
|
9972
|
+
return serverReceptionEntryPointsBag;
|
|
9973
|
+
}
|
|
9974
|
+
|
|
9975
|
+
|
|
9780
9976
|
|
|
9781
9977
|
send(channelName, data, clientsRoomsTag=null, clientSocketParam=null){
|
|
9782
9978
|
|
|
9783
9979
|
// DBG
|
|
9784
9980
|
lognow("(SERVER) SERVER TRIES TO SEND !");
|
|
9785
9981
|
|
|
9982
|
+
// Channel information is stored in exchanged data :
|
|
9983
|
+
let dataWrapped=saveClassesInformation({channelName:channelName, data:data});
|
|
9984
|
+
|
|
9786
9985
|
|
|
9787
9986
|
if(!clientSocketParam){
|
|
9788
9987
|
|
|
@@ -9798,6 +9997,7 @@ window.NodeServerInstance=class NodeServerInstance{
|
|
|
9798
9997
|
// serverClients=this.serverSocket.sockets.sockets;
|
|
9799
9998
|
}
|
|
9800
9999
|
|
|
10000
|
+
|
|
9801
10001
|
serverClients.forEach((clientSocket)=>{
|
|
9802
10002
|
|
|
9803
10003
|
if(!window.isConnected(clientSocket)) return;
|
|
@@ -9805,20 +10005,20 @@ window.NodeServerInstance=class NodeServerInstance{
|
|
|
9805
10005
|
// Room information is stored in client socket object :
|
|
9806
10006
|
if(!window.WebsocketImplementation.isInRoom(clientSocket,clientsRoomsTag)) return;
|
|
9807
10007
|
|
|
9808
|
-
// Channel information is stored in exchanged data :
|
|
9809
|
-
let dataWrapped=saveClassesInformation({channelName:channelName, data:data});
|
|
9810
10008
|
|
|
9811
10009
|
// CAUTION : WE CAN ONLY SEND STRINGS !!!
|
|
9812
10010
|
// (or else we'll have TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object)
|
|
9813
10011
|
// (Don't worry, the underlying sub-system will turn it back into Objects without you need to do anything!)
|
|
9814
|
-
|
|
10012
|
+
const dataWrappedStr=stringifyObject(dataWrapped);
|
|
9815
10013
|
|
|
10014
|
+
if(clientSocketParam){
|
|
9816
10015
|
// if(!window.WebsocketImplementation.useSocketIOImplementation)
|
|
9817
|
-
|
|
9818
|
-
|
|
9819
|
-
|
|
9820
|
-
|
|
9821
|
-
// clientSocket.emit(channelName, dataWrapped);
|
|
10016
|
+
if(!window.WebsocketImplementation.implementationToUse){
|
|
10017
|
+
clientSocket.send(dataWrappedStr);
|
|
10018
|
+
}else{
|
|
10019
|
+
window.WebsocketImplementation.implementationToUse.serverSend(clientSocket, dataWrappedStr);
|
|
10020
|
+
// clientSocket.emit(channelName, dataWrapped);
|
|
10021
|
+
}
|
|
9822
10022
|
}
|
|
9823
10023
|
|
|
9824
10024
|
});
|
|
@@ -9826,7 +10026,7 @@ window.NodeServerInstance=class NodeServerInstance{
|
|
|
9826
10026
|
}else{
|
|
9827
10027
|
|
|
9828
10028
|
// DBG
|
|
9829
|
-
lognow("(SERVER) (server sends to a client)");
|
|
10029
|
+
lognow("(SERVER) (server sends to a single client)");
|
|
9830
10030
|
|
|
9831
10031
|
|
|
9832
10032
|
let clientSocket=clientSocketParam;
|
|
@@ -9842,27 +10042,26 @@ window.NodeServerInstance=class NodeServerInstance{
|
|
|
9842
10042
|
// Room information is stored in client socket object :
|
|
9843
10043
|
if(!window.WebsocketImplementation.isInRoom(clientSocket,clientsRoomsTag)) return;
|
|
9844
10044
|
|
|
9845
|
-
// Channel information is stored in exchanged data :
|
|
9846
|
-
let dataWrapped=saveClassesInformation({channelName:channelName, data:data});
|
|
9847
10045
|
|
|
9848
10046
|
// CAUTION : WE CAN ONLY SEND STRINGS !!!
|
|
9849
10047
|
// (or else we'll have TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of Object)
|
|
9850
10048
|
// (Don't worry, the underlying sub-system will turn it back into Objects without you need to do anything!)
|
|
9851
|
-
|
|
10049
|
+
const dataWrappedStr=stringifyObject(dataWrapped);
|
|
9852
10050
|
|
|
9853
|
-
|
|
9854
|
-
// if(!window.WebsocketImplementation.useSocketIOImplementation)
|
|
9855
|
-
|
|
9856
|
-
|
|
9857
|
-
|
|
9858
|
-
|
|
9859
|
-
// clientSocket.emit(channelName,dataWrapped);
|
|
10051
|
+
if(clientSocketParam){
|
|
10052
|
+
// if(!window.WebsocketImplementation.useSocketIOImplementation)
|
|
10053
|
+
if(!window.WebsocketImplementation.implementationToUse){
|
|
10054
|
+
clientSocket.send(dataWrappedStr);
|
|
10055
|
+
}else{
|
|
10056
|
+
window.WebsocketImplementation.implementationToUse.serverSend(clientSocket, dataWrappedStr);
|
|
10057
|
+
// clientSocket.emit(channelName,dataWrapped);
|
|
10058
|
+
}
|
|
9860
10059
|
}
|
|
9861
10060
|
|
|
9862
10061
|
}
|
|
9863
10062
|
|
|
9864
10063
|
|
|
9865
|
-
return
|
|
10064
|
+
return dataWrapped;
|
|
9866
10065
|
}
|
|
9867
10066
|
|
|
9868
10067
|
|
|
@@ -9902,9 +10101,16 @@ window.NodeServerInstance=class NodeServerInstance{
|
|
|
9902
10101
|
|
|
9903
10102
|
|
|
9904
10103
|
// We execute the events registration listeners entry points:
|
|
9905
|
-
|
|
9906
|
-
|
|
10104
|
+
// DEPRECATED : OLD API :
|
|
10105
|
+
foreach(self.serverReceptionEntryPoints, (serverReceptionEntryPoint,i)=>{
|
|
10106
|
+
serverReceptionEntryPoint.execute(eventOrMessage, clientSocket, true);
|
|
10107
|
+
});
|
|
10108
|
+
|
|
10109
|
+
// NEW API :
|
|
10110
|
+
foreach(self.serverReceptionEntryPointsBags, (serverReceptionEntryPointsBag,i)=>{
|
|
10111
|
+
serverReceptionEntryPointsBag.executeAll(eventOrMessage, clientSocket, true);
|
|
9907
10112
|
});
|
|
10113
|
+
|
|
9908
10114
|
};
|
|
9909
10115
|
|
|
9910
10116
|
// if(!window.WebsocketImplementation.useSocketIOImplementation){
|
|
@@ -9912,8 +10118,8 @@ window.NodeServerInstance=class NodeServerInstance{
|
|
|
9912
10118
|
// DOES NOT WORK WITH BUN : clientSocket.addEventListener("message", doOnMessage);
|
|
9913
10119
|
// DOES NOT WORK AT ALL : clientSocket.on("message", doOnMessage);
|
|
9914
10120
|
clientSocket.onmessage=doOnMessage;
|
|
9915
|
-
}else{
|
|
9916
|
-
|
|
10121
|
+
// OLD : }else{
|
|
10122
|
+
// OLD : window.WebsocketImplementation.implementationToUse.initOnMessageReceived(doOnMessage);
|
|
9917
10123
|
}
|
|
9918
10124
|
|
|
9919
10125
|
doOnConnection(this, clientSocket);
|
aotrautils-srv/package-lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aotrautils-srv",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2017",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "aotrautils-srv",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.2017",
|
|
10
10
|
"license": "HGPL-1.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"atob": "^2.1.2",
|
aotrautils-srv/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aotrautils-srv",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2017",
|
|
4
4
|
"main": "aotrautils-srv.build.js",
|
|
5
5
|
"description": "A library for vanilla javascript utils (server-side) used in aotra javascript CMS",
|
|
6
6
|
"author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",
|