mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 02:54:11 +08:00

* chore: move tns-core-modules to nativescript-core * chore: preparing compat generate script * chore: add missing definitions * chore: no need for http-request to be private * chore: packages chore * test: generate tests for tns-core-modules * chore: add anroid module for consistency * chore: add .npmignore * chore: added privateModulesWhitelist * chore(webpack): added bundle-entry-points * chore: scripts * chore: tests changed to use @ns/core * test: add scoped-packages test project * test: fix types * test: update test project * chore: build scripts * chore: update build script * chore: npm scripts cleanup * chore: make the compat pgk work with old wp config * test: generate diff friendly tests * chore: create barrel exports * chore: move files after rebase * chore: typedoc config * chore: compat mode * chore: review of barrels * chore: remove tns-core-modules import after rebase * chore: dev workflow setup * chore: update developer-workflow * docs: experiment with API extractor * chore: api-extractor and barrel exports * chore: api-extractor configs * chore: generate d.ts rollup with api-extractor * refactor: move methods inside Frame * chore: fic tests to use Frame static methods * refactor: create Builder class * refactor: use Builder class in tests * refactor: include Style in ui barrel * chore: separate compat build script * chore: fix tslint errors * chore: update NATIVESCRIPT_CORE_ARGS * chore: fix compat pack * chore: fix ui-test-app build with linked modules * chore: Application, ApplicationSettings, Connectivity and Http * chore: export Trace, Profiling and Utils * refactor: Static create methods for ImageSource * chore: fix deprecated usages of ImageSource * chore: move Span and FormattedString to ui * chore: add events-args and ImageSource to index files * chore: check for CLI >= 6.2 when building for IOS * chore: update travis build * chore: copy Pod file to compat package * chore: update error msg ui-tests-app * refactor: Apply suggestions from code review Co-Authored-By: Martin Yankov <m.i.yankov@gmail.com> * chore: typings and refs * chore: add missing d.ts files for public API * chore: adress code review FB * chore: update api-report * chore: dev-workflow for other apps * chore: api update * chore: update api-report
225 lines
6.3 KiB
TypeScript
225 lines
6.3 KiB
TypeScript
export namespace domains {
|
|
export namespace network {
|
|
export interface NetworkDomainDebugger {
|
|
create(): domains.network.NetworkRequest;
|
|
}
|
|
|
|
export interface Headers {
|
|
}
|
|
|
|
export interface Request {
|
|
url: string;
|
|
method: string;
|
|
headers: domains.network.Headers;
|
|
postData?: string;
|
|
}
|
|
|
|
export interface Response {
|
|
url: string;
|
|
status: number;
|
|
statusText: string;
|
|
headers: Headers;
|
|
headersText?: string;
|
|
mimeType: string;
|
|
requestHeaders?: domains.network.Headers;
|
|
requestHeadersText?: string;
|
|
fromDiskCache?: boolean;
|
|
}
|
|
|
|
export interface NetworkRequest {
|
|
mimeType: string;
|
|
data: any;
|
|
responseReceived(response: domains.network.Response);
|
|
loadingFinished();
|
|
requestWillBeSent(request: domains.network.Request);
|
|
}
|
|
}
|
|
}
|
|
|
|
let network;
|
|
|
|
export function getNetwork(): domains.network.NetworkDomainDebugger {
|
|
return network;
|
|
}
|
|
export function setNetwork(newNetwork: domains.network.NetworkDomainDebugger) {
|
|
network = newNetwork;
|
|
}
|
|
|
|
let dom;
|
|
|
|
export function getDOM(): any {
|
|
return dom;
|
|
}
|
|
|
|
export function setDOM(newDOM) {
|
|
dom = newDOM;
|
|
}
|
|
|
|
let css;
|
|
|
|
export function getCSS(): any {
|
|
return css;
|
|
}
|
|
|
|
export function setCSS(newCSS) {
|
|
css = newCSS;
|
|
}
|
|
|
|
export namespace NetworkAgent {
|
|
export interface Request {
|
|
url: string;
|
|
method: string;
|
|
headers: any;
|
|
initialPriority: string;
|
|
referrerPolicy: string;
|
|
postData?: string;
|
|
}
|
|
|
|
export interface RequestData {
|
|
requestId: string;
|
|
url: string;
|
|
request: Request;
|
|
timestamp: number;
|
|
type: string;
|
|
wallTime: number;
|
|
}
|
|
|
|
export interface Response {
|
|
url: string;
|
|
status: number;
|
|
statusText: string;
|
|
headers: any;
|
|
headersText?: string;
|
|
mimeType: string;
|
|
connectionReused: boolean;
|
|
connectionId: number;
|
|
encodedDataLength: number;
|
|
securityState: string;
|
|
fromDiskCache?: boolean;
|
|
}
|
|
|
|
export interface ResponseData {
|
|
requestId: string;
|
|
type: string;
|
|
response: Response;
|
|
timestamp: number;
|
|
}
|
|
|
|
export interface SuccessfulRequestData {
|
|
requestId: string;
|
|
data: string;
|
|
hasTextContent: boolean;
|
|
}
|
|
|
|
export interface LoadingFinishedData {
|
|
requestId: string;
|
|
timestamp: number;
|
|
}
|
|
|
|
export function responseReceived(requestId: number, result: org.nativescript.widgets.Async.Http.RequestResult, headers: any) {
|
|
const requestIdStr = requestId.toString();
|
|
// Content-Type and content-type are both common in headers spelling
|
|
const mimeType: string = <string>headers["Content-Type"] || <string>headers["content-type"] || "application/octet-stream";
|
|
const contentLengthHeader: string = <string>headers["Content-Length"] || <string>headers["content-length"];
|
|
let contentLength = parseInt(contentLengthHeader, 10);
|
|
if (isNaN(contentLength)) {
|
|
contentLength = 0;
|
|
}
|
|
|
|
const response: NetworkAgent.Response = {
|
|
url: result.url || "",
|
|
status: result.statusCode,
|
|
statusText: result.statusText || "",
|
|
headers: headers,
|
|
mimeType: mimeType,
|
|
fromDiskCache: false,
|
|
connectionReused: true,
|
|
connectionId: 0,
|
|
encodedDataLength: contentLength,
|
|
securityState: "info"
|
|
};
|
|
|
|
const responseData: NetworkAgent.ResponseData = {
|
|
requestId: requestIdStr,
|
|
type: mimeTypeToType(response.mimeType),
|
|
response: response,
|
|
timestamp: getTimeStamp()
|
|
};
|
|
|
|
global.__inspector.responseReceived(responseData);
|
|
global.__inspector.loadingFinished({
|
|
requestId: requestIdStr,
|
|
timestamp: getTimeStamp(),
|
|
encodedDataLength: contentLength
|
|
});
|
|
|
|
const hasTextContent = responseData.type === "Document" || responseData.type === "Script";
|
|
let data;
|
|
|
|
if (!hasTextContent) {
|
|
if (responseData.type === "Image") {
|
|
const bitmap = result.responseAsImage;
|
|
if (bitmap) {
|
|
const outputStream = new java.io.ByteArrayOutputStream();
|
|
bitmap.compress(android.graphics.Bitmap.CompressFormat.PNG, 100, outputStream);
|
|
|
|
const base64Image = android.util.Base64.encodeToString(outputStream.toByteArray(), android.util.Base64.DEFAULT);
|
|
data = base64Image;
|
|
}
|
|
}
|
|
} else {
|
|
data = result.responseAsString;
|
|
}
|
|
|
|
const successfulRequestData: NetworkAgent.SuccessfulRequestData = {
|
|
requestId: requestIdStr,
|
|
data: data,
|
|
hasTextContent: hasTextContent
|
|
};
|
|
|
|
global.__inspector.dataForRequestId(successfulRequestData);
|
|
}
|
|
|
|
export function requestWillBeSent(requestId: number, options: any) {
|
|
const request: NetworkAgent.Request = {
|
|
url: options.url,
|
|
method: options.method,
|
|
headers: options.headers || {},
|
|
postData: options.content ? options.content.toString() : "",
|
|
initialPriority: "Medium",
|
|
referrerPolicy: "no-referrer-when-downgrade"
|
|
};
|
|
|
|
const requestData: NetworkAgent.RequestData = {
|
|
requestId: requestId.toString(),
|
|
url: request.url,
|
|
request: request,
|
|
timestamp: getTimeStamp(),
|
|
type: "Document",
|
|
wallTime: 0
|
|
};
|
|
|
|
global.__inspector.requestWillBeSent(requestData);
|
|
}
|
|
|
|
function getTimeStamp(): number {
|
|
const d = new Date();
|
|
|
|
return Math.round(d.getTime() / 1000);
|
|
}
|
|
|
|
function mimeTypeToType(mimeType: string): string {
|
|
let type: string = "Document";
|
|
|
|
if (mimeType) {
|
|
if (mimeType.indexOf("image") === 0) {
|
|
type = "Image";
|
|
} else if (mimeType.indexOf("javascript") !== -1 || mimeType.indexOf("json") !== -1) {
|
|
type = "Script";
|
|
}
|
|
}
|
|
|
|
return type;
|
|
}
|
|
}
|