From 1aab50816f6f9cbd8be4437f33c86b7e3120b471 Mon Sep 17 00:00:00 2001 From: Stijn Bernards Date: Thu, 14 May 2020 11:53:44 +0200 Subject: [PATCH] Adds open by appId and type (#29) * Minor spelling mistakes and promises now return booleans instead of strings * Add opening of app by type and appId to work around app searching --- src/samsung.ts | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/samsung.ts b/src/samsung.ts index 8779d53..bc002f4 100644 --- a/src/samsung.ts +++ b/src/samsung.ts @@ -179,6 +179,36 @@ class Samsung { return this._sendPromise(getMsgInstalledApp()) } + public openAppByAppIdAndType( + appId: string, + type: number, + done?: (error: Error | { code: string } | null, result: WSData | null) => void + ) { + this._send( + getMsgLaunchApp({app_type: type, appId, icon: '', is_lock: 0, name: ''}), + done + ) + } + + public openAppByAppIdAndTypePromise( + appId: string, + type: number, + ) { + return new Promise((resolve, reject) => { + this.openAppByAppIdAndType( + appId, + type, + (err, res) => { + if (err) { + reject(err) + } + + resolve(res) + } + ) + }) + } + public openApp( appId: string, done?: (err: Error | { code: string } | null, res: WSData | string | null) => void @@ -239,14 +269,14 @@ class Samsung { (err, response) => { if (!err) { this.LOGGER.log( - 'Link sended', + 'Link sent', { status: response.statusCode, body: response.body, headers: response.headers }, 'openYouTubeLink' ) - resolve('Link sended') + resolve('Link sent') } else { this.LOGGER.error('While send a link, somthing went wrong', { err }, 'openYouTubeLink') - reject('While send a link, somthing went wrong') + reject(err) } } )