Skip to content

Commit

Permalink
feat: expose SERVICE in instrument as INSTRUMENT_CHANNEL (#89)
Browse files Browse the repository at this point in the history
* feat: expose SERVICE in instrument

* fix typo

* rename
  • Loading branch information
KazuCocoa authored Apr 14, 2022
1 parent 7ec52f8 commit 40983e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { default as Usbmux } from './lib/usbmux';
import * as utilities from './lib/utilities';
import * as services from './lib/services';
import { INSTRUMENT_CHANNEL } from './lib/instrument';


export { Usbmux, utilities, services };
export { Usbmux, utilities, services, INSTRUMENT_CHANNEL };
export default Usbmux;
12 changes: 6 additions & 6 deletions lib/instrument/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const CHANNEL_OFFSET = 2 ** 32;
const INSTRUMENT_SERVICE_NAME_VERSION_14 = 'com.apple.instruments.remoteserver.DVTSecureSocketProxy';
const INSTRUMENT_SERVICE_NAME = 'com.apple.instruments.remoteserver';

export const SERVICE = Object.freeze({
export const INSTRUMENT_CHANNEL = Object.freeze({
DEVICE_INFO: 'com.apple.instruments.server.services.deviceinfo',
PROCESS_CONTROL: 'com.apple.instruments.server.services.processcontrol',
SYSMONTAP: 'com.apple.instruments.server.services.sysmontap',
Expand Down Expand Up @@ -84,9 +84,9 @@ class InstrumentService extends BaseServiceSocket {
}

/**
* If the event is registered, this channel {SERVICE} messages will be returned to event. refer to this._handleData
* If the event is registered, this channel {CHANNEL} messages will be returned to event. refer to this._handleData
* It's actually listening for int channelCode. In this._channel object to record channel key and int value
* @param {string} channel instruments service channel e.g: SERVICE.DEVICE_INFO.
* @param {string} channel instruments service channel e.g: INSTRUMENT_CHANNEL.DEVICE_INFO.
* @param {DTXCallback} event
*/
async registerChannelCallback (channel, event) {
Expand All @@ -96,7 +96,7 @@ class InstrumentService extends BaseServiceSocket {

/**
* Create a service channel, data transmission of the service will use this channelCode
* @param {string} channel instruments service channel e.g: SERVICE.DEVICE_INFO
* @param {string} channel instruments service channel e.g: INSTRUMENT_CHANNEL.DEVICE_INFO
* @returns {Promise<number|*>} instruments service channel code for data transmission
*/
async makeChannel (channel) {
Expand All @@ -111,12 +111,12 @@ class InstrumentService extends BaseServiceSocket {

/**
* In general, we call this method to start the instrument dtx service
* @param {string} channel instrument dtx service e.g: SERVICE.DEVICE_INFO
* @param {string} channel instrument dtx service e.g: INSTRUMENT_CHANNEL.DEVICE_INFO
* @param {string} selector instrument service method name (reflection calls)
* @param {...any} auxiliaries parameters required by selector
* @returns {Promise<DTXMessage>}
* example:
* instrumentService.callChannel(SERVICE.PROCESS_CONTROL,
* instrumentService.callChannel(INSTRUMENT_CHANNEL.PROCESS_CONTROL,
'launchSuspendedProcessWithDevicePath:bundleIdentifier:environment:arguments:options:', '',
bundleID, {}, [], {'StartSuspendedKey': 0, 'KillExisting': 1}
*/
Expand Down
8 changes: 4 additions & 4 deletions test/instrument/instrument-service-specs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chai from 'chai';
import {InstrumentService, SERVICE} from '../../lib/instrument';
import {InstrumentService, INSTRUMENT_CHANNEL} from '../../lib/instrument';
import { getServerWithFixtures, fixtures } from '../fixtures';
import B from 'bluebird';

Expand All @@ -25,7 +25,7 @@ describe('instrument', function () {
({server, socket} = await getServerWithFixtures(fixtures.INSTRUMENTS_LAUNCH_APP));
const bundleID = 'com.apple.mobilesafari';
instrumentService = new InstrumentService(socket);
const data = await instrumentService.callChannel(SERVICE.PROCESS_CONTROL,
const data = await instrumentService.callChannel(INSTRUMENT_CHANNEL.PROCESS_CONTROL,
'launchSuspendedProcessWithDevicePath:bundleIdentifier:environment:arguments:options:', '',
bundleID, {}, [], {'StartSuspendedKey': 0, 'KillExisting': 1});
data.selector.should.be.equal(pid);
Expand All @@ -34,7 +34,7 @@ describe('instrument', function () {
it('should ios device kill app ', async function () {
({server, socket} = await getServerWithFixtures(fixtures.INSTRUMENTS_LAUNCH_APP));
instrumentService = new InstrumentService(socket);
await instrumentService.callChannel(SERVICE.PROCESS_CONTROL, 'killPid:', pid.toString());
await instrumentService.callChannel(INSTRUMENT_CHANNEL.PROCESS_CONTROL, 'killPid:', pid.toString());
});

it('should ios device get fps', async function () {
Expand All @@ -46,7 +46,7 @@ describe('instrument', function () {
}
instrumentService = new InstrumentService(socket, message);
const data = [];
await instrumentService.callChannel(SERVICE.GRAPHICS_OPENGL, 'startSamplingAtTimeInterval:', 0);
await instrumentService.callChannel(INSTRUMENT_CHANNEL.GRAPHICS_OPENGL, 'startSamplingAtTimeInterval:', 0);
await new B((resolve) => {
setTimeout(() => {
resolve(data);
Expand Down

0 comments on commit 40983e5

Please sign in to comment.