Skip to content

Commit

Permalink
fix: add attachSocket()
Browse files Browse the repository at this point in the history
  • Loading branch information
asdocoder committed Jun 25, 2024
1 parent 383f8fe commit 5bab43c
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/core/Ros.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* @author Brandon Alexander - baalexander@gmail.com
*/

import socketAdapter from './SocketAdapter.js';
import { EventEmitter } from 'eventemitter3';

import Topic from './Topic.js';
import Service from './Service.js';
import Param from './Param.js';
import TFClient from '../tf/TFClient.js';
import ActionClient from '../actionlib/ActionClient.js';
import SimpleActionServer from '../actionlib/SimpleActionServer.js';
import { EventEmitter } from 'eventemitter3';
import TFClient from '../tf/TFClient.js';
import Param from './Param.js';
import Service from './Service.js';
import socketAdapter from './SocketAdapter.js';
import Topic from './Topic.js';

/**
* Manages connection to the server and all interactions with ROS.
Expand Down Expand Up @@ -80,6 +80,19 @@ export default class Ros extends EventEmitter {
throw 'Unknown transportLibrary: ' + this.transportLibrary.toString();
}
}
/**
* Connects to an existing socket
*
* @param {WebSocket} socket
*/
attachSocket(socket) {
if (this.transportLibrary.constructor.name === 'websocket') {
socket.binaryType = 'arraybuffer';
this.socket = Object.assign(socket, socketAdapter(this));
} else {
throw 'attachSocket only supported for websocket transportLibrary';
}
}
/**
* Disconnect from the WebSocket server.
*/
Expand Down

0 comments on commit 5bab43c

Please sign in to comment.