aotrautils 0.0.256 → 0.0.257

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 (25/09/2022-18:14:33)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (27/09/2022-01:09:03)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -4827,7 +4827,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
4827
4827
 
4828
4828
 
4829
4829
 
4830
- /*utils CLIENT library associated with aotra version : «1_29072022-2359 (25/09/2022-18:14:33)»*/
4830
+ /*utils CLIENT library associated with aotra version : «1_29072022-2359 (27/09/2022-01:09:03)»*/
4831
4831
  /*-----------------------------------------------------------------------------*/
4832
4832
  /* ## Utility global methods in a browser (htmljs) client environment.
4833
4833
  *
@@ -11913,131 +11913,145 @@ createOritaMainClient=function(
11913
11913
  socketToServer.send("protocol", "request.register:mainClient:"+storedHashKey);
11914
11914
  }
11915
11915
 
11916
-
11917
-
11918
- }, urlParam, portParam, isSecure);
11919
11916
 
11917
+
11918
+
11919
+
11920
+
11921
+ // ------------------------------ CONNECTION EVENTS REGISTRATION ------------------------------
11920
11922
 
11921
- oritaClient.microClientsInfos={};
11922
- oritaClient.inputsGPIO={};
11923
- oritaClient.outputsGPIO={};
11924
11923
 
11925
11924
 
11926
-
11927
- // DBG
11928
- lognow("oritaClient (MAIN):",oritaClient);
11929
-
11925
+ // DBG
11926
+ lognow("oritaClient (MAIN):",oritaClient);
11930
11927
 
11931
-
11932
- oritaClient.client.socketToServer.receive("protocol", (message)=>{
11933
-
11934
- // TRACE
11935
- lognow("Mainclient received message from server:",message);
11936
-
11937
-
11938
- if(message.type==="response.mainClient.registered"){
11928
+
11939
11929
 
11940
- // TRACE
11941
- log("Main client registered to server.");
11942
-
11943
- // TRACE
11944
- log("Starting main receiving :");
11930
+ oritaClient.client.socketToServer.receive("protocol", (message)=>{
11945
11931
 
11932
+ // TRACE
11933
+ lognow("Mainclient received message from server:",message);
11946
11934
 
11947
11935
 
11936
+ if(message.type==="response.mainClient.registered"){
11948
11937
 
11949
- // Main client starts receiving :
11950
- oritaClient.client.socketToServer.receive("server.send.data", (receivedData)=>{
11951
-
11952
-
11953
- let microClientId=receivedData.microClientId;
11938
+ // TRACE
11939
+ log("Main client registered to server.");
11940
+
11941
+ // TRACE
11942
+ log("Starting main receiving :");
11954
11943
 
11955
- // // DEBUG
11956
- // lognow("INFO : MAINCLIENT : MainClient received data from microClient «"+microClientId+"» :",receivedData);
11957
11944
 
11958
- let compression=receivedData.compression;
11959
11945
 
11960
- // // DBG
11961
- // console.log("receivedData:",receivedData);
11962
- // console.log("receivedData.compression:",compression);
11963
11946
 
11964
- if(receivedData.video){// -------- VIDEO :
11965
-
11966
- if(compression){
11967
- // Actually, only handles "LZW" uncompression, for now...
11968
- let uncompressedData;
11969
- if(ORITA_CONSTANTS.STRINGIFY_VIDEO_DATA) uncompressedData=arrayFromString(receivedData.video.data, compression.algorithm?true:false, compression.precision);
11970
- else uncompressedData=receivedData.video.data;
11971
-
11972
- receivedData.video.data=uncompressedData;
11973
- }
11974
-
11975
- // // DBG
11976
- // console.log("received receivedData.length",receivedData);
11977
-
11978
-
11979
- let microClientInfos=oritaClient.microClientsInfos[microClientId];
11980
- if(!microClientInfos) oritaClient.microClientsInfos[microClientId]={};
11981
- microClientInfos=oritaClient.microClientsInfos[microClientId];
11982
- microClientInfos.hasVideo=true;
11983
-
11984
- oritaClient.microClientsInfos[microClientId].lastTime=getNow();
11947
+ // Main client starts receiving :
11948
+ oritaClient.client.socketToServer.receive("server.send.data", (receivedData)=>{
11949
+
11985
11950
 
11951
+ let microClientId=receivedData.microClientId;
11986
11952
 
11953
+ // // DEBUG
11954
+ // lognow("INFO : MAINCLIENT : MainClient received data from microClient «"+microClientId+"» :",receivedData);
11987
11955
 
11988
- treatVideoData();
11956
+ let compression=receivedData.compression;
11989
11957
 
11958
+ // // DBG
11959
+ // console.log("receivedData:",receivedData);
11960
+ // console.log("receivedData.compression:",compression);
11990
11961
 
11991
-
11992
- }else if(receivedData.audio){// -------- AUDIO :
11993
-
11994
- if(compression){
11995
- // Actually, only handles "LZW" uncompression, for now...
11996
- let uncompressedData;
11997
- if(ORITA_CONSTANTS.STRINGIFY_VIDEO_DATA) uncompressedData=arrayFromString(receivedData.audio.data, compression.algorithm?true:false, compression.precision);
11998
- else uncompressedData=receivedData.audio.data;
11962
+ if(receivedData.video){// -------- VIDEO :
11963
+
11964
+ if(compression){
11965
+ // Actually, only handles "LZW" uncompression, for now...
11966
+ let uncompressedData;
11967
+ if(ORITA_CONSTANTS.STRINGIFY_VIDEO_DATA) uncompressedData=arrayFromString(receivedData.video.data, compression.algorithm?true:false, compression.precision);
11968
+ else uncompressedData=receivedData.video.data;
11969
+
11970
+ receivedData.video.data=uncompressedData;
11971
+ }
11972
+
11973
+ // // DBG
11974
+ // console.log("received receivedData.length",receivedData);
11975
+
11976
+
11977
+ let microClientInfos=oritaClient.microClientsInfos[microClientId];
11978
+ if(!microClientInfos) oritaClient.microClientsInfos[microClientId]={};
11979
+ microClientInfos=oritaClient.microClientsInfos[microClientId];
11980
+ microClientInfos.hasVideo=true;
11981
+
11982
+ oritaClient.microClientsInfos[microClientId].lastTime=getNow();
11983
+
11984
+
11985
+
11986
+ treatVideoData();
11987
+
11999
11988
 
12000
- receivedData.audio.data=uncompressedData;
12001
- }
12002
-
12003
-
12004
- let microClientInfos=oritaClient.microClientsInfos[microClientId];
12005
- if(!microClientInfos) oritaClient.microClientsInfos[microClientId]={};
12006
- microClientInfos=oritaClient.microClientsInfos[microClientId];
12007
- microClientInfos.hasAudio=true;
12008
-
12009
- oritaClient.microClientsInfos[microClientId].lastTime=getNow();
12010
11989
 
11990
+ }else if(receivedData.audio){// -------- AUDIO :
11991
+
11992
+ if(compression){
11993
+ // Actually, only handles "LZW" uncompression, for now...
11994
+ let uncompressedData;
11995
+ if(ORITA_CONSTANTS.STRINGIFY_VIDEO_DATA) uncompressedData=arrayFromString(receivedData.audio.data, compression.algorithm?true:false, compression.precision);
11996
+ else uncompressedData=receivedData.audio.data;
11997
+
11998
+ receivedData.audio.data=uncompressedData;
11999
+ }
12000
+
12001
+
12002
+ let microClientInfos=oritaClient.microClientsInfos[microClientId];
12003
+ if(!microClientInfos) oritaClient.microClientsInfos[microClientId]={};
12004
+ microClientInfos=oritaClient.microClientsInfos[microClientId];
12005
+ microClientInfos.hasAudio=true;
12006
+
12007
+ oritaClient.microClientsInfos[microClientId].lastTime=getNow();
12008
+
12009
+
12010
+ treatAudioData();
12011
+
12011
12012
 
12012
- treatAudioData();
12013
+ }
12013
12014
 
12015
+ });
12014
12016
 
12015
- }
12016
12017
 
12017
- });
12018
-
12019
-
12018
+
12019
+
12020
+
12021
+ doOnRegistered();
12020
12022
 
12023
+ }
12021
12024
 
12022
12025
 
12023
- doOnRegistered();
12024
-
12025
- }
12026
-
12026
+
12027
+ });
12027
12028
 
12028
-
12029
- });
12030
-
12029
+
12030
+
12031
+ oritaClient.client.socketToServer.receive("communication", (message)=>{
12032
+
12033
+ // We execute eventual on message events listeners :
12034
+ foreach(onCommunicationEventListeners, (e)=>{
12035
+ if(!e.condition || e.condition(message)) e.execute(message);
12036
+ });
12037
+
12038
+ });
12039
+
12040
+
12041
+
12031
12042
 
12043
+
12044
+
12045
+
12046
+
12032
12047
 
12033
- oritaClient.client.socketToServer.receive("communication", (message)=>{
12048
+ }, urlParam, portParam, isSecure);
12034
12049
 
12035
- // We execute eventual on message events listeners :
12036
- foreach(onCommunicationEventListeners, (e)=>{
12037
- if(!e.condition || e.condition(message)) e.execute(message);
12038
- });
12039
12050
 
12040
- });
12051
+ oritaClient.microClientsInfos={};
12052
+ oritaClient.inputsGPIO={};
12053
+ oritaClient.outputsGPIO={};
12054
+
12041
12055
 
12042
12056
 
12043
12057
 
@@ -12088,10 +12102,7 @@ createOritaMainClient=function(
12088
12102
 
12089
12103
 
12090
12104
 
12091
- createOritaMicroClient=function(isNode=false){
12092
-
12093
-
12094
-
12105
+ createOritaMicroClient=function(url, port, isNode=false){
12095
12106
 
12096
12107
 
12097
12108
 
@@ -12105,7 +12116,6 @@ createOritaMicroClient=function(isNode=false){
12105
12116
  inputsGPIO:{},
12106
12117
 
12107
12118
 
12108
-
12109
12119
  };
12110
12120
 
12111
12121
 
@@ -12164,6 +12174,10 @@ createOritaMicroClient=function(isNode=false){
12164
12174
  oritaClient.client.socketToServer = WebsocketImplementation.getStatic(isNode).connectToServer(url, port);
12165
12175
  oritaClient.client.socketToServer.onConnectionToServer(() => {
12166
12176
 
12177
+
12178
+
12179
+
12180
+
12167
12181
  // TRACE
12168
12182
  console.log("INFO : MICRO CLIENT : Sending register request...");
12169
12183
 
@@ -12179,167 +12193,186 @@ createOritaMicroClient=function(isNode=false){
12179
12193
 
12180
12194
  oritaClient.client.socketToServer.send("protocol", "request.register:microClient:" + microClientId);
12181
12195
 
12182
- });
12183
-
12184
-
12185
12196
 
12186
- oritaClient.client.socketToServer.receive("protocol", (message) => {
12187
12197
 
12188
- // TRACE
12189
- lognow("INFO : MICRO CLIENT : Server sent a message on the protocol channel : message:", JSON.stringify(message));
12190
-
12191
-
12192
- if (contains(message.type, "response.microClient.registered")) {
12193
-
12194
- let microClientId = message.microClientId;
12195
12198
 
12196
- // To be sure this registration response does not concerns another micro client :
12197
- if (oritaClient.microClientId !== microClientId) return;
12198
-
12199
-
12200
- // DBG
12201
- lognow(" MICRO CLIENT REGISTERED : message:", message);
12202
-
12203
-
12204
- // CAUTION : ON TODAY, MICRO CLIENTS ONLY SUPPORT ONE MEDIA TO SEND AT THE TIME !!!
12205
- if (medias === "audio" || medias === "video") {
12206
-
12207
- // TRACE
12208
- lognow("Starting micro client sending method for micro client microClientId «" + microClientId + "»:");
12209
-
12210
-
12211
- // START SENDING AUDIO OR VIDEO :
12212
- // Refreshing rate calculus :
12213
- let refreshingRateMillis = REFRESHING_RATE_MILLIS_DEFAULT;
12214
- if (medias === "audio") {
12215
- // (We want millis, not seconds)
12216
- refreshingRateMillis = Math.floor((audioBufferSize / selfMediaHandler.getAudioSampleRate()) * 1000);
12217
- } else if (medias === "video") {
12218
- refreshingRateMillis = nonull(oritaClient.captureConfig.refreshMillis, ORITA_CONSTANTS.DEFAULT_CAPTURE_REFRESH_MILLIS);
12219
- }
12220
-
12221
- // *************************
12222
- // LOCAL SENDING LOOP :
12223
- oritaClient.sending = setInterval(function() {
12224
-
12225
- let data = {};
12226
- if (medias === "video") {
12227
-
12228
- let videoData = selfMediaHandler.getVideoData();
12229
-
12230
-
12231
- // // DBG
12232
- // console.log("INFO : MICRO CLIENT : videoData : ",videoData);
12233
-
12234
- if (videoData && videoData.data) {
12235
-
12236
- let videoRawData = videoData.data;
12237
-
12238
-
12239
- if (videoData.format !== "base64" && videoData.messWithAlpha) {
12240
- videoRawData = removeAlpha(videoRawData);
12199
+
12200
+
12201
+
12202
+ // ------------------------------ CONNECTION EVENTS REGISTRATION ------------------------------
12203
+
12204
+ oritaClient.client.socketToServer.receive("protocol", (message) => {
12205
+
12206
+ // TRACE
12207
+ lognow("INFO : MICRO CLIENT : Server sent a message on the protocol channel : message:", JSON.stringify(message));
12208
+
12209
+
12210
+ if (contains(message.type, "response.microClient.registered")) {
12211
+
12212
+ let microClientId = message.microClientId;
12213
+
12214
+ // To be sure this registration response does not concerns another micro client :
12215
+ if (oritaClient.microClientId !== microClientId) return;
12216
+
12217
+
12218
+ // DBG
12219
+ lognow(" MICRO CLIENT REGISTERED : message:", message);
12220
+
12221
+
12222
+ // CAUTION : ON TODAY, MICRO CLIENTS ONLY SUPPORT ONE MEDIA TO SEND AT THE TIME !!!
12223
+ if (medias === "audio" || medias === "video") {
12224
+
12225
+ // TRACE
12226
+ lognow("Starting micro client sending method for micro client microClientId «" + microClientId + "»:");
12227
+
12228
+
12229
+ // START SENDING AUDIO OR VIDEO :
12230
+ // Refreshing rate calculus :
12231
+ let refreshingRateMillis = REFRESHING_RATE_MILLIS_DEFAULT;
12232
+ if (medias === "audio") {
12233
+ // (We want millis, not seconds)
12234
+ refreshingRateMillis = Math.floor((audioBufferSize / selfMediaHandler.getAudioSampleRate()) * 1000);
12235
+ } else if (medias === "video") {
12236
+ refreshingRateMillis = nonull(oritaClient.captureConfig.refreshMillis, ORITA_CONSTANTS.DEFAULT_CAPTURE_REFRESH_MILLIS);
12237
+ }
12238
+
12239
+ // *************************
12240
+ // LOCAL SENDING LOOP :
12241
+ oritaClient.sending = setInterval(function() {
12242
+
12243
+ let data = {};
12244
+ if (medias === "video") {
12245
+
12246
+ let videoData = selfMediaHandler.getVideoData();
12247
+
12248
+
12249
+ // // DBG
12250
+ // console.log("INFO : MICRO CLIENT : videoData : ",videoData);
12251
+
12252
+ if (videoData && videoData.data) {
12253
+
12254
+ let videoRawData = videoData.data;
12255
+
12256
+
12257
+ if (videoData.format !== "base64" && videoData.messWithAlpha) {
12258
+ videoRawData = removeAlpha(videoRawData);
12259
+ }
12260
+
12261
+ // We set the Side is «left» or «right»
12262
+ if (videoSide) data.videoSide = videoSide;
12263
+
12264
+ // // TRACE
12265
+ // lognow("CLIENT : getting to send : videoRawData.length:"+videoRawData.length);
12266
+
12267
+ // Actually, only handles "LZW" compression, for now...
12268
+
12269
+ let stringToSend;
12270
+ if (ORITA_CONSTANTS.STRINGIFY_VIDEO_DATA) stringToSend = arrayToString(videoRawData, false, 1);
12271
+ else stringToSend = videoRawData;
12272
+
12273
+
12274
+
12275
+ data.video = {
12276
+ width: videoData.width,
12277
+ height: videoData.height,
12278
+ data: stringToSend,
12279
+ messWithAlpha: videoData.messWithAlpha,
12280
+ format: videoData.format,
12281
+ };
12282
+ data.compression = {
12283
+ precision: 1,
12284
+ // algorithm:"LZW"
12285
+ };
12286
+
12241
12287
  }
12242
-
12243
- // We set the Side is «left» or «right»
12244
- if (videoSide) data.videoSide = videoSide;
12245
-
12246
- // // TRACE
12247
- // lognow("CLIENT : getting to send : videoRawData.length:"+videoRawData.length);
12248
-
12288
+
12289
+ } else if (medias === "audio") {
12290
+
12291
+ let audioData = selfMediaHandler.getAudioData().data;
12292
+
12293
+ // // DBG
12294
+ // log("CLIENT : getting to send : audioData:"+audioData.length);
12295
+
12249
12296
  // Actually, only handles "LZW" compression, for now...
12250
-
12251
- let stringToSend;
12252
- if (ORITA_CONSTANTS.STRINGIFY_VIDEO_DATA) stringToSend = arrayToString(videoRawData, false, 1);
12253
- else stringToSend = videoRawData;
12254
-
12255
-
12256
-
12257
- data.video = {
12258
- width: videoData.width,
12259
- height: videoData.height,
12260
- data: stringToSend,
12261
- messWithAlpha: videoData.messWithAlpha,
12262
- format: videoData.format,
12263
- };
12264
- data.compression = {
12265
- precision: 1,
12266
- // algorithm:"LZW"
12267
- };
12268
-
12297
+ // DBG
12298
+ // let stringToSend=arrayToString(audioData,false,0.001);
12299
+ // data.audio={ data: stringToSend };
12300
+ // data.compression={precision:0.001,
12301
+ // // algorithm:"LZW"
12302
+ // };
12303
+
12304
+ // DBG
12305
+ data.audio = { data: audioData };
12306
+ data.compression = {};
12307
+
12308
+ } else { // Case no medias selected
12309
+ /*DO NOTHING*/
12310
+ // // TRACE
12311
+ // lognow("WARN : MICRO CLIENT : Caution, micro client has no data to send to main clients !");
12312
+ return;
12269
12313
  }
12270
-
12271
- } else if (medias === "audio") {
12272
-
12273
- let audioData = selfMediaHandler.getAudioData().data;
12274
-
12275
- // // DBG
12276
- // log("CLIENT : getting to send : audioData:"+audioData.length);
12277
-
12278
- // Actually, only handles "LZW" compression, for now...
12279
- // DBG
12280
- // let stringToSend=arrayToString(audioData,false,0.001);
12281
- // data.audio={ data: stringToSend };
12282
- // data.compression={precision:0.001,
12283
- // // algorithm:"LZW"
12284
- // };
12285
-
12286
- // DBG
12287
- data.audio = { data: audioData };
12288
- data.compression = {};
12289
-
12290
- } else { // Case no medias selected
12291
- /*DO NOTHING*/
12292
- // // TRACE
12293
- // lognow("WARN : MICRO CLIENT : Caution, micro client has no data to send to main clients !");
12294
- return;
12314
+
12315
+
12316
+ // // TRACE
12317
+ // lognow("CLIENT : SENDING DATA TO SERVER :");
12318
+ // // DBG
12319
+ // log("data:"+data);
12320
+
12321
+
12322
+ data.microClientId = oritaClient.microClientId;
12323
+
12324
+ // Micro client starts sending :
12325
+ oritaClient.client.socketToServer.send("microClient.send.data", data);
12326
+
12327
+
12328
+
12295
12329
  }
12296
-
12297
-
12298
- // // TRACE
12299
- // lognow("CLIENT : SENDING DATA TO SERVER :");
12300
- // // DBG
12301
- // log("data:"+data);
12302
-
12303
-
12304
- data.microClientId = oritaClient.microClientId;
12305
-
12306
- // Micro client starts sending :
12307
- oritaClient.client.socketToServer.send("microClient.send.data", data);
12308
-
12309
-
12310
-
12330
+ , refreshingRateMillis); // SENDING LOOP
12331
+ // *************************
12311
12332
  }
12312
- , refreshingRateMillis); // SENDING LOOP
12313
- // *************************
12333
+
12334
+
12335
+
12336
+ // We execute eventual on registration events listeners :
12337
+ foreach(oritaClient.onRegistrationEventListeners, (e) => {
12338
+ e.execute(microClientId, message);
12339
+ });
12340
+
12341
+
12342
+ //End of startResultPromise :
12343
+ resolve(oritaClient); // CAUTION : Media handler might be ready AFTER this point !
12314
12344
  }
12315
-
12316
-
12317
-
12318
- // We execute eventual on registration events listeners :
12319
- foreach(oritaClient.onRegistrationEventListeners, (e) => {
12320
- e.execute(microClientId, message);
12345
+
12346
+
12347
+
12348
+
12349
+
12350
+
12351
+ });
12352
+
12353
+
12354
+
12355
+
12356
+ oritaClient.client.socketToServer.receive("communication", (message) => {
12357
+ // We execute eventual on message events listeners :
12358
+ foreach(oritaClient.onCommunicationEventListeners, (e) => {
12359
+ if (!e.condition || e.condition(message)) e.execute(message);
12321
12360
  });
12361
+ });
12362
+
12363
+
12364
+
12322
12365
 
12323
12366
 
12324
- //End of startResultPromise :
12325
- resolve(oritaClient); // CAUTION : Media handler might be ready AFTER this point !
12326
- }
12327
-
12328
12367
 
12329
12368
 
12330
12369
 
12331
12370
 
12332
12371
 
12333
- });
12334
12372
 
12335
12373
 
12336
12374
 
12337
12375
 
12338
- oritaClient.client.socketToServer.receive("communication", (message) => {
12339
- // We execute eventual on message events listeners :
12340
- foreach(oritaClient.onCommunicationEventListeners, (e) => {
12341
- if (!e.condition || e.condition(message)) e.execute(message);
12342
- });
12343
12376
  });
12344
12377
 
12345
12378
 
@@ -12351,7 +12384,6 @@ createOritaMicroClient=function(isNode=false){
12351
12384
 
12352
12385
 
12353
12386
 
12354
-
12355
12387
  };
12356
12388
 
12357
12389
 
@@ -12905,7 +12937,7 @@ createOritaMicroClient=function(isNode=false){
12905
12937
  };
12906
12938
 
12907
12939
 
12908
- /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (25/09/2022-18:14:33)»*/
12940
+ /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (27/09/2022-01:09:03)»*/
12909
12941
  /*-----------------------------------------------------------------------------*/
12910
12942
 
12911
12943
 
@@ -14133,7 +14165,7 @@ function rayVsUnitSphereClosestPoint(p, r) {
14133
14165
  // MUST REMAIN AT THE END OF THIS LIBRARY FILE !
14134
14166
 
14135
14167
  AOTRAUTILS_GEOMETRY_LIB_IS_LOADED=true;
14136
- /*utils SERVER library associated with aotra version : «1_29072022-2359 (25/09/2022-18:14:33)»*/
14168
+ /*utils SERVER library associated with aotra version : «1_29072022-2359 (27/09/2022-01:09:03)»*/
14137
14169
  /*-----------------------------------------------------------------------------*/
14138
14170
 
14139
14171
 
aotrautils/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils",
3
- "version": "0.0.256",
3
+ "version": "0.0.257",
4
4
  "main": "aotrautils.build.js",
5
5
  "description": "A library for vanilla javascript utils (client-side) used in aotra javascript CMS",
6
6
  "author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",