socket拼接url时, 增加demo注释说明
This commit is contained in:
parent
a9064f4201
commit
4a94414696
|
|
@ -71,7 +71,14 @@ export class SubScriber<ED extends EntityDict & BaseEntityDict> extends Feature
|
|||
|
||||
const url = this.url!;
|
||||
const path = this.path!;
|
||||
|
||||
|
||||
// import { io } from "socket.io-client";
|
||||
// const socket = io('https://example.com/order', {
|
||||
// path: '/my-custom-path/',
|
||||
// });
|
||||
// the Socket instance is attached to the "order" Namespace
|
||||
// the HTTP requests will look like: GET https://example.com/my-custom-path/?EIO=4&transport=polling&t=ML4jUwU
|
||||
// 文档 https://socket.io/docs/v4/client-options/
|
||||
this.socket = io(url, {
|
||||
path,
|
||||
});
|
||||
|
|
@ -95,13 +102,16 @@ export class SubScriber<ED extends EntityDict & BaseEntityDict> extends Feature
|
|||
}
|
||||
});
|
||||
|
||||
socket.on('data', (opRecords: OpRecord<ED>[], event: string) => {
|
||||
const callback = this.eventMap[event];
|
||||
if (callback) {
|
||||
callback(event, opRecords);
|
||||
socket.on(
|
||||
'data',
|
||||
(opRecords: OpRecord<ED>[], event: string) => {
|
||||
const callback = this.eventMap[event];
|
||||
if (callback) {
|
||||
callback(event, opRecords);
|
||||
}
|
||||
this.cache.sync(opRecords);
|
||||
}
|
||||
this.cache.sync(opRecords);
|
||||
});
|
||||
);
|
||||
|
||||
socket.on('error', (errString: string) => {
|
||||
console.error(errString);
|
||||
|
|
@ -110,13 +120,12 @@ export class SubScriber<ED extends EntityDict & BaseEntityDict> extends Feature
|
|||
title: '服务器subscriber抛出异常',
|
||||
content: errString,
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
if (Object.keys(this.eventMap).length > 0) {
|
||||
socket.emit('sub', Object.keys(this.eventMap));
|
||||
resolve(undefined);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
resolve(undefined);
|
||||
socket.disconnect();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue