{"id":23155035,"url":"https://github.com/tengattack/cronet.js","last_synced_at":"2025-04-04T16:44:54.128Z","repository":{"id":227117855,"uuid":"770506568","full_name":"tengattack/cronet.js","owner":"tengattack","description":"Cronet Node.js bindings","archived":false,"fork":false,"pushed_at":"2024-03-20T15:24:44.000Z","size":124,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-30T00:53:35.590Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tengattack.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":"2024-03-11T17:08:56.000Z","updated_at":"2024-08-10T17:24:36.000Z","dependencies_parsed_at":"2024-10-06T16:20:35.831Z","dependency_job_id":"2be1fbf7-e709-4ed0-8282-80ec1c5034c6","html_url":"https://github.com/tengattack/cronet.js","commit_stats":null,"previous_names":["tengattack/cronet.js"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tengattack%2Fcronet.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tengattack%2Fcronet.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tengattack%2Fcronet.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tengattack%2Fcronet.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tengattack","download_url":"https://codeload.github.com/tengattack/cronet.js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247215671,"owners_count":20903003,"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":[],"created_at":"2024-12-17T20:15:11.741Z","updated_at":"2025-04-04T16:44:54.114Z","avatar_url":"https://github.com/tengattack.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cronet.js\n\n[Cronet](https://chromium.googlesource.com/chromium/src/+/refs/heads/main/components/cronet)'s native API bindings for Node.js.\n\n## Installation\n\nThis native addon uses [CMake.js](https://github.com/cmake-js/cmake-js) to build when package install.\n\nSo we will need to fulfill its requirements at first.\n\n```sh\nnpm install cronet\n```\n\n## Usage\n\n```js\nconst { Buffer } = require('node:buffer')\nconst cronetjs = require('cronet')\nconst {\n  CronetEngineParams,\n  CronetEngine,\n  CronetExecutor,\n  CronetUrlRequestCallback,\n  CronetUrlRequestParams,\n  CronetUrlRequest,\n} = cronetjs\n\n// dynamic load library\nCronetEngine.loadLibrary('libcronet.so')\n\nconst params = new CronetEngineParams()\nparams.enableQuic = true // by default\nconst engine = new CronetEngine()\nconsole.log('CronetEngine version: ' + engine.versionString)\nengine.startWithParams(params)\n\nconst executor = new CronetExecutor()\nexecutor.start()\n\nfunction newRequest(url, timeout = 2000) {\n  return new Promise((resolve, reject) =\u003e {\n    const urlReq = new CronetUrlRequest()\n\n    let body = null\n\n    let t = setTimeout(function () {\n      if (!t) {\n        return\n      }\n      console.log('Request timeout.')\n      t = null\n      urlReq.cancel()\n    }, timeout)\n\n    const done = function () {\n      if (t) {\n        clearTimeout(t)\n        t = null\n      }\n      resolve(body)\n    }\n\n    const urlReqParams = new CronetUrlRequestParams()\n    urlReqParams.httpMethod = 'GET'\n    urlReqParams.disableCache = true\n\n    const urlCallback = new CronetUrlRequestCallback()\n    urlCallback.onRedirectReceived = function (request, info, newLocationUrl) {\n      console.log('onFollowRedirect: ' + info.httpStatusCode + ' ' + newLocationUrl)\n      request.followRedirect()\n    }\n    urlCallback.onResponseStarted = function (request, info) {\n      console.log('onResponseStarted: ' + info.url\n        + ' ' + info.negotiatedProtocol\n        + ' ' + info.httpStatusCode + ' ' + info.httpStatusText)\n\n      console.log('All headers:')\n      const allHeadersListSize = info.allHeadersListSize()\n      for (let i = 0; i \u003c allHeadersListSize; i++) {\n        const header = info.allHeadersListAt(i)\n        console.log({ name: header.name, value: header.value })\n      }\n\n      let buffer = new cronetjs.CronetBuffer()\n      // Create and allocate 32kb buffer.\n      buffer.initWithAlloc(32 * 1024)\n      // Started reading the response.\n      request.read(buffer)\n    }\n    urlCallback.onReadCompleted = function (request, info, buffer, bytesRead) {\n      console.log('onReadCompleted, bytes read: ' + bytesRead)\n      const bytes = buffer.data.slice(0, bytesRead)\n      if (!body) {\n        body = Buffer.from(bytes)\n      } else {\n        body = Buffer.concat([body, bytes])\n      }\n      // Continue reading the response.\n      request.read(buffer)\n    }\n    urlCallback.onSucceeded = function (request, info) {\n      console.log('onSucceeded')\n      done()\n    }\n    urlCallback.onFailed = function (request, info, error) {\n      console.log('onFailed, message: ' + error.message\n        + ', error_code: ' + error.errorCode\n        + ', internal_error_code: ' + error.internalErrorCode)\n      done()\n    }\n    urlCallback.onCanceled = function (request, info) {\n      console.log('onCanceled')\n      done()\n    }\n\n    urlReq.initWithParams(engine, url, urlReqParams, urlCallback, executor)\n    urlReq.start()\n  })\n}\n\nasync function main() {\n  await newRequest('https://google.com/', 2000)\n  executor.shutdown()\n  engine.shutdown()\n}\n\nmain()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftengattack%2Fcronet.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftengattack%2Fcronet.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftengattack%2Fcronet.js/lists"}