diff --git a/index.html b/index.html
index b8e6747..66c93dd 100644
--- a/index.html
+++ b/index.html
@@ -250,7 +250,8 @@
console.log(this.contacts);
},
async sendCommandGetDeviceTime() {
- await this.connection.sendCommandGetDeviceTime();
+ const deviceTime = await this.connection.getDeviceTime();
+ console.log(deviceTime);
},
async sendCommandSetDeviceTime() {
const timestamp = Math.floor(Date.now() / 1000);
diff --git a/src/connection/connection.js b/src/connection/connection.js
index fbc728a..636cf58 100644
--- a/src/connection/connection.js
+++ b/src/connection/connection.js
@@ -664,6 +664,37 @@ class Connection extends EventEmitter {
});
}
+ getDeviceTime() {
+ return new Promise(async (resolve, reject) => {
+ try {
+
+ // resolve promise when we receive sent response
+ const onCurrTime = (response) => {
+ this.off(Constants.ResponseCodes.CurrTime, onCurrTime);
+ this.off(Constants.ResponseCodes.Err, onErr);
+ resolve(response);
+ }
+
+ // reject promise when we receive err
+ const onErr = () => {
+ this.off(Constants.ResponseCodes.CurrTime, onCurrTime);
+ this.off(Constants.ResponseCodes.Err, onErr);
+ reject();
+ }
+
+ // listen for events
+ this.once(Constants.ResponseCodes.CurrTime, onCurrTime);
+ this.once(Constants.ResponseCodes.Err, onErr);
+
+ // get device time
+ await this.sendCommandGetDeviceTime();
+
+ } catch(e) {
+ reject(e);
+ }
+ });
+ }
+
}
export default Connection;