Coder Social home page Coder Social logo

ws_electron about aaronphy.github.io HOT 1 CLOSED

aaronphy avatar aaronphy commented on May 22, 2024
ws_electron

from aaronphy.github.io.

Comments (1)

Aaronphy avatar Aaronphy commented on May 22, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.