Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support XmlHttpRequest via protocol message #43

Closed
mpost opened this issue Aug 14, 2014 · 2 comments
Closed

Support XmlHttpRequest via protocol message #43

mpost opened this issue Aug 14, 2014 · 2 comments

Comments

@mpost
Copy link
Member

mpost commented Aug 14, 2014

A first draft of an abstraction for the protocol has been created:

the tabris.HttpRequest object is only used once and recycled after use. The tabris.js code will create a new object for each request. The snippet below reflects the latest comments added below.

We currently do NOT support the upload scenario but sketched the protocol messages for future consistency.

create {
    type: "tabris.HttpRequest"
}
    
call {
    method: "send"
    property: {
        method: string // "GET"
        url: string // "url.com/file.txt"
        headers: {string, string}
        data: string // request body data
        timeout: number // connection timeout in ms
        ...
    }
}

call {
    method: "abort"
}

listen {
    StateChange: boolean
}

notify "StateChange" {
    state: "uploading" | "uploadend" | "headers" | "loading" | "finished" | "aborted" | "error" | "timeout"
    code: number // http status code, send in "headers"
    message: string // http status message, send in "headers"
    headers: {string, string} // send in "headers"
    response: string // send in "finished"
}

listen {
    DownloadProgress: boolean
}

notify "DownloadProgress" {
    loaded: number,
    total: number,
    lengthComputable: boolean
}

listen {
    UploadProgress: boolean
}

notify "UploadProgress" {
    loaded: number,
    total: number,
    lengthComputable: boolean
}
@tbuschto
Copy link
Member

My proposal:

notify "StateChange" {
    state: "headers" | "loading" | "finished" | "aborted" | "error" | "timeout"
    code: HTTP STATUS CODE,
    response: string
}
notify "Progress" {
    loaded: long,
    total: long
}

"StateChenge" covers XHR "load", "loadend", "abort", "error", "timeout" and state change 2-4
"Progress" covers "progress". Progress events are fired only while the state is "loading"
"loadstart" and state change 1 (OPENED) can be handled completely in JS (fired after a few pre-checks in the send/open methods, before delegating to the bridge.)

Perhaps "headers" and "loading" can be merged, I'm not sure if there is a state between having the headers but not yet a a single byte of the respose text.

@ralfstx
Copy link
Member

ralfstx commented Oct 14, 2014

Implemented in 49e55b4

@ralfstx ralfstx closed this as completed Oct 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants