Comments (1)
const io = require('socket.io-client');
const { dialog } = require('electron');
const { clipboard } = require('electron');
let MAIN_WINDOW = null;
let CONNECTED = false;
export let setMainWindow = (w) => MAIN_WINDOW = w;
export let connect = function() {
if (CONNECTED) {
return dialog.showMessageBox({
message: `已经发起远程链接`,
detail: `请不要重复发起~`,
type: 'error',
})
}
const deb = MAIN_WINDOW.webContents.debugger;
deb.attach('1.1');
CONNECTED = true;
const connection = io('wss://ecsi.taobao.com', {
transports: ['websocket'],
reconnection: false,
});
connection.on('connect_error', function (e) {
console.log(e);
})
connection.on('connect', function () {
deb.on('message', function (event, method, params) {
connection.emit('data.event', {
method, params
})
})
connection.on('sessionCreated', (id) => {
dialog.showMessageBox({
message: `远程连接成功`,
detail: `请将以下 ID 给到与您联系的小二 \r\n${id}`,
type: 'info',
buttons: ['复制远程ID'],
defaultId: 0, // bound to buttons array
}, () => {
clipboard.writeText(`${id}`, 'clipboard');
})
})
connection.on('data.request', function (data) {
if (data.method === 'Page.canScreencast') {
var reply = {
id: data.id,
result: {
result: true,
},
};
connection.emit('data.response', reply);
return;
}
deb.sendCommand(data.method, data.params)
.then(res => {
var reply = {
id: data.id,
result: res,
};
connection.emit('data.response', reply);
})
.catch(res => {
console.error(data.method, res);
})
});
connection.emit('hello', {});
})
}
from aaronphy.github.io.
Related Issues (20)
- 计算机网络复习-HTTPS
- DOM自省
- 一些调试
- 千岛湖游记
- TS技巧集合
- 手撕代码
- 4月份阅读
- 前端性能指标
- 5月份阅读
- ByteDance Interview HOT 1
- vscode 配置遇到的问题
- 30w-40w车推荐
- 一些命令解决一些问题
- interview pre HOT 5
- useful code HOT 5
- 算法4课程
- ReactNative ENV Records HOT 9
- FFMPEG COMMANDS HOT 1
- Python shell HOT 1
- 装修拉齐
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aaronphy.github.io.