npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clobot-socket-manager

v1.0.13

Published

> Clobot Socket Manager (TM websocket handler) > <br/> > <br/>

Downloads

44

Readme

ClobotRosManager

Clobot Socket Manager (TM websocket handler)

목차

Getting Started

Installation

npm install clobot-socket-manager

or

yarn add clobot-socket-manager

Syntax

import ClobotSocketManager, {
  ClobotSocketOption,
  SocketUrlVO,
} from "clobot-ros-manager";

const options: ClobotSocketOption = {
  url,
  maxRetries: 0,
  publisher: "APP",
};

const serviceUrl = {
  ROBOT_CMD: "/clobot_msgs/robot/robot_cmd",
  CHANGE_REQUEST: "/clobot_msgs/page/change_request",
  CONFIG_SAVE: "/clobot_msgs/robot/config_save",
  LOAD_PAGE: "/clobot_msgs/page/load_page",
};

const topicUrl = {
  ROBOT_STATUS: "/clobot_msgs/robot/robot_status",
  ALERT_MESSAGE: "/clobot_msgs/robot/alert_message",
  LOADING_PROGRESS: "/clobot_msgs/robot/loading_progress",
  EMERGENCY: "/clobot_msgs/robot/emergency",
};

this.socketUrl = new SocketUrlVO(serviceUrl, topicUrl);
this.socketManager = new ClobotSocketManager(options, this.socketUrl);
  • options (optional)

    • Type: Object
    • Check out the available options.
  • socketUrl (optional)

    • Type: SocketUrlVO
    • Check out the available socketUrl.

Example

Methods Event

import ClobotSocketManager, {
  ClobotSocketOption,
  SocketStatus,
  ClobotSocketMessage,
  SocketUrlVO,
} from "clobot-socket-manager";


const serviceUrl = {
  ROBOT_CMD: "/clobot_msgs/robot/robot_cmd",
  CHANGE_REQUEST: "/clobot_msgs/page/change_request",
  CONFIG_SAVE: "/clobot_msgs/robot/config_save",
  LOAD_PAGE: "/clobot_msgs/page/load_page",
};

const topicUrl = {
  ROBOT_STATUS: "/clobot_msgs/robot/robot_status",
  ALERT_MESSAGE: "/clobot_msgs/robot/alert_message",
  LOADING_PROGRESS: "/clobot_msgs/robot/loading_progress",
  EMERGENCY: "/clobot_msgs/robot/emergency",
};
export default class SocketManager {
  public socketManager: ClobotSocketManager;
  private socketUrl: SocketUrlVO;

  constructor(url: string) {
    const options: ClobotSocketOption = {
      url,
      maxRetries: 0,
      publisher: "APP",
    };


    this.socketUrl = new SocketUrlVO(serviceUrl, topicUrl);

    this.socketManager = new ClobotSocketManager(options, this.socketUrl);
    // Socket Service handler
    const { CHANGE_REQUEST, ROBOT_CMD } = this.socketUrl.service;
    this.socketManager.event.on(CHANGE_REQUEST, this.handleChanageRequest);
    this.socketManager.event.on(ROBOT_CMD, this.handleRobotCmd);

    // Socket Topic handler
    const { ALERT_MESSAGE, ROBOT_STATUS } = this.socketUrl.topic;
    this.socketManager.event.on(ALERT_MESSAGE, this.handleAlertMessage);
    this.socketManager.event.on(ROBOT_STATUS, this.handleRobotStatus);

    // Socket status handler
    this.socketManager.event.on("socket", this.handleSocket);
    this.socketManager.event.on("error", this.handleError);
  }

  private handleSocket = (state: SocketStatus) => {
    switch (state) {
      case "onSuccess":
        console.log("# onSuccess");
        break;
      case "onDisconnect":
        console.log("# onDisconnect");
        break;
      case "onClose":
        console.log("# onClose");
        break;
      case "onFail":
        console.log("# onFail");
        break;
      case "onTimeOut":
        console.log("# onTimeOut");
        break;
      case "onConnecting":
        console.log("# on connecting");
        break;
    }
  };

  private handleChanageRequest = (data: ClobotSocketMessage) => {
    console.log("handle change request", data);
  };

  private handleRobotCmd = (data: ClobotSocketMessage) => {
    console.log("handle robot cmd", data);
  };

  private handleAlertMessage = (data: ClobotSocketMessage) => {
    console.log("handle robot cmd", data);
  };

  private handleRobotStatus = (data: ClobotSocketMessage) => {
    console.log("handle robot  status", data);
  };

  private handleError = (error: any) => {
    console.log("ERROR", error);
  };
}

⬆ back to top

Options

- url

TM Socket에 연동할 URL 정보

  • Type: String
  • Default: false

- maxRetries

Socket 연동 실패할 경우 다시 연동 시도 할 카운터 수 - "0"의 경우 붙을 때까지 연동 시도

  • Type: Number
  • Default: false

- publisher

Socket event 발송 주체 TM의 경우 publisher : 'TM' 고정 Front의 경우 상황에 따라 'UI' or 'APP' 사용

  • Type: 'UI' or 'APP'
  • Default: false

socketUrl

- Service

  • CHANGE_REQUEST: "< Enter your project's 'CHANGE_REQUEST' URL >"
  • CONFIG_SAVE: "< Enter your project's 'CONFIG_SAVE' URL >"
  • LOAD_PAGE: "< Enter your project's 'LOAD_PAGE' URL >"
  • ROBOT_CMD: "< Enter your project's 'ROBOT_CMD' URL >"

- Topic

  • ROBOT_STATUS: "< Enter your project's 'ROBOT_STATUS' URL >"
  • ALERT_MESSAGE: "< Enter your project's 'ALERT_MESSAGE' URL >"
  • LOADING_PROGRESS: "< Enter your project's 'LOADING_PROGRESS' URL >"
  • EMERGENCY: "< Enter your project's 'EMERGENCY' URL >"

⬆ back to top

Methods

UI or APP -> TM

changeRequest(data : any, timeout : number)

  • type : service
  • name : Service.CHANGE_REQUEST ( enum )
  • path : /clobot_msgs/page/change_request ( path )
socketManager.changeRequest(
  {
    page_id: "page_id",
    comp_id: "comp_id",
    content: {},
  },
  10000 // timeout - default 10s
);

robotCmd(data :any, timeout :number)

  • type : service
  • name : Service.ROBOT_CMD ( enum )
  • path : /clobot_msgs/robot/robot_cmd ( path )
socketManager.robotCmd(
  {
    page_id: "page_id",
    comp_id: "comp_id",
    content: {},
  },
  10000 // timeout - default 10s
);

⬆ back to top

Event

TM -> UI or APP

Socket Event

SocketStatus

- onDisconnect : 연결이 존재하다가 끊어졌을 떄 상태
- onClose : 연결이 종료되었을 떄 상태
- onFail : 연결 실패 상태
- onSuccess : 연결 성공 상태
- onConnecting : 연결 시도중 상태
- onTimeOut : 요청중 타임아웃 되었을 때 상태
import ClobotSocketManager, { SocketStatus } from "clobot-clobot-manager";
socketManager.event.on("socket", (status: SocketStatus) => {});

Service Event

Service

* 현재 정의되어 있는 Service Keys

- ROBOT_CMD,
- CHANGE_REQUEST,
- LOADING_PROGRESS,
- EMERGENCY,

Topic Event

Topic

* 현재 정의되어 있는 Topic Keys

- ROBOT_STATUS,
- ALERT_MESSAGE,
- CONFIG_SAVE,
- LOAD_PAGE,