12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import * as signalr from 'signalr-for-wx'
- import { RequestOption, ResponseOptions } from 'signalr-for-wx'
- console.log('in socket', signalr)
- const socket = new signalr.HubConnectionBuilder()
- .configureLogging(1)
- .withUrl('https://www.ado5.com', {
- skipNegotiation: true,
- transport: signalr.HttpTransportType.WebSockets,
- })
- .build()
- socket.onclose((err) => {
- err && console.log(err)
- wx.showModal({
- title: 'Socket 已断开',
- content: JSON.stringify(err),
- })
- })
- socket.start()
- // const request = new signalr.Request({
- // baseUrl: `http://www.baidu.com`,
- // timeout: 60 * 1000,
- // headers: { 'content-type': 'application/json' },
- // transformRequest: [
- // // 支持 async/await
- // async (options: RequestOption) => {
- // // options.url = `new url`
- // // TODO ...
- // },
- // ],
- // transformResponse: [
- // // 支持 async/await
- // async (response: ResponseOptions) => {
- // // TODO 处理 response
- // // 如果 return Promise.reject() 或 抛出异常,则停止后续 响应处理
- // },
- // ],
- // responseType: signalr.ResponseType.JSON,
- // method: signalr.RequestMethod.GET,
- // })
- // request.get('/').then((rsp) => {
- // console.log(rsp.data)
- // })
- console.log(socket, '<- socket init')
- export default socket
|