tcp代理服务
This commit is contained in:
		
							parent
							
								
									f61665a59f
								
							
						
					
					
						commit
						69f22de4ff
					
				| @ -2,7 +2,7 @@ import IdlServiceExtStub from './idl_service_ext_stub'; | ||||
| import hilog from '@ohos.hilog'; | ||||
| import type { insertDataToMapCallback } from './i_idl_service_ext'; | ||||
| import type { processDataCallback } from './i_idl_service_ext'; | ||||
| import request from '../common/utils/request'; | ||||
| import request, { tcpRequest } from '../common/utils/request'; | ||||
| import pasteboard from '@ohos.pasteboard'; | ||||
| 
 | ||||
| const ERR_OK = 0; | ||||
| @ -18,7 +18,7 @@ export default class ServiceExtImpl extends IdlServiceExtStub { | ||||
|     pasteboard.getSystemPasteboard().getData().then((res) => { | ||||
|       let pasteData = res.getPrimaryText() | ||||
|       console.log("lixiao receive paste", pasteData) | ||||
|       request(JSON.parse(pasteData)).then(response => { | ||||
|       tcpRequest(JSON.parse(pasteData)).then(response => { | ||||
|         console.log("lixiao success", JSON.stringify(response)) | ||||
|         callback(0, JSON.stringify({ | ||||
|           code: 0, | ||||
|  | ||||
| @ -2,7 +2,8 @@ import ServiceExtension from '@ohos.app.ability.ServiceExtensionAbility' | ||||
| 
 | ||||
| // import { ServiceExtensionAbility, Want } from '@kit.AbilityKit'; | ||||
| // import { rpc } from '@kit.IPCKit'; | ||||
| import  hilog  from '@ohos.hilog'; | ||||
| import hilog from '@ohos.hilog'; | ||||
| import { tcpUtil } from '../common/utils/TcpRequest'; | ||||
| import ServiceExtImpl from '../IdlServiceExt/idl_service_ext_impl'; | ||||
| 
 | ||||
| const TAG: string = '[ServiceExtAbility]'; | ||||
| @ -11,8 +12,9 @@ const DOMAIN_NUMBER: number = 0xFF00; | ||||
| export default class ServiceExtAbility extends ServiceExtension { | ||||
|   serviceExtImpl: ServiceExtImpl = new ServiceExtImpl('ExtImpl', this.context); | ||||
| 
 | ||||
|   onCreate(want): void { | ||||
|     // let serviceExtensionContext = this.context; | ||||
|   async onCreate(want): Promise<void> { | ||||
|     // tcp创建连接 | ||||
|     await tcpUtil.init() | ||||
|     hilog.info(DOMAIN_NUMBER, TAG, `js-test ServiceExtensionAbility-- onCreate, want: ${want.abilityName}`); | ||||
|   }; | ||||
| 
 | ||||
|  | ||||
| @ -181,7 +181,8 @@ class TcpUtils { | ||||
|       await this.socket.send({ data: "#$" }) | ||||
|       console.log(tag, 'send success') | ||||
|     } catch (err) { | ||||
|       console.log("tcp request send failed", this.requestMap.get(key).url) | ||||
|       console.log("tcp request send failed url:", this.requestMap.get(key).url) | ||||
|       console.log("tcp request send failed error:", JSON.stringify(err)) | ||||
|       this.requestMap.get(key).reject({ | ||||
|         message: "tcp request send failed", | ||||
|         code: 2300007 | ||||
|  | ||||
| @ -5,7 +5,7 @@ import { tcpUtil } from './TcpRequest'; | ||||
| import Prompt from '@system.prompt'; | ||||
| import tempRequest from './tempRequest'; | ||||
| 
 | ||||
| function tcpRequest<T>(req: any): Promise<T> { | ||||
| export function tcpRequest<T>(req: any): Promise<T> { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     let {url,params = {},data = {},xml,method = 'get',host,isNewCenter = false, timeout} = req; | ||||
|     try { | ||||
|  | ||||
| @ -77,7 +77,8 @@ export default class EntryAbility extends UIAbility { | ||||
|     // this.requestPermission(this.context) | ||||
|     // this.featureAbilityAuth() | ||||
|     TempLogger.init() | ||||
|     await tcpUtil.init() | ||||
|     // tcp创建连接 | ||||
|     // await tcpUtil.init() | ||||
| 
 | ||||
|     const windowClass = await windowStage.getMainWindow(); | ||||
|     globalThis.windowClass = windowClass | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user