Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
Amadeus
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Wiki externe
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneurs
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
bakaclub
Amadeus
Validations
56be3dff
Vérifiée
Valider
56be3dff
rédigé
Il y a 4 ans
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
First command: the status command is working
parent
b43917fe
Branches
Branches contenant la validation
Aucune étiquette associée trouvée
2 requêtes de fusion
!3
Dev kubat
,
!1
Create basic lib
Modifications
3
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
common/lkt.js
+58
-14
58 ajouts, 14 suppressions
common/lkt.js
common/logger.js
+2
-1
2 ajouts, 1 suppression
common/logger.js
test/test_lkt.js
+5
-3
5 ajouts, 3 suppressions
test/test_lkt.js
avec
65 ajouts
et
18 suppressions
common/lkt.js
+
58
−
14
Voir le fichier @
56be3dff
const
logger
=
require
.
main
.
require
(
'
./common/logger.js
'
);
const
logger
=
require
.
main
.
require
(
'
./common/logger.js
'
);
const
net
=
require
(
'
net
'
);
const
net
=
require
(
'
net
'
);
/* The sleep function */
const
{
promisify
}
=
require
(
'
util
'
)
const
sleep
=
promisify
(
setTimeout
)
class
LktClient
{
class
LktClient
{
/***************************************
* Not static methods, do not use them *
***************************************/
/* The constructor
/* The constructor
* - host: String
* - host: String
* - port: String
* - port: String
*
*
* Private members
* Private members
* - m_socket: net.socket */
* - m_socket: net.socket
*
* Node: You should not use that directly, prefere the use of static
* methods */
constructor
(
port
=
6600
)
{
constructor
(
port
=
6600
)
{
this
.
m_online
=
false
;
this
.
m_online
=
false
;
this
.
m_port
=
port
;
this
.
m_port
=
port
;
this
.
m_socket
=
new
net
.
Socket
();
this
.
m_socket
=
new
net
.
Socket
();
this
.
m_closed
=
true
;
const
sockopt
=
{
const
sockopt
=
{
port
:
this
.
m_port
,
port
:
this
.
m_port
,
host
:
"
localhost
"
,
host
:
"
localhost
"
,
...
@@ -21,7 +33,7 @@ class LktClient {
...
@@ -21,7 +33,7 @@ class LktClient {
};
};
logger
.
debug
(
"
Creating the lektor client
"
);
logger
.
debug
(
"
Creating the lektor client
"
);
this
.
m_socket
.
setTimeout
(
1
0
);
this
.
m_socket
.
setTimeout
(
300
0
);
this
.
m_socket
.
setEncoding
(
'
utf8
'
);
this
.
m_socket
.
setEncoding
(
'
utf8
'
);
this
.
m_socket
.
on
(
"
timeout
"
,
()
=>
{
this
.
m_socket
.
on
(
"
timeout
"
,
()
=>
{
logger
.
error
(
`Got timeout while connecting to localhost:
${
this
.
m_port
}
`
);
logger
.
error
(
`Got timeout while connecting to localhost:
${
this
.
m_port
}
`
);
...
@@ -33,10 +45,6 @@ class LktClient {
...
@@ -33,10 +45,6 @@ class LktClient {
this
.
m_online
=
true
;
this
.
m_online
=
true
;
});
});
this
.
m_socket
.
on
(
'
data
'
,
(
data
)
=>
{
logger
.
debug
(
`Recieved "
${
data
.
replace
(
/
(\r\n
|
\n
|
\r)
/gm
,
""
)}
"`
);
});
this
.
m_socket
.
on
(
"
end
"
,
()
=>
{
this
.
m_socket
.
on
(
"
end
"
,
()
=>
{
logger
.
info
(
`Disconnected from server localhost:
${
this
.
m_port
}
`
);
logger
.
info
(
`Disconnected from server localhost:
${
this
.
m_port
}
`
);
this
.
m_online
=
false
;
this
.
m_online
=
false
;
...
@@ -59,17 +67,12 @@ class LktClient {
...
@@ -59,17 +67,12 @@ class LktClient {
logger
.
info
(
`Socket connected to localhost:
${
this
.
m_port
}
`
);
logger
.
info
(
`Socket connected to localhost:
${
this
.
m_port
}
`
);
this
.
m_online
=
true
;
this
.
m_online
=
true
;
});
});
}
/* Wait for the socket to be connected */
return
this
;
wait
()
{
logger
.
debug
(
`Waiting to connect to localhost:
${
this
.
m_port
}
`
);
var
i
=
0
;
while
(
!
this
.
m_online
)
{
}
}
}
/* Close the client */
/* Close the client.
* Note: Prefere using the static methods. */
close
()
{
close
()
{
if
(
this
.
m_online
)
{
if
(
this
.
m_online
)
{
logger
.
debug
(
"
Requesting socket shutdown
"
);
logger
.
debug
(
"
Requesting socket shutdown
"
);
...
@@ -77,7 +80,48 @@ class LktClient {
...
@@ -77,7 +80,48 @@ class LktClient {
}
else
{
}
else
{
logger
.
debug
(
"
Socket already closed
"
);
logger
.
debug
(
"
Socket already closed
"
);
}
}
this
.
m_closed
=
true
;
}
}
/*****************************************
* Static methods, to be used by clients *
*****************************************/
/* The status command */
static
commandStatus
()
{
var
client
=
new
this
();
var
once
=
false
;
var
result
=
{};
function
__getResult
(
client
)
{
return
new
Promise
(
resolv
=>
{
client
.
m_socket
.
on
(
"
data
"
,
(
data
)
=>
{
if
(
!
once
)
{
client
.
m_socket
.
write
(
"
status
\n
"
);
once
=
true
;
return
null
;
}
else
{
client
.
close
();
result
=
__mpdToObject
(
data
);
resolv
(
result
);
}
});
})
};
return
__getResult
(
client
);
}
}
function
__mpdToObject
(
string
)
{
var
ret
=
{};
string
.
split
(
"
\n
"
)
.
forEach
(
(
line
)
=>
{
if
(
line
.
length
<=
1
)
return
;
var
couple
=
line
.
split
(
/:
(
.+
)
/
).
slice
(
0
,
2
);
ret
[
couple
[
0
]]
=
couple
[
1
];
});
return
ret
;
}
}
module
.
exports
=
LktClient
;
module
.
exports
=
LktClient
;
Ce diff est replié.
Cliquez pour l'agrandir.
common/logger.js
+
2
−
1
Voir le fichier @
56be3dff
...
@@ -30,7 +30,8 @@ const __loggerCustomLevels = {
...
@@ -30,7 +30,8 @@ const __loggerCustomLevels = {
};
};
const
__myFormat
=
winston
.
format
.
printf
(({
level
,
message
,
label
,
timestamp
})
=>
{
const
__myFormat
=
winston
.
format
.
printf
(({
level
,
message
,
label
,
timestamp
})
=>
{
return
`[
${
timestamp
}
]
${
level
}
\t
${
message
}
`
;
// return `[${timestamp}] ${level}\t ${message}`;
return
`[
${
timestamp
}
]
${
message
}
`
;
});
});
module
.
exports
=
global
.
logger
=
module
.
exports
=
winston
.
createLogger
({
module
.
exports
=
global
.
logger
=
module
.
exports
=
winston
.
createLogger
({
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
test/test_lkt.js
+
5
−
3
Voir le fichier @
56be3dff
const
logger
=
require
.
main
.
require
(
'
./common/logger.js
'
);
const
logger
=
require
.
main
.
require
(
'
./common/logger.js
'
);
const
lkt
=
require
.
main
.
require
(
'
./common/lkt.js
'
);
const
lkt
=
require
.
main
.
require
(
'
./common/lkt.js
'
);
var
client
=
new
lkt
();
lkt
.
commandStatus
()
// client.wait();
.
then
(
(
res
)
=>
{
console
.
log
(
res
);
})
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter