| | |
| | | * @param file 要保存到本地的文件对象 |
| | | * @param timeout 下载超时,单位是毫秒 |
| | | * @param headers 头标志例如{"a":"11"} |
| | | * @return 布尔型 true 代表成功 false代表失败 |
| | | * @return {boolean} true 代表成功 false代表失败 |
| | | */ |
| | | HttpWrapper.prototype.downloadFile = function (remoteUrl, file, timeout, headers) { |
| | | if (httpWrapper == null) { |
| | |
| | | * @param remoteUrl 远程文件URL |
| | | * @param file 要保存到本地的路径 |
| | | * @param headers 头标志例如{"a":"11"} |
| | | * @return 布尔型 true 代表成功 false代表失败 |
| | | * @return {boolean} true 代表成功 false代表失败 |
| | | */ |
| | | HttpWrapper.prototype.downloadFileDefault = function (remoteUrl, file, headers) { |
| | | if (httpWrapper == null) { |
| | |
| | | * @param url 请求的URL |
| | | * @param timeout 超时时间 单位毫秒 |
| | | * @param headers 头标志例如{"a":"11"} |
| | | * @return 字符串 请求后返回的字符串 |
| | | * @return {string} 请求后返回的字符串 |
| | | */ |
| | | HttpWrapper.prototype.httpGetDefault = function (url, timeout, headers) { |
| | | if (httpWrapper == null) { |
| | |
| | | * @param params 参数Map表 例如 {"a":"1"} 这样的参数或者字符串 |
| | | * @param timeout 超时时间 单位毫秒 |
| | | * @param headers 头标志例如{"a":"11"} |
| | | * @return 字符串 请求后返回的字符串 |
| | | * @return {null|string} 请求后返回的字符串 |
| | | */ |
| | | HttpWrapper.prototype.httpGet = function (url, params, timeout, headers) { |
| | | if (httpWrapper == null) { |
| | |
| | | * @param files 要上传的文件,例如 {"file1":"/sdcard/a.txt"} |
| | | * @param timeout 超时时间 单位毫秒 |
| | | * @param headers 头标志例如{"a":"11"} |
| | | * @return 字符串 请求后返回的字符串 |
| | | * @return {null|string} 请求后返回的字符串 |
| | | */ |
| | | HttpWrapper.prototype.httpPost = function (url, params, files, timeout, headers) { |
| | | if (httpWrapper == null) { |
| | |
| | | * @param files 要上传的文件,例如 {"file1":"/sdcard/a.txt"} |
| | | * @param timeout 超时时间 单位毫秒 |
| | | * @param headers 头标志例如{"a":"11"} |
| | | * @return 字符串 请求后返回的字符串 |
| | | * @return {null|string} 请求后返回的字符串 |
| | | */ |
| | | HttpWrapper.prototype.httpPostEx = function (url, params, files, timeout, headers) { |
| | | if (httpWrapper == null) { |
| | |
| | | * @param json json数据 |
| | | * @param timeout 超时时间 单位毫秒 |
| | | * @param headers 头标志例如{"a":"11"} |
| | | * @return 字符串 请求后返回的字符串 |
| | | * @return {null|string} 请求后返回的字符串 |
| | | */ |
| | | HttpWrapper.prototype.postJSON = function (url, json, timeout, headers) { |
| | | if (httpWrapper == null) { |
| | |
| | | * ]<Br/> |
| | | * 其中contentType可有可无 |
| | | * responseCharset: 字符串,强制设置响应内容的编码集 |
| | | * @return Response 对象或者null |
| | | * @return {null|Response1} 对象或者null |
| | | */ |
| | | HttpWrapper.prototype.request = function (param) { |
| | | if (httpWrapper == null || param == null) { |
| | |
| | | if (x == null || x == "") { |
| | | return null; |
| | | } |
| | | return new Response(JSON.parse(x)); |
| | | return new Response1(JSON.parse(x)); |
| | | }; |
| | | |
| | | /** |
| | | * |
| | | * @param param |
| | | * @return {null|Response1} |
| | | */ |
| | | HttpWrapper.prototype.requestEx = function (param) { |
| | | if (httpWrapper == null || param == null) { |
| | | return null; |
| | |
| | | if (x == null || x == "") { |
| | | return null; |
| | | } |
| | | return new Response(JSON.parse(x)); |
| | | return new Response1(JSON.parse(x)); |
| | | }; |
| | | |
| | | function Response(data) { |
| | | function Response1(data) { |
| | | this.cookie = {}; |
| | | this.header = {}; |
| | | this.charset = ""; |
| | |
| | | * @param url 要连接的地址 |
| | | * @param header 参数头 |
| | | * @param type 类库类型,1 okhttp 2 javawebsocket |
| | | * @return {@link WebSocket } WebSocket对象 |
| | | * @return {WebSocket1} WebSocket1 对象 |
| | | */ |
| | | HttpWrapper.prototype.newWebsocket = function (url, header, type) { |
| | | var p = null; |
| | |
| | | p = JSON.stringify(header); |
| | | } |
| | | var ws = httpWrapper.websocket(url, p, type); |
| | | return new WebSocket(ws); |
| | | return new WebSocket1(ws); |
| | | }; |
| | | |
| | | |
| | | function WebSocket(ws) { |
| | | function WebSocket1(ws) { |
| | | this.websocketClient = ws; |
| | | } |
| | | |
| | |
| | | * @param period 心跳周期 时间是毫秒 |
| | | * @param cancelOld 是否取消老的,true 或者false |
| | | */ |
| | | WebSocket.prototype.startHeartBeat = function (heartDataBinCallback, heartDataStrCallback, period, cancelOld) { |
| | | WebSocket1.prototype.startHeartBeat = function (heartDataBinCallback, heartDataStrCallback, period, cancelOld) { |
| | | if (this.websocketClient != null) { |
| | | this.websocketClient.startHeartBeat(heartDataBinCallback, heartDataStrCallback, period, cancelOld); |
| | | } |
| | |
| | | /** |
| | | * 停止心跳函数 |
| | | */ |
| | | WebSocket.prototype.stopHeartBeat = function () { |
| | | WebSocket1.prototype.stopHeartBeat = function () { |
| | | if (this.websocketClient != null) { |
| | | this.websocketClient.stopHeartBeat(); |
| | | } |
| | |
| | | /** |
| | | * 开始异步连接 |
| | | * @param timeout 链接超时时间 |
| | | * @return {bool} true 代表成功 false代表失败 |
| | | * @return {boolean} true 代表成功 false代表失败 |
| | | */ |
| | | WebSocket.prototype.connect = function (timeout) { |
| | | WebSocket1.prototype.connect = function (timeout) { |
| | | if (this.websocketClient != null) { |
| | | return this.websocketClient.connect(timeout); |
| | | } |
| | |
| | | /** |
| | | * EC 6.17.0+ [已过期] |
| | | * 重置连接 |
| | | * @return {bool} true 代表成功 false代表失败 |
| | | * @return {boolean} true 代表成功 false代表失败 |
| | | */ |
| | | WebSocket.prototype.reset = function () { |
| | | WebSocket1.prototype.reset = function () { |
| | | if (this.websocketClient != null) { |
| | | return this.websocketClient.reset(); |
| | | } |
| | |
| | | /** |
| | | * EC 6.17.0+ [已过期] |
| | | * 开始同步重新链接 |
| | | * @return {bool} true 代表链接成功 false代表失败 |
| | | * @return {boolean} true 代表链接成功 false代表失败 |
| | | */ |
| | | WebSocket.prototype.reconnectBlocking = function () { |
| | | WebSocket1.prototype.reconnectBlocking = function () { |
| | | if (this.websocketClient != null) { |
| | | return this.websocketClient.reconnectBlocking(); |
| | | } |
| | |
| | | * EC 6.17.0+ [已过期] |
| | | * 开始同步链接 |
| | | * @param timeout 链接超时时间 单位是毫秒 |
| | | * @return {bool} true 代表链接成功 false代表失败 |
| | | * @return {boolean} true 代表链接成功 false代表失败 |
| | | */ |
| | | WebSocket.prototype.connectBlocking = function (timeout) { |
| | | WebSocket1.prototype.connectBlocking = function (timeout) { |
| | | if (this.websocketClient != null) { |
| | | return this.websocketClient.connectBlocking(timeout); |
| | | } |
| | |
| | | |
| | | /** |
| | | * 是否已经关闭 |
| | | * @return true 代表已经关闭,false 未关闭 |
| | | * @return {boolean} true 代表已经关闭,false 未关闭 |
| | | */ |
| | | WebSocket.prototype.isClosed = function () { |
| | | WebSocket1.prototype.isClosed = function () { |
| | | if (this.websocketClient != null) { |
| | | return this.websocketClient.isClosed(); |
| | | } |
| | |
| | | |
| | | /** |
| | | * 是否已经连接了 |
| | | * @return true 代表已经连接,false 未连接 |
| | | * @return {boolean} true 代表已经连接,false 未连接 |
| | | */ |
| | | WebSocket.prototype.isConnected = function () { |
| | | WebSocket1.prototype.isConnected = function () { |
| | | if (this.websocketClient != null) { |
| | | return this.websocketClient.isConnected(); |
| | | } |
| | |
| | | /** |
| | | * 关闭链接 |
| | | */ |
| | | WebSocket.prototype.close = function () { |
| | | WebSocket1.prototype.close = function () { |
| | | this.websocketClient.close(); |
| | | }; |
| | | |
| | | /** |
| | | * 适用EC 6.17.0+ |
| | | * 设置自动重连 |
| | | * @param v true 代表自动重连 |
| | | * @param {boolean} true 代表自动重连 |
| | | */ |
| | | WebSocket.prototype.setAutoReconnect = function (v) { |
| | | WebSocket1.prototype.setAutoReconnect = function (v) { |
| | | this.websocketClient.setAutoReconnect(v); |
| | | }; |
| | | /** |
| | |
| | | * 设置丢失链接超时时间 |
| | | * @param timeout 单位是秒 |
| | | */ |
| | | WebSocket.prototype.setConnectionLostTimeout = function (timeout) { |
| | | WebSocket1.prototype.setConnectionLostTimeout = function (timeout) { |
| | | this.websocketClient.setConnectionLostTimeout(timeout); |
| | | }; |
| | | |
| | |
| | | * 设置数据读取超时时间 |
| | | * @param timeout 单位是秒 |
| | | */ |
| | | WebSocket.prototype.setReadTimeout = function (timeout) { |
| | | WebSocket1.prototype.setReadTimeout = function (timeout) { |
| | | this.websocketClient.setReadTimeout(timeout); |
| | | }; |
| | | |
| | |
| | | * 设置数据写入超时时间 |
| | | * @param timeout 单位是秒 |
| | | */ |
| | | WebSocket.prototype.setWriteTimeout = function (timeout) { |
| | | WebSocket1.prototype.setWriteTimeout = function (timeout) { |
| | | this.websocketClient.setWriteTimeout(timeout); |
| | | }; |
| | | |
| | |
| | | * 设置心跳超时时间 |
| | | * @param timeout 单位是秒 |
| | | */ |
| | | WebSocket.prototype.setPingInterval = function (timeout) { |
| | | WebSocket1.prototype.setPingInterval = function (timeout) { |
| | | this.websocketClient.setPingInterval(timeout); |
| | | }; |
| | | |
| | |
| | | * 设置调用超时时间 |
| | | * @param timeout 单位是秒 |
| | | */ |
| | | WebSocket.prototype.setCallTimeout = function (timeout) { |
| | | WebSocket1.prototype.setCallTimeout = function (timeout) { |
| | | this.websocketClient.setCallTimeout(timeout); |
| | | }; |
| | | |
| | |
| | | /** |
| | | * 发送文本消息 |
| | | * @param text 文本信息 |
| | | * @return true 代表成功,false 失败 |
| | | * @return {boolean} true 代表成功,false 失败 |
| | | */ |
| | | WebSocket.prototype.sendText = function (text) { |
| | | WebSocket1.prototype.sendText = function (text) { |
| | | return this.websocketClient.sendText(text); |
| | | }; |
| | | /** |
| | | * 发送字节信息 |
| | | * @param bin |
| | | * @return true 代表成功,false 失败 |
| | | * @return {boolean} true 代表成功,false 失败 |
| | | */ |
| | | WebSocket.prototype.sendBinary = function (bin) { |
| | | WebSocket1.prototype.sendBinary = function (bin) { |
| | | return this.websocketClient.sendBinary(bin); |
| | | }; |
| | | |
| | |
| | | * 当连接打开的时候事件回调 |
| | | * @param callback 回调函数 |
| | | */ |
| | | WebSocket.prototype.onOpen = function (callback) { |
| | | WebSocket1.prototype.onOpen = function (callback) { |
| | | this.websocketClient.setCallbackOnOpen(callback); |
| | | }; |
| | | /** |
| | | * 当有文本信息发送过来的时候回调 |
| | | * @param callback 回调函数 |
| | | */ |
| | | WebSocket.prototype.onText = function (callback) { |
| | | WebSocket1.prototype.onText = function (callback) { |
| | | this.websocketClient.setCallbackOnText(callback); |
| | | }; |
| | | /** |
| | | * 当关闭的时候回调 |
| | | * @param callback 回调函数 |
| | | */ |
| | | WebSocket.prototype.onClose = function (callback) { |
| | | WebSocket1.prototype.onClose = function (callback) { |
| | | this.websocketClient.setCallbackOnClose(callback); |
| | | }; |
| | | /** |
| | | * 当发生错误的时候回调 |
| | | * @param callback 回调函数 |
| | | */ |
| | | WebSocket.prototype.onError = function (callback) { |
| | | WebSocket1.prototype.onError = function (callback) { |
| | | this.websocketClient.setCallbackOnError(callback); |
| | | }; |
| | | /** |
| | | * 当有二进制数据过来的时候回调 |
| | | * @param callback 回调函数 |
| | | */ |
| | | WebSocket.prototype.onBinary = function (callback) { |
| | | WebSocket1.prototype.onBinary = function (callback) { |
| | | this.websocketClient.setCallbackOnBinary(callback); |
| | | }; |
| | | |