{"id":13615129,"url":"https://github.com/NodeRT/NodeRT","last_synced_at":"2025-04-13T20:33:06.264Z","repository":{"id":16224758,"uuid":"18972098","full_name":"NodeRT/NodeRT","owner":"NodeRT","description":"Winrt APIs-node.js modules generator","archived":false,"fork":false,"pushed_at":"2024-05-02T06:44:48.000Z","size":17092,"stargazers_count":668,"open_issues_count":84,"forks_count":66,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-03-28T21:03:49.956Z","etag":null,"topics":["electron","nodejs","nodert","uwp"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NodeRT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-04-20T19:29:19.000Z","updated_at":"2025-03-13T03:49:42.000Z","dependencies_parsed_at":"2024-06-09T20:34:33.889Z","dependency_job_id":"41ab4713-a3da-492d-9220-d59f2cd3032b","html_url":"https://github.com/NodeRT/NodeRT","commit_stats":{"total_commits":159,"total_committers":16,"mean_commits":9.9375,"dds":"0.35220125786163525","last_synced_commit":"cc0cf26fe97c44433a82c751be525d447dc12fa8"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NodeRT%2FNodeRT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NodeRT%2FNodeRT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NodeRT%2FNodeRT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NodeRT%2FNodeRT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NodeRT","download_url":"https://codeload.github.com/NodeRT/NodeRT/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247248938,"owners_count":20908202,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["electron","nodejs","nodert","uwp"],"created_at":"2024-08-01T20:01:09.731Z","updated_at":"2025-04-13T20:33:05.283Z","avatar_url":"https://github.com/NodeRT.png","language":"C++","funding_links":[],"categories":["C++","nodejs","electron"],"sub_categories":[],"readme":"# NodeRT: Use WinRT in Node, Electron, and NW.js\n\n:computer: Example\n```\nnpm install --save @nodert-win10-rs3/windows.ui.notifications\n```\n\n| SDK | Known As | Windows Version | npm Scope |\n| --- | --- | --- | --- |\n| Windows 10, Build 17134 | April 2018 Update (Redstone 4) | 1803 | [npmjs.com/org/nodert-win10-rs4](https://www.npmjs.com/org/nodert-win10-rs4) |\n| Windows 10, Build 16299 | Fall Creators Update (Redstone 3) | 1709 |  [npmjs.com/org/nodert-win10-rs3](https://www.npmjs.com/org/nodert-win10-rs3) |\n| Windows 10, Build 15063 | Creators Update (Redstone 2) | 1703 | [npmjs.com/org/nodert-win10-cu](https://www.npmjs.com/org/nodert-win10-cu) |\n| Windows 10, Build 14393 | Anniversary Update (Redstone 1) | 1607 | [npmjs.com/org/nodert-win10-au](https://www.npmjs.com/org/nodert-win10-au) |\n| Windows 10, Build 10586 | Threshold 2 | 1511 | [npmjs.com/~nodert-win10](https://www.npmjs.com/~nodert-win10) |\n\nFor an in-depth overview, [check out our `//build` talk][talk].\n\nIn general, any WinRT/UWP API that can be called by a desktop app can by called by\nNode.js or Electron using NodeRT. There are notable exceptions, but UWP APIs\nare [generally callable from desktop applications][desktop-callable].\n\nFor more examples of what NodeRT can do, check out the [samples](./samples).\n\n## :books: Documentation\n\nWe've split the documentation up into two parts. If you want to use NodeRT modules,\nread on. If you want to use NodeRT to compile your own WinRT modules, [see\nthe module creation guide](./MODULE_CREATION.md).\n\n * [Using NodeRT modules](#using-nodert-modules)\n * [Naming and Properties](#nodert-modules-naming-and-properties)\n * [Namespaces](#namespaces)\n * [Class inheritance and object casting](#class-inheritance-and-object-casting)\n * [Using WinRT streams in Node.js](#using-winrt-streams-in-node.js)\n * [Building and Consuming in Electron](#nodert-and-electron)\n * [License](#license)\n * [Attributions](#attributions)\n * [Contribute](#contribute)\n\n\n### Using NodeRT Modules\n\nNodeRT automatically exposes Microsoft’s UWP/WinRT APIs to the Node.js environment\nby generating Node modules for all Windows namespaces. This enables Node.js developers\nto write code that consumes native Windows capabilities. The generated modules' APIs\nare (almost) the same as the [WinRT APIs listed on MSDN][uwp-namespaces].\n\nAs an example, let's check out the `Windows.Devices.Geolocation` namespace to\nlocate the user from Node.js.\n\n:one: First, ensure that you have the Windows 10 SDK installed. In this example,\nwe're using the [Fall Creators Update SDK][sdk-archive].\n:two: Then, install `@nodert-win10-rs3/windows.devices.geolocation`. The npm\norganization denotes the used SDK version - in this case, it's the Fall Creators\nUpdate, which has the codename \"Redstone 3\".\n\n```sh\nnpm i --save @nodert-win10-rs3/windows.devices.geolocation\n```\n\nOnce you've installed the module, you're ready to use your computer's geolocation\nfeatures. In this example, we're creating a new `Geolocator` and are calling\nits instance method [`getGeopositionAsync()`][getgeopositionasync].\n\n```js\nconst { Geolocator } = require('windows.devices.geolocation')\nconst locator = new Geolocator()\n\nlocator.getGeopositionAsync((error, result) =\u003e {\n  if (error) {\n    console.error(error)\n    return\n  }\n\n  const { coordinate } = result\n  const { longitude, latitude } = coordinate\n\n  console.info(longitude, latitude)\n})\n```\n\nLet's take a closer look at the whole module:\n\n![Windows.Devices.Geolocation NodeRT module contents](/doc/images/object_contents.png)\n\nAs you can see, you can create new WinRT objects using the `new` operator. In\norder to inspect the method and properties of the object, you can inspect\nits prototype. For example, a new `Geolocator` object looks like this:\n\n```javascript\nconsole.log(new geolocation.Geolocator().__proto__)\n```\nAnd the output will be:\n\n![Geolocator prototype contents](/doc/images/golocation__proto.png)\n\n\u003e :memo: Note that property values are fetched on the fly, and hence have `undefined`\n\u003e values when printing the prototype.\n\n### Naming and Properties\n\nNodeRT uses the same JavaScript conventions as Microsoft does for\nJavaScript-based UWP applications.\n\n * Class/Enum names have the first letter in upper-case\n * Class/Enum fields (properties, methods, and events) always start with a\n   lower-case letter. The remainder of the name is identical to what you'd\n   find on MSDN.\n * Enums are JavaScript objects with keys corresponding to the enum\n   fields and values to the enum field's numeric values.\n\n#### Properties\n\nProperties on WinRT objects behave like JavaScript properties.\n\n```js\nlocator.reportInterval = 2000\nconsole.info(locator.reportInterval)\n```\n\n#### Synchronous methods\n\nStraight-forward JavaScript: Make the call with the appropriate arguments\nand don't even worry about the fact that you're calling native code. If\nthere are several WinRT overloads for the method, make the call with the\nright set of arguments and the correct overload of the method will be\ncalled:\n\n```js\nconst { XmlDocument }  = require('windows.data.xml.dom')\n\nconst xmlDoc = new xml.XmlDocument();\nxmlDoc.loadXml('\u003cnode\u003esome text here\u003c/node\u003e')\n```\n\n#### Asynchronous methods\n\nAsynchronous method accepts the same variables as listed on MSDN - with the\naddition of a completion callback as the last argument.\n\nThis callback will be called when the function has finished, and will receive\nan error as the first argument, and the result as the second argument:\n\n```js\nlocator.getGeopositionAsync((err, result) =\u003e {\n  if (error) {\n    console.error(error)\n    return\n  }\n\n  // Result is of type \"Geoposition\"\n  const { coordinate } = result\n  const { longitude, latitude } = coordinate\n\n  console.info(longitude, latitude)\n})\n```\n\n#### Events\n\nRegistering to events is done using the class' `on` method (which is equivalent\nto `addListener`), which receives the event name (case insensitive) and the\nevent handler function.\n\nFor example:\n\n```js\nconst handler = (sender, eventArgs) =\u003e {\n  console.info('status is:', eventArgs.status)\n}\n\nlocator.on('statusChanged', handler)\n```\n\nUnregistering from an event is done the same way, using the class's `off` or\n`removeListener` methods.\n\n```js\n// Using same event handler as in the example above\nlocator.off('statusChanged', handler);\n```\n\n### Namespaces\n\nEach NodeRT module represents a single namespace. For instance, `windows.storage`\nis its own NodeRT module - and `windows.storage.streams` is another NodeRT module.\n\nThe reason for this separation is strictly due to performance considerations.\nSeparating the code allows you to load only the code you actually intend to\nuse, meaning that Node.js won't fill the machine's memory.\n\nThis architecture means that in case you are using a NodeRT module which\ncontains a function, property, or event which returns an object from another\nnamespace, then you will need to require that namespace **before** calling\nthat function/property/event.\n\nFor example:\n\n```js\nconst capture = require('windows.media.capture')\n\n// We also require this module in order to be able to access\n// device controller properties\nconst devices = require('windows.media.devices')\n\nconst capture = new capture.MediaCapture()\n\ncapture.initializeAsync((error, result) =\u003e {\n  if (error) {\n    return console.error(error);\n  }\n\n  // Get the device controller, its type (VideoDeviceController) is defined in\n  // the windows.media.devices namespace. That's why we had to load\n  // windows.media.devices before calling this method.\n  const deviceController = capture.videoDeviceController\n\n  // We can now use the VideoDeviceController regularly\n  deviceController.brightness.trySetValue(-1)\n})\n```\n\n### Class inheritance and object casting\n\nSince some WinRT classes inherit from other classes. You might also need to cast an\nobject of a certain type to another type.\n\nIn order to do so, each NodeRT object has a static method named \u003cb\u003ecastFrom\u003c/b\u003e\nwhich accepts another object and tries to cast it to the class' type. Magical, right?\n\nThe following example casts an [IXmlNode][IXmlNode] object to an\n[XmlElement][XmlElement]:\n\n```js\nconst xml = require('windows.data.xml.dom')\n\n...\n\n// Obtain a list of nodes:\nconst nodesList = ....\nconst xmlNode = nodesList.getAt(0)\n\n// Cast xmlNode to XmlElement\nconst xmlElement = xml.XmlElement.castFrom(xmlNode)\n\n// We can now use XmlElement functions\nxmlElement.setAttribute('attr', 'value')\n```\n\n### Using WinRT streams in Node.js\n\nIn order to support the use of WinRT streams in Node.js, we have created the\n[`nodert-streams`][streams] module, which bridges between WinRT streams and\nNode.js streams.\n\nThis bridge enable the conversion of WinRT streams to Node.js streams, such\nthat WinRT streams could be used just as regular Node.js streams.\n\n### NodeRT and Electron\n\nNodeRT modules are native Node addons. As such, you'll need to compile\nthem for usage with Electron. If you're using an Electron boilerplate\nor CLI (like `electron-forge` or `electron-builder`), the embedded tools\nwill automatically compile the native code correctly.\n\nIf you are not using a boilerplate or are having trouble correctly compiling\nNodeRT modules, see Electron's documentation for [how to use native Node addons\nin Electron](https://electronjs.org/docs/tutorial/using-native-node-modules).\n\nFrom Electron v14 on, you'll have to require NodeRT modules in the `main` process.\nSee https://github.com/NodeRT/NodeRT/issues/158 for details.\n\n## License\n\nNodeRT is released under the Apache 2.0 license.\nFor more information, please take a look at the \u003ca href=\"./LICENSE\"\u003elicense\u003c/a\u003e file.\n\n## Attributions\n\nIn order to build NodeRT we used these 2 great libraries:\n* RazorTemplates - https://github.com/volkovku/RazorTemplates\n* RX.NET - https://github.com/Reactive-Extensions/Rx.NET/\n\n## Contribute\nYou are welcome to send us any bugs you may find, suggestions, or any other\ncomments. Before sending anything, please go over the repository issues list,\njust to make sure that it isn't already there.\n\nYou are more than welcome to fork this repository and send us a pull request\nif you feel that what you've done should be included.\n\n[talk]: https://www.youtube.com/watch?v=9z5xDyVRh6M\n[desktop-callable]: https://docs.microsoft.com/en-us/windows/desktop/apiindex/uwp-apis-callable-from-a-classic-desktop-app\n[uwp-namespaces]: http://msdn.microsoft.com/en-us/library/windows/apps/br211377.aspx\n[geolocation]: http://msdn.microsoft.com/library/windows/apps/br225603\n[sdk-archive]: https://developer.microsoft.com/en-us/windows/downloads/sdk-archive\n[getgeopositionasync]: https://docs.microsoft.com/en-us/uwp/api/windows.devices.geolocation.geolocator.getgeopositionasync\n[IXmlNode]: https://docs.microsoft.com/en-us/uwp/api/Windows.Data.Xml.Dom.IXmlNode\n[XmlElement]: https://docs.microsoft.com/en-us/uwp/api/Windows.Data.Xml.Dom.XmlElement\n[streams]: https://github.com/NodeRT/nodert-streams\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNodeRT%2FNodeRT","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNodeRT%2FNodeRT","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNodeRT%2FNodeRT/lists"}