Closed ionescu77 closed 3 years ago
I am using the html div from the index.html sample in the TypeScript folder of this repo:
<div class="information-wrapper">
<span class="information-title">DEVICE_ORIENTATION</span>
<span class="information-value" id="orientation"></span>
</div>
@ionescu77 Hi I'm sejoong. I test your code in my TV device(Tizen version 6.0), it works well. Can you share your device information and the version of the npm package?
$ npm list --depth=0
sample-typescript@2.0.0 D:\workspace\tsfy\tizen-common-web\samples\typescript
+-- @tizentv/wits@2.5.0
+-- @types/node@12.12.47
+-- @types/tizen-common-web@2.0.0
+-- @types/tizen-tv-webapis@2.0.0
+-- concurrently@5.2.0
+-- glob@7.1.6
+-- prettier@1.19.1
+-- tizen-common-web@2.0.1 -> D:\workspace\tsfy\tizen-common-web
+-- tizen-tv-webapis@2.0.0
+-- ts-loader@6.2.2
+-- typescript@3.9.5
+-- webpack@4.43.0
`-- webpack-cli@3.3.11
In my case, the package version are '@types/tizen-common-web@2.0.0and 'tizen-common-web@2.0.1
.
And also please check if you've already run build webpack before launching your application. "npm run webpack"
Hello, thank you:
@prozanne Yup I run the webpack, build the wgt
and then install and start it on the emulator.
@SejoongDeJang
Here is my npm (is a bit more extensive because I am using this in angular)
npm list --depth=0
mm-tizen-angular@0.0.0 /Users/razvansky/myProjects/mm-tizen-angular
โโโ __ngcc_entry_points__.json@ extraneous
โโโ @angular-devkit/build-angular@0.1102.8
โโโ @angular/animations@11.2.9
โโโ @angular/cli@11.2.8
โโโ @angular/common@11.2.9
โโโ @angular/compiler-cli@11.2.9
โโโ @angular/compiler@11.2.9
โโโ @angular/core@11.2.9
โโโ @angular/forms@11.2.9
โโโ @angular/platform-browser-dynamic@11.2.9
โโโ @angular/platform-browser@11.2.9
โโโ @angular/router@11.2.9
โโโ @types/jasmine@3.6.9
โโโ @types/node@12.20.7
โโโ @types/tizen-common-web@2.0.0
โโโ @types/tizen-tv-webapis@2.0.0
โโโ @types/video.js@7.3.15
โโโ animejs@3.2.1
โโโ child_process@1.0.2
โโโ codelyzer@6.0.1
โโโ gulp-clean-css@4.3.0
โโโ gulp-clean@0.4.0
โโโ gulp-rename@2.0.0
โโโ gulp-replace@1.0.0
โโโ gulp-run@1.7.1
โโโ gulp-template@5.0.0
โโโ gulp@4.0.2
โโโ jasmine-core@3.6.0
โโโ jasmine-spec-reporter@5.0.2
โโโ karma-chrome-launcher@3.1.0
โโโ karma-coverage@2.0.3
โโโ karma-jasmine-html-reporter@1.5.4
โโโ karma-jasmine@4.0.1
โโโ karma@6.1.2
โโโ merge-stream@2.0.0
โโโ protractor@7.0.0
โโโ readable-stream@3.6.0
โโโ rxjs@6.6.7
โโโ tizen-common-web@2.0.1
โโโ tizen-tv-webapis@2.0.0
โโโ ts-node@8.3.0
โโโ tslib@2.2.0
โโโ tslint@6.1.3
โโโ typescript@4.1.5
โโโ video.js@7.11.8
โโโ yargs@15.4.1
โโโ zone.js@0.11.4
It seems it is more like a problem accessing variables in TypeScript call-backs.
Can you actually see the deviceOrientation.status
in the html?
Really some more complex examples for FileSystem API or Alarm API for TypeScript would be so great :(
Hi @ionescu77
getPropertyValue( 'DEVICE_ORIENTATION', (deviceOrientation: SystemInfoDeviceOrientation) => {
console.log(deviceOrientation);
updateInformation('orientation', `${deviceOrientation.status}`
);
}
);
Here is my working code. Compare to your code, I figure out you don't declare type of the callback.
So I guess your problem is occurred because of the callback
. And the key is the SystemInfoPropertyType
, which is the first parameter of SystemInfoPropertySuccessCallback
, is a intersection type.
export interface SystemInfoPropertySuccessCallback {
(property: SystemInfoPropertyType): void;
}
export type SystemInfoPropertyType = SystemInfoBattery & SystemInfoCpu & SystemInfoStorage & SystemInfoStorageUnit & SystemInfoDisplay & SystemInfoPanel & SystemInfoDeviceOrientation & SystemInfoBuild & SystemInfoLocale & SystemInfoNetwork & SystemInfoWifiNetwork & SystemInfoEthernetNetwork & SystemInfoCellularNetwork & SystemInfoNetProxyNetwork & SystemInfoPeripheral & SystemInfoMemory & SystemInfoVideoSource ;
And I want to know what is the 'complex example'? Tell me the exactly API name, then we follow up your developing.
Hello @SejoongDeJang
I managed to get the callback to work! Nice observation indeed, about the callback. Thank you.
tizen.systeminfo.getPropertyValue('DEVICE_ORIENTATION', (e: any) => this.ngZone.run(() => {
this.updateInformation(
'orientation',
e.status
);
console.log('Dev orientation: ', e.status);
// this will update the global devOrientation variable
this.devOrientation = e.status;
}));
By complex example is tizen.download
. I do not manage to get it working in my Angular 11 project.
I think this also has to do with nagular/typescript, because I have difficulties translating the js
examples from ther Tizen Documentation :(.
For example this looks pretty straight forward:
javascript (found on the devforum, and similar to the official Tizen API download documentation examples:
var contentdownload = function () {
var url = 'https://dwdvhqfdmesuz.cloudfront.net/5bb5b552ab41a237a95db866/5bb5b618ab41a237a95db86b.jpeg';
var download_api_capability = tizen.systeminfo.getCapability("http://tizen.org/feature/download");
var wifi_capability = tizen.systeminfo.getCapability("http://tizen.org/feature/network.wifi");
var listener = {
onprogress: function(id, receivedSize, totalSize) {
console.log('Received with id: ' + id + ', ' + receivedSize + '/' + totalSize);
},
onpaused: function(id) {
console.log('Paused with id: ' + id);
},
oncanceled: function(id) {
console.log('Canceled with id: ' + id);
},
oncompleted: function(id, path) {
console.log('Completed with id: ' + id + ', path: ' + path);
},
onfailed: function(id, error) {
console.log('Failed with id: ' + id + ', error: ' , error); // returning error
}
};
var downloadRequest = new tizen.DownloadRequest(url, "Downloads"); var downloadId = tizen.download.start(downloadRequest, listener); }
### Convert to Typescript - no succes
No succes in implementing the listener and start the download request
```ts
downloadFile() {
var url = 'http://192.168.0.34:7979/media/poster_sample.png';
const download_api_capability = tizen.systeminfo.getCapability("http://tizen.org/feature/download");
var listener = {
onprogress: function(id, receivedSize, totalSize) {
console.log('Received with id: ' + id + ', ' + receivedSize + '/' + totalSize);
this.updateInformation("downloads", "download id: "+ id + ", " + receivedSize + "/" + totalSize);
},
onpaused: function(id) {
console.log('Paused with id: ' + id);
},
oncanceled: function(id) {
console.log('Canceled with id: ' + id);
},
oncompleted: function(id, path) {
console.log('Completed with id: ' + id + ', path: ' + path);
this.updateInformation("downloads","Completed id: " + id + ", path: " + path);
},
onfailed: function(id, error) {
console.log('Failed with id: ' + id + ', error: ' , error); // returning error
this.updateInformation("downloads","Failed witg id: " + id + ", error: " + error);
}
};
var downloadRequest = new tizen.DownloadRequest(url, "downloads");
var downloadId = tizen.download.start(downloadRequest, listener);
}
I have tried different combinations. Including:
var downloadId = tizen.download.start(downloadRequest, () => listener);
for which I get:
Argument of type '() => { onprogress: (id: any, receivedSize: any, totalSize: any) => void; onpaused: (id: any) => void; oncanceled: (id: any) => void; oncompleted: (id: any, path: any) => void; onfailed: (id: any, error: any) => void; }' is not assignable to parameter of type 'DownloadCallback'. Type '() => { onprogress: (id: any, receivedSize: any, totalSize: any) => void; onpaused: (id: any) => void; oncanceled: (id: any) => void; oncompleted: (id: any, path: any) => void; onfailed: (id: any, error: any) => void; }' is missing the following properties from type 'DownloadCallback': oncanceled, oncompleted, onfailed, onpaused, onprogressts(2345)
Obviously I am missing again some guidance about TypeScript implementation :(
Thank you,
Raz
PS I managed to trigger the download by leaving out the listener
, however I cannot monitor the download progress :(
@ionescu77 Here is my download request code.
try {
// Checks whether Download API is supported on a device.
var download_api_capability = systeminfo.getCapability(
'http://tizen.org/feature/download'
);
if (download_api_capability === false) {
console.log('Download API is not supported on this device');
}
console.log(`start download test`);
var listener = {
onprogress: function(
id: number,
receivedSize: number,
totalSize: number
) {
console.log(
'Received with id: ' +
id +
', ' +
receivedSize +
'/' +
totalSize
);
},
onpaused: function(id: number) {
console.log('Paused with id: ' + id);
},
oncanceled: function(id: number) {
console.log('Canceled with id: ' + id);
},
oncompleted: function(id: number, path: string) {
console.log('Completed with id: ' + id + ', path: ' + path);
},
onfailed: function(id: number, error: WebAPIError) {
console.log(
'Failed with id: ' + id + ', error name: ' + error.name
);
}
};
// Starts downloading the file from the Web with the corresponding callbacks.
var downloadRequest = new DownloadRequest(
'http://download.tizen.org/tools/README.txt',
'documents'
);
var downloadId = download.start(downloadRequest, listener);
console.log('downloadId :', downloadId);
} catch (error) {}
I wonder what is your editor. I think your question is related with syntax error of the typescripts. So I suggest set up vs code with this article, then you can easily inspect the syntax error.
And we discuss about uploading our typescript TC. It include whole usage of APIs.
Thank you for comming back to me.
I have an angular 11 project where I tried to implement as TypeScript, I am using Visual Studio Code with the Tizen extension.
I will give it a try.
I will find time and setup a public repo for the future to help others, too.
Hello @SejoongDeJang , the code which work for me in angular 11
var listener = {
onprogress: (id, receivedSize, totalSize) => {
console.log('Received with id: ' + id + ', ' + receivedSize + '/' + totalSize);
this.updateInformation("downloads", "download id: "+ id + ", " + receivedSize + "/" + totalSize);
},
onpaused: (id) => {
console.log('Paused with id: ' + id);
},
oncanceled: (id) => {
console.log('Canceled with id: ' + id);
},
oncompleted: (id, path) => {
console.log('Completed with id: ' + id + ', path: ' + path);
this.updateInformation("downloads","Completed id: " + id + ", path: " + path);
},
onfailed: (id, error) => {
console.log('Failed with id: ' + id + ', error: ' , error); // returning error
this.updateInformation("downloads","Failed with id: " + id + ", error: " + error);
}
};
// some other code, then
var downloadRequest = new DownloadRequest(url,"downloads");
var downloadId = download.start(downloadRequest, listener);
It is pretty similar, please note the "arrow functions", () => {}
maybe Angular needs them to pass the correct context, or event!?
Thank you for your help.
Best regards,
Raz
Hello,
I have managed to implement the methods presented in the TypeScript sample, thank you so much.
https://github.com/Samsung/tizen-common-web/blob/4ac6fdacbc9bb100cc37225f99bb3a442a8450c6/samples/typescript/src/main.ts#L14
However I cannot seem to write the proper callback for
DEVICE_ORIENTATION
:( ๐ฅ :Can you provide some more samples or help for more advanced API usage?
Thank you!