mirror of
https://gitee.com/eolink_admin/postcat.git
synced 2024-12-02 03:38:03 +08:00
Merge branch 'main' of github.com:eolinker/eoapi
This commit is contained in:
commit
ddd60e1f8d
@ -229,7 +229,7 @@ export class WebsocketComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
this.model.response.responseBody.unshift({ type: 'get', msg: content, isExpand: false });
|
||||
} else {
|
||||
this.model.response.responseBody.unshift({ type: 'end', msg: 'Disconnect by Server', isExpand: false });
|
||||
this.model.response.responseBody.unshift({ type: 'end', msg: `Disconnect by ${this.getLink()}` , isExpand: false });
|
||||
this.wsStatus = 'disconnect';
|
||||
this.switchEditStatus();
|
||||
this.unListen();
|
||||
|
@ -1,5 +1,8 @@
|
||||
const IO = require('socket.io');
|
||||
const WebSocket = require('ws');
|
||||
process.on('uncaughtException', err => {
|
||||
console.error('uncaughtException', err)
|
||||
})
|
||||
|
||||
const socket = (port = 4301) => {
|
||||
const io = new IO.Server(port);
|
||||
@ -7,7 +10,6 @@ const socket = (port = 4301) => {
|
||||
// send a message to the client
|
||||
socket.emit('ws-client', 'link success');
|
||||
let ws = null;
|
||||
|
||||
// receive a message from the client
|
||||
socket.on('ws-server', ({ type, content }) => {
|
||||
if (type === 'connect') {
|
||||
@ -44,7 +46,6 @@ const socket = (port = 4301) => {
|
||||
}
|
||||
|
||||
const reqHeader = ws._req.getHeaders();
|
||||
// console.log(ws);
|
||||
|
||||
// 打开WebSocket连接后立刻发送一条消息:
|
||||
ws.on('open', () => {
|
||||
@ -59,7 +60,7 @@ const socket = (port = 4301) => {
|
||||
socket.emit('ws-client', {
|
||||
type: 'ws-message-back',
|
||||
status: 0,
|
||||
content: message instanceof ArrayBuffer ? new TextDecoder().decode(message) : message,
|
||||
content:message?.toString()
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user