@player-tools/devtools-client 0.2.1--canary.11.139
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/index.cjs.js +197 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.esm.js +177 -0
- package/package.json +33 -0
- package/src/index.ts +3 -0
- package/src/redux/actions.ts +82 -0
- package/src/redux/aliases.ts +51 -0
- package/src/redux/index.ts +73 -0
- package/src/redux/reducers.ts +119 -0
- package/src/rpc/index.ts +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var devtoolsCommon = require('@player-tools/devtools-common');
|
|
6
|
+
var toolkit = require('@reduxjs/toolkit');
|
|
7
|
+
|
|
8
|
+
const GET_INFO_DETAILS = "GET_INFO_DETAILS";
|
|
9
|
+
const GET_CONFIG_DETAILS = "GET_CONFIG_DETAILS";
|
|
10
|
+
const GET_VIEW_DETAILS = "GET_VIEW_DETAILS";
|
|
11
|
+
const GET_DATA_BINDING_DETAILS = "GET_DATA_BINDING_DETAILS";
|
|
12
|
+
const GET_CONSOLE_EVAL = "GET_CONSOLE_EVAL";
|
|
13
|
+
const START_PROFILER = "START_PROFILER";
|
|
14
|
+
const STOP_PROFILER = "STOP_PROFILER";
|
|
15
|
+
const alias = (aliases) => () => (next) => (action) => {
|
|
16
|
+
const alias2 = aliases[action.type];
|
|
17
|
+
if (alias2) {
|
|
18
|
+
return next(alias2(action));
|
|
19
|
+
}
|
|
20
|
+
return next(action);
|
|
21
|
+
};
|
|
22
|
+
const buildAliases = (actions) => alias({
|
|
23
|
+
GET_INFO_DETAILS: (action) => actions["player-runtime-info-request"](action.payload),
|
|
24
|
+
GET_CONFIG_DETAILS: (action) => actions["player-config-request"](action.payload),
|
|
25
|
+
GET_VIEW_DETAILS: (action) => actions["player-view-details-request"](action.payload),
|
|
26
|
+
GET_DATA_BINDING_DETAILS: (action) => actions["player-data-binding-details"](action.payload),
|
|
27
|
+
GET_CONSOLE_EVAL: (action) => actions["player-execute-expression"](action.payload),
|
|
28
|
+
START_PROFILER: (action) => actions["player-start-profiler-request"](action.payload),
|
|
29
|
+
STOP_PROFILER: (action) => actions["player-stop-profiler-request"](action.payload)
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
var fulfilled = (value) => {
|
|
35
|
+
try {
|
|
36
|
+
step(generator.next(value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var rejected = (value) => {
|
|
42
|
+
try {
|
|
43
|
+
step(generator.throw(value));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
reject(e);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
const logger = devtoolsCommon.createLogger(devtoolsCommon.BACKGROUND_SOURCE);
|
|
53
|
+
const buildRPCActions = (handlers) => devtoolsCommon.Runtime.RuntimeRPCTypes.reduce((acc, rpcType) => (acc[rpcType] = toolkit.createAsyncThunk(rpcType, (params) => __async(undefined, null, function* () {
|
|
54
|
+
logger.log(`Requesting ${rpcType}`, params);
|
|
55
|
+
const data = yield handlers[rpcType].call(params);
|
|
56
|
+
logger.log(`Response from ${rpcType}`, data);
|
|
57
|
+
return data;
|
|
58
|
+
})), acc), {});
|
|
59
|
+
|
|
60
|
+
const buildPlayerReducerCallback = (actions) => (builder) => {
|
|
61
|
+
builder.addCase(actions["player-runtime-info-request"].fulfilled, (state, action) => {
|
|
62
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
63
|
+
if (!selectedPlayerId) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const data = action.payload && Object.keys(action.payload).length > 0 ? action.payload : null;
|
|
67
|
+
activePlayers[selectedPlayerId].flowInfo = data;
|
|
68
|
+
});
|
|
69
|
+
builder.addCase(actions["player-config-request"].fulfilled, (state, action) => {
|
|
70
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
71
|
+
if (!selectedPlayerId) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
activePlayers[selectedPlayerId].configState = action.payload;
|
|
75
|
+
});
|
|
76
|
+
builder.addCase(actions["player-view-details-request"].fulfilled, (state, action) => {
|
|
77
|
+
var _a;
|
|
78
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
79
|
+
if (!selectedPlayerId) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
activePlayers[selectedPlayerId].view = (_a = action.payload) == null ? void 0 : _a.lastViewUpdate;
|
|
83
|
+
});
|
|
84
|
+
builder.addCase(actions["player-data-binding-details"].fulfilled, (state, action) => {
|
|
85
|
+
const {
|
|
86
|
+
meta: {
|
|
87
|
+
arg: { binding, playerID }
|
|
88
|
+
},
|
|
89
|
+
payload
|
|
90
|
+
} = action;
|
|
91
|
+
const { activePlayers } = state;
|
|
92
|
+
if (!playerID || !activePlayers[playerID]) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (binding === "") {
|
|
96
|
+
activePlayers[playerID].dataState.allBindings = payload;
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
activePlayers[playerID].dataState.selectedBinding = payload;
|
|
100
|
+
});
|
|
101
|
+
builder.addCase(actions["player-execute-expression"].fulfilled, (state, action) => {
|
|
102
|
+
var _a, _b, _c, _d;
|
|
103
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
104
|
+
if (!selectedPlayerId) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
(_d = (_a = activePlayers[selectedPlayerId].consoleState) == null ? void 0 : _a.history) == null ? void 0 : _d.push({
|
|
108
|
+
id: action.meta.requestId,
|
|
109
|
+
result: action.payload,
|
|
110
|
+
expression: (_c = (_b = action.payload) == null ? void 0 : _b.exp) != null ? _c : ""
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
builder.addCase(actions["player-start-profiler-request"].fulfilled, (state, action) => {
|
|
114
|
+
var _a;
|
|
115
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
116
|
+
if (!selectedPlayerId)
|
|
117
|
+
return;
|
|
118
|
+
activePlayers[selectedPlayerId].profilerInfo = (_a = action.payload) == null ? void 0 : _a.data;
|
|
119
|
+
});
|
|
120
|
+
builder.addCase(actions["player-stop-profiler-request"].fulfilled, (state, action) => {
|
|
121
|
+
var _a;
|
|
122
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
123
|
+
if (!selectedPlayerId)
|
|
124
|
+
return;
|
|
125
|
+
activePlayers[selectedPlayerId].profilerInfo = (_a = action.payload) == null ? void 0 : _a.data;
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
function handleMessage(store, message) {
|
|
130
|
+
switch (message.type) {
|
|
131
|
+
case "runtime-init":
|
|
132
|
+
store.dispatch(devtoolsCommon.clearStore());
|
|
133
|
+
break;
|
|
134
|
+
case "player-init":
|
|
135
|
+
store.dispatch(devtoolsCommon.playerInitAction(message));
|
|
136
|
+
store.dispatch(devtoolsCommon.selectedPlayerAction());
|
|
137
|
+
break;
|
|
138
|
+
case "player-removed":
|
|
139
|
+
store.dispatch(devtoolsCommon.playerRemoveAction(message.playerID));
|
|
140
|
+
store.dispatch(devtoolsCommon.selectedPlayerAction());
|
|
141
|
+
break;
|
|
142
|
+
case "player-flow-start":
|
|
143
|
+
store.dispatch(devtoolsCommon.playerFlowStartAction(message));
|
|
144
|
+
store.dispatch(devtoolsCommon.playerTimelineAction(message));
|
|
145
|
+
store.dispatch({
|
|
146
|
+
type: GET_DATA_BINDING_DETAILS,
|
|
147
|
+
payload: { playerID: message.playerID, binding: "" }
|
|
148
|
+
});
|
|
149
|
+
break;
|
|
150
|
+
case "player-log-event":
|
|
151
|
+
store.dispatch(devtoolsCommon.playerTimelineAction(message));
|
|
152
|
+
break;
|
|
153
|
+
case "player-view-update-event":
|
|
154
|
+
store.dispatch(devtoolsCommon.playerViewUpdateAction(message));
|
|
155
|
+
break;
|
|
156
|
+
case "player-data-change-event": {
|
|
157
|
+
const { players } = store.getState();
|
|
158
|
+
if (players.activePlayers[message.playerID] && players.activePlayers[message.playerID].dataState.selectedBinding) {
|
|
159
|
+
store.dispatch({
|
|
160
|
+
type: GET_DATA_BINDING_DETAILS,
|
|
161
|
+
payload: message
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
store.dispatch({
|
|
165
|
+
type: GET_DATA_BINDING_DETAILS,
|
|
166
|
+
payload: { playerID: message.playerID, binding: "" }
|
|
167
|
+
});
|
|
168
|
+
store.dispatch(devtoolsCommon.playerTimelineAction(message));
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
default:
|
|
172
|
+
console.warn(`Unhandled event: ${JSON.stringify(message)}`);
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const buildRPCRequests = (onRequestMessage) => devtoolsCommon.Runtime.RuntimeRPCTypes.reduce((acc, rpcType) => (acc[rpcType] = devtoolsCommon.createRPCRequest(rpcType, devtoolsCommon.PANEL_SOURCE, onRequestMessage), acc), {});
|
|
178
|
+
|
|
179
|
+
exports.GET_CONFIG_DETAILS = GET_CONFIG_DETAILS;
|
|
180
|
+
exports.GET_CONSOLE_EVAL = GET_CONSOLE_EVAL;
|
|
181
|
+
exports.GET_DATA_BINDING_DETAILS = GET_DATA_BINDING_DETAILS;
|
|
182
|
+
exports.GET_INFO_DETAILS = GET_INFO_DETAILS;
|
|
183
|
+
exports.GET_VIEW_DETAILS = GET_VIEW_DETAILS;
|
|
184
|
+
exports.START_PROFILER = START_PROFILER;
|
|
185
|
+
exports.STOP_PROFILER = STOP_PROFILER;
|
|
186
|
+
exports.buildAliases = buildAliases;
|
|
187
|
+
exports.buildPlayerReducerCallback = buildPlayerReducerCallback;
|
|
188
|
+
exports.buildRPCActions = buildRPCActions;
|
|
189
|
+
exports.buildRPCRequests = buildRPCRequests;
|
|
190
|
+
exports.handleMessage = handleMessage;
|
|
191
|
+
Object.keys(devtoolsCommon).forEach(function (k) {
|
|
192
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
get: function () { return devtoolsCommon[k]; }
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Runtime, RPCRequestHandler, RPCRequestMessageEvent, PlayersState, Message } from '@player-tools/devtools-common';
|
|
2
|
+
export * from '@player-tools/devtools-common';
|
|
3
|
+
import { Store } from 'redux';
|
|
4
|
+
import { AsyncThunk, ActionReducerMapBuilder } from '@reduxjs/toolkit';
|
|
5
|
+
|
|
6
|
+
declare type RuntimeRPCRequestHandlers = {
|
|
7
|
+
[key in Runtime.RuntimeRPCTypes]: RPCRequestHandler<any>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
declare const buildRPCRequests: (onRequestMessage: (message: RPCRequestMessageEvent<Runtime.RuntimeRPC>) => void) => RuntimeRPCRequestHandlers;
|
|
13
|
+
|
|
14
|
+
declare type AsyncRPCActions = {
|
|
15
|
+
[key in Runtime.RuntimeRPCTypes]: AsyncThunk<Extract<Runtime.RuntimeRPC, {
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
type: key;
|
|
20
|
+
}>['result'], Extract<Runtime.RuntimeRPC, {
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
type: key;
|
|
25
|
+
}>['params'], {}>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
declare const buildRPCActions: (handlers: RuntimeRPCRequestHandlers) => AsyncRPCActions;
|
|
31
|
+
|
|
32
|
+
declare const GET_INFO_DETAILS = "GET_INFO_DETAILS";
|
|
33
|
+
declare const GET_CONFIG_DETAILS = "GET_CONFIG_DETAILS";
|
|
34
|
+
declare const GET_VIEW_DETAILS = "GET_VIEW_DETAILS";
|
|
35
|
+
declare const GET_DATA_BINDING_DETAILS = "GET_DATA_BINDING_DETAILS";
|
|
36
|
+
declare const GET_CONSOLE_EVAL = "GET_CONSOLE_EVAL";
|
|
37
|
+
declare const START_PROFILER = "START_PROFILER";
|
|
38
|
+
declare const STOP_PROFILER = "STOP_PROFILER";
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
declare const buildAliases: (actions: AsyncRPCActions) => () => (next: any) => (action: any) => any;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Callback function that adds cases for async actions for the player.
|
|
46
|
+
*
|
|
47
|
+
* @param playerReducerCallback
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
declare const buildPlayerReducerCallback: (actions: AsyncRPCActions) => (builder: ActionReducerMapBuilder<PlayersState>) => void;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
declare function handleMessage(store: Store, message: Message): void;
|
|
56
|
+
|
|
57
|
+
export { AsyncRPCActions, GET_CONFIG_DETAILS, GET_CONSOLE_EVAL, GET_DATA_BINDING_DETAILS, GET_INFO_DETAILS, GET_VIEW_DETAILS, RuntimeRPCRequestHandlers, START_PROFILER, STOP_PROFILER, buildAliases, buildPlayerReducerCallback, buildRPCActions, buildRPCRequests, handleMessage };
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { createLogger, BACKGROUND_SOURCE, Runtime, playerTimelineAction, playerViewUpdateAction, playerFlowStartAction, playerRemoveAction, selectedPlayerAction, playerInitAction, clearStore, createRPCRequest, PANEL_SOURCE } from '@player-tools/devtools-common';
|
|
2
|
+
export * from '@player-tools/devtools-common';
|
|
3
|
+
import { createAsyncThunk } from '@reduxjs/toolkit';
|
|
4
|
+
|
|
5
|
+
const GET_INFO_DETAILS = "GET_INFO_DETAILS";
|
|
6
|
+
const GET_CONFIG_DETAILS = "GET_CONFIG_DETAILS";
|
|
7
|
+
const GET_VIEW_DETAILS = "GET_VIEW_DETAILS";
|
|
8
|
+
const GET_DATA_BINDING_DETAILS = "GET_DATA_BINDING_DETAILS";
|
|
9
|
+
const GET_CONSOLE_EVAL = "GET_CONSOLE_EVAL";
|
|
10
|
+
const START_PROFILER = "START_PROFILER";
|
|
11
|
+
const STOP_PROFILER = "STOP_PROFILER";
|
|
12
|
+
const alias = (aliases) => () => (next) => (action) => {
|
|
13
|
+
const alias2 = aliases[action.type];
|
|
14
|
+
if (alias2) {
|
|
15
|
+
return next(alias2(action));
|
|
16
|
+
}
|
|
17
|
+
return next(action);
|
|
18
|
+
};
|
|
19
|
+
const buildAliases = (actions) => alias({
|
|
20
|
+
GET_INFO_DETAILS: (action) => actions["player-runtime-info-request"](action.payload),
|
|
21
|
+
GET_CONFIG_DETAILS: (action) => actions["player-config-request"](action.payload),
|
|
22
|
+
GET_VIEW_DETAILS: (action) => actions["player-view-details-request"](action.payload),
|
|
23
|
+
GET_DATA_BINDING_DETAILS: (action) => actions["player-data-binding-details"](action.payload),
|
|
24
|
+
GET_CONSOLE_EVAL: (action) => actions["player-execute-expression"](action.payload),
|
|
25
|
+
START_PROFILER: (action) => actions["player-start-profiler-request"](action.payload),
|
|
26
|
+
STOP_PROFILER: (action) => actions["player-stop-profiler-request"](action.payload)
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
var __async = (__this, __arguments, generator) => {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
var fulfilled = (value) => {
|
|
32
|
+
try {
|
|
33
|
+
step(generator.next(value));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
reject(e);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var rejected = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
step(generator.throw(value));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
46
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const logger = createLogger(BACKGROUND_SOURCE);
|
|
50
|
+
const buildRPCActions = (handlers) => Runtime.RuntimeRPCTypes.reduce((acc, rpcType) => (acc[rpcType] = createAsyncThunk(rpcType, (params) => __async(undefined, null, function* () {
|
|
51
|
+
logger.log(`Requesting ${rpcType}`, params);
|
|
52
|
+
const data = yield handlers[rpcType].call(params);
|
|
53
|
+
logger.log(`Response from ${rpcType}`, data);
|
|
54
|
+
return data;
|
|
55
|
+
})), acc), {});
|
|
56
|
+
|
|
57
|
+
const buildPlayerReducerCallback = (actions) => (builder) => {
|
|
58
|
+
builder.addCase(actions["player-runtime-info-request"].fulfilled, (state, action) => {
|
|
59
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
60
|
+
if (!selectedPlayerId) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const data = action.payload && Object.keys(action.payload).length > 0 ? action.payload : null;
|
|
64
|
+
activePlayers[selectedPlayerId].flowInfo = data;
|
|
65
|
+
});
|
|
66
|
+
builder.addCase(actions["player-config-request"].fulfilled, (state, action) => {
|
|
67
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
68
|
+
if (!selectedPlayerId) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
activePlayers[selectedPlayerId].configState = action.payload;
|
|
72
|
+
});
|
|
73
|
+
builder.addCase(actions["player-view-details-request"].fulfilled, (state, action) => {
|
|
74
|
+
var _a;
|
|
75
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
76
|
+
if (!selectedPlayerId) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
activePlayers[selectedPlayerId].view = (_a = action.payload) == null ? void 0 : _a.lastViewUpdate;
|
|
80
|
+
});
|
|
81
|
+
builder.addCase(actions["player-data-binding-details"].fulfilled, (state, action) => {
|
|
82
|
+
const {
|
|
83
|
+
meta: {
|
|
84
|
+
arg: { binding, playerID }
|
|
85
|
+
},
|
|
86
|
+
payload
|
|
87
|
+
} = action;
|
|
88
|
+
const { activePlayers } = state;
|
|
89
|
+
if (!playerID || !activePlayers[playerID]) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (binding === "") {
|
|
93
|
+
activePlayers[playerID].dataState.allBindings = payload;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
activePlayers[playerID].dataState.selectedBinding = payload;
|
|
97
|
+
});
|
|
98
|
+
builder.addCase(actions["player-execute-expression"].fulfilled, (state, action) => {
|
|
99
|
+
var _a, _b, _c, _d;
|
|
100
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
101
|
+
if (!selectedPlayerId) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
(_d = (_a = activePlayers[selectedPlayerId].consoleState) == null ? void 0 : _a.history) == null ? void 0 : _d.push({
|
|
105
|
+
id: action.meta.requestId,
|
|
106
|
+
result: action.payload,
|
|
107
|
+
expression: (_c = (_b = action.payload) == null ? void 0 : _b.exp) != null ? _c : ""
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
builder.addCase(actions["player-start-profiler-request"].fulfilled, (state, action) => {
|
|
111
|
+
var _a;
|
|
112
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
113
|
+
if (!selectedPlayerId)
|
|
114
|
+
return;
|
|
115
|
+
activePlayers[selectedPlayerId].profilerInfo = (_a = action.payload) == null ? void 0 : _a.data;
|
|
116
|
+
});
|
|
117
|
+
builder.addCase(actions["player-stop-profiler-request"].fulfilled, (state, action) => {
|
|
118
|
+
var _a;
|
|
119
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
120
|
+
if (!selectedPlayerId)
|
|
121
|
+
return;
|
|
122
|
+
activePlayers[selectedPlayerId].profilerInfo = (_a = action.payload) == null ? void 0 : _a.data;
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
function handleMessage(store, message) {
|
|
127
|
+
switch (message.type) {
|
|
128
|
+
case "runtime-init":
|
|
129
|
+
store.dispatch(clearStore());
|
|
130
|
+
break;
|
|
131
|
+
case "player-init":
|
|
132
|
+
store.dispatch(playerInitAction(message));
|
|
133
|
+
store.dispatch(selectedPlayerAction());
|
|
134
|
+
break;
|
|
135
|
+
case "player-removed":
|
|
136
|
+
store.dispatch(playerRemoveAction(message.playerID));
|
|
137
|
+
store.dispatch(selectedPlayerAction());
|
|
138
|
+
break;
|
|
139
|
+
case "player-flow-start":
|
|
140
|
+
store.dispatch(playerFlowStartAction(message));
|
|
141
|
+
store.dispatch(playerTimelineAction(message));
|
|
142
|
+
store.dispatch({
|
|
143
|
+
type: GET_DATA_BINDING_DETAILS,
|
|
144
|
+
payload: { playerID: message.playerID, binding: "" }
|
|
145
|
+
});
|
|
146
|
+
break;
|
|
147
|
+
case "player-log-event":
|
|
148
|
+
store.dispatch(playerTimelineAction(message));
|
|
149
|
+
break;
|
|
150
|
+
case "player-view-update-event":
|
|
151
|
+
store.dispatch(playerViewUpdateAction(message));
|
|
152
|
+
break;
|
|
153
|
+
case "player-data-change-event": {
|
|
154
|
+
const { players } = store.getState();
|
|
155
|
+
if (players.activePlayers[message.playerID] && players.activePlayers[message.playerID].dataState.selectedBinding) {
|
|
156
|
+
store.dispatch({
|
|
157
|
+
type: GET_DATA_BINDING_DETAILS,
|
|
158
|
+
payload: message
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
store.dispatch({
|
|
162
|
+
type: GET_DATA_BINDING_DETAILS,
|
|
163
|
+
payload: { playerID: message.playerID, binding: "" }
|
|
164
|
+
});
|
|
165
|
+
store.dispatch(playerTimelineAction(message));
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
default:
|
|
169
|
+
console.warn(`Unhandled event: ${JSON.stringify(message)}`);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const buildRPCRequests = (onRequestMessage) => Runtime.RuntimeRPCTypes.reduce((acc, rpcType) => (acc[rpcType] = createRPCRequest(rpcType, PANEL_SOURCE, onRequestMessage), acc), {});
|
|
175
|
+
|
|
176
|
+
export { GET_CONFIG_DETAILS, GET_CONSOLE_EVAL, GET_DATA_BINDING_DETAILS, GET_INFO_DETAILS, GET_VIEW_DETAILS, START_PROFILER, STOP_PROFILER, buildAliases, buildPlayerReducerCallback, buildRPCActions, buildRPCRequests, handleMessage };
|
|
177
|
+
//# sourceMappingURL=index.esm.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@player-tools/devtools-client",
|
|
3
|
+
"version": "0.2.1--canary.11.139",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"registry": "https://registry.npmjs.org"
|
|
7
|
+
},
|
|
8
|
+
"peerDependencies": {},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@reduxjs/toolkit": "^1.6.1",
|
|
11
|
+
"@player-tools/devtools-common": "0.2.1--canary.11.139",
|
|
12
|
+
"@babel/runtime": "7.15.4"
|
|
13
|
+
},
|
|
14
|
+
"main": "dist/index.cjs.js",
|
|
15
|
+
"module": "dist/index.esm.js",
|
|
16
|
+
"typings": "dist/index.d.ts",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/player-ui/tools"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/player-ui/tools/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://player-ui.github.io",
|
|
27
|
+
"contributors": [
|
|
28
|
+
{
|
|
29
|
+
"name": "Ketan Reddy",
|
|
30
|
+
"url": "https://github.com/KetanReddy"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { AsyncThunk } from '@reduxjs/toolkit';
|
|
2
|
+
import { createAsyncThunk } from '@reduxjs/toolkit';
|
|
3
|
+
import {
|
|
4
|
+
Runtime,
|
|
5
|
+
createLogger,
|
|
6
|
+
BACKGROUND_SOURCE,
|
|
7
|
+
} from '@player-tools/devtools-common';
|
|
8
|
+
import type { RuntimeRPCRequestHandlers } from '../rpc';
|
|
9
|
+
|
|
10
|
+
const logger = createLogger(BACKGROUND_SOURCE);
|
|
11
|
+
|
|
12
|
+
export type AsyncRPCActions = {
|
|
13
|
+
[key in Runtime.RuntimeRPCTypes]: AsyncThunk<
|
|
14
|
+
Extract<
|
|
15
|
+
Runtime.RuntimeRPC,
|
|
16
|
+
{
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
type: key;
|
|
21
|
+
}
|
|
22
|
+
>['result'],
|
|
23
|
+
Extract<
|
|
24
|
+
Runtime.RuntimeRPC,
|
|
25
|
+
{
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
type: key;
|
|
30
|
+
}
|
|
31
|
+
>['params'],
|
|
32
|
+
{}
|
|
33
|
+
>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
export const buildRPCActions = (
|
|
40
|
+
handlers: RuntimeRPCRequestHandlers
|
|
41
|
+
): AsyncRPCActions =>
|
|
42
|
+
Runtime.RuntimeRPCTypes.reduce(
|
|
43
|
+
(acc, rpcType) => (
|
|
44
|
+
// TODO: Fix this
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
(acc[rpcType] = createAsyncThunk<
|
|
47
|
+
Extract<
|
|
48
|
+
Runtime.RuntimeRPC,
|
|
49
|
+
{
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
type: typeof rpcType;
|
|
54
|
+
}
|
|
55
|
+
>['result'],
|
|
56
|
+
Extract<
|
|
57
|
+
Runtime.RuntimeRPC,
|
|
58
|
+
{
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
type: typeof rpcType;
|
|
63
|
+
}
|
|
64
|
+
>['params']
|
|
65
|
+
>(rpcType, async (params) => {
|
|
66
|
+
logger.log(`Requesting ${rpcType}`, params);
|
|
67
|
+
const data = (await handlers[rpcType].call(params)) as Extract<
|
|
68
|
+
Runtime.RuntimeRPC,
|
|
69
|
+
{
|
|
70
|
+
/**
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
type: typeof rpcType;
|
|
74
|
+
}
|
|
75
|
+
>['result'];
|
|
76
|
+
logger.log(`Response from ${rpcType}`, data);
|
|
77
|
+
return data;
|
|
78
|
+
})),
|
|
79
|
+
acc
|
|
80
|
+
),
|
|
81
|
+
{} as AsyncRPCActions
|
|
82
|
+
);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AliasAction,
|
|
3
|
+
ConfigAction,
|
|
4
|
+
DataBindingAction,
|
|
5
|
+
ExpressionAction,
|
|
6
|
+
StartProfilerAction,
|
|
7
|
+
StopProfilerAction,
|
|
8
|
+
} from '@player-tools/devtools-common';
|
|
9
|
+
import type { AsyncRPCActions } from './actions';
|
|
10
|
+
|
|
11
|
+
export const GET_INFO_DETAILS = 'GET_INFO_DETAILS';
|
|
12
|
+
export const GET_CONFIG_DETAILS = 'GET_CONFIG_DETAILS';
|
|
13
|
+
export const GET_VIEW_DETAILS = 'GET_VIEW_DETAILS';
|
|
14
|
+
export const GET_DATA_BINDING_DETAILS = 'GET_DATA_BINDING_DETAILS';
|
|
15
|
+
export const GET_CONSOLE_EVAL = 'GET_CONSOLE_EVAL';
|
|
16
|
+
export const START_PROFILER = 'START_PROFILER';
|
|
17
|
+
export const STOP_PROFILER = 'STOP_PROFILER';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
const alias = (aliases: any) => () => (next: any) => (action: any) => {
|
|
23
|
+
const alias = aliases[action.type];
|
|
24
|
+
|
|
25
|
+
if (alias) {
|
|
26
|
+
return next(alias(action));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return next(action);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
export const buildAliases = (actions: AsyncRPCActions) =>
|
|
36
|
+
alias({
|
|
37
|
+
GET_INFO_DETAILS: (action: AliasAction) =>
|
|
38
|
+
actions['player-runtime-info-request'](action.payload),
|
|
39
|
+
GET_CONFIG_DETAILS: (action: ConfigAction) =>
|
|
40
|
+
actions['player-config-request'](action.payload),
|
|
41
|
+
GET_VIEW_DETAILS: (action: AliasAction) =>
|
|
42
|
+
actions['player-view-details-request'](action.payload),
|
|
43
|
+
GET_DATA_BINDING_DETAILS: (action: DataBindingAction) =>
|
|
44
|
+
actions['player-data-binding-details'](action.payload),
|
|
45
|
+
GET_CONSOLE_EVAL: (action: ExpressionAction) =>
|
|
46
|
+
actions['player-execute-expression'](action.payload),
|
|
47
|
+
START_PROFILER: (action: StartProfilerAction) =>
|
|
48
|
+
actions['player-start-profiler-request'](action.payload),
|
|
49
|
+
STOP_PROFILER: (action: StopProfilerAction) =>
|
|
50
|
+
actions['player-stop-profiler-request'](action.payload),
|
|
51
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Message } from '@player-tools/devtools-common';
|
|
2
|
+
import {
|
|
3
|
+
clearStore,
|
|
4
|
+
playerFlowStartAction,
|
|
5
|
+
playerInitAction,
|
|
6
|
+
playerRemoveAction,
|
|
7
|
+
playerTimelineAction,
|
|
8
|
+
playerViewUpdateAction,
|
|
9
|
+
selectedPlayerAction,
|
|
10
|
+
} from '@player-tools/devtools-common';
|
|
11
|
+
import type { Store } from 'redux';
|
|
12
|
+
import { GET_DATA_BINDING_DETAILS } from './aliases';
|
|
13
|
+
|
|
14
|
+
export * from './actions';
|
|
15
|
+
export * from './aliases';
|
|
16
|
+
export * from './reducers';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
export function handleMessage(store: Store, message: Message) {
|
|
22
|
+
switch (message.type) {
|
|
23
|
+
case 'runtime-init':
|
|
24
|
+
store.dispatch(clearStore());
|
|
25
|
+
break;
|
|
26
|
+
case 'player-init':
|
|
27
|
+
store.dispatch(playerInitAction(message));
|
|
28
|
+
store.dispatch(selectedPlayerAction());
|
|
29
|
+
break;
|
|
30
|
+
case 'player-removed':
|
|
31
|
+
store.dispatch(playerRemoveAction(message.playerID));
|
|
32
|
+
store.dispatch(selectedPlayerAction());
|
|
33
|
+
break;
|
|
34
|
+
case 'player-flow-start':
|
|
35
|
+
store.dispatch(playerFlowStartAction(message));
|
|
36
|
+
store.dispatch(playerTimelineAction(message));
|
|
37
|
+
store.dispatch({
|
|
38
|
+
type: GET_DATA_BINDING_DETAILS,
|
|
39
|
+
payload: { playerID: message.playerID, binding: '' },
|
|
40
|
+
});
|
|
41
|
+
break;
|
|
42
|
+
case 'player-log-event':
|
|
43
|
+
store.dispatch(playerTimelineAction(message));
|
|
44
|
+
break;
|
|
45
|
+
case 'player-view-update-event':
|
|
46
|
+
store.dispatch(playerViewUpdateAction(message));
|
|
47
|
+
break;
|
|
48
|
+
case 'player-data-change-event': {
|
|
49
|
+
const { players } = store.getState();
|
|
50
|
+
|
|
51
|
+
if (
|
|
52
|
+
players.activePlayers[message.playerID] &&
|
|
53
|
+
players.activePlayers[message.playerID].dataState.selectedBinding
|
|
54
|
+
) {
|
|
55
|
+
store.dispatch({
|
|
56
|
+
type: GET_DATA_BINDING_DETAILS,
|
|
57
|
+
payload: message,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
store.dispatch({
|
|
62
|
+
type: GET_DATA_BINDING_DETAILS,
|
|
63
|
+
payload: { playerID: message.playerID, binding: '' },
|
|
64
|
+
});
|
|
65
|
+
store.dispatch(playerTimelineAction(message));
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
default:
|
|
70
|
+
console.warn(`Unhandled event: ${JSON.stringify(message)}`);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { ActionReducerMapBuilder } from '@reduxjs/toolkit';
|
|
2
|
+
import type { PlayersState } from '@player-tools/devtools-common';
|
|
3
|
+
import type { AsyncRPCActions } from './actions';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Callback function that adds cases for async actions for the player.
|
|
7
|
+
*
|
|
8
|
+
* @param playerReducerCallback
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export const buildPlayerReducerCallback =
|
|
12
|
+
(actions: AsyncRPCActions) =>
|
|
13
|
+
(builder: ActionReducerMapBuilder<PlayersState>) => {
|
|
14
|
+
builder.addCase(
|
|
15
|
+
actions['player-runtime-info-request'].fulfilled,
|
|
16
|
+
(state, action) => {
|
|
17
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
18
|
+
|
|
19
|
+
if (!selectedPlayerId) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const data =
|
|
24
|
+
action.payload && Object.keys(action.payload).length > 0
|
|
25
|
+
? action.payload
|
|
26
|
+
: null;
|
|
27
|
+
activePlayers[selectedPlayerId].flowInfo = data;
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
builder.addCase(
|
|
32
|
+
actions['player-config-request'].fulfilled,
|
|
33
|
+
(state, action) => {
|
|
34
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
35
|
+
|
|
36
|
+
if (!selectedPlayerId) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
activePlayers[selectedPlayerId].configState = action.payload;
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
builder.addCase(
|
|
45
|
+
actions['player-view-details-request'].fulfilled,
|
|
46
|
+
(state, action) => {
|
|
47
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
48
|
+
|
|
49
|
+
if (!selectedPlayerId) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
activePlayers[selectedPlayerId].view = action.payload?.lastViewUpdate;
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
builder.addCase(
|
|
58
|
+
actions['player-data-binding-details'].fulfilled,
|
|
59
|
+
(state, action) => {
|
|
60
|
+
const {
|
|
61
|
+
meta: {
|
|
62
|
+
arg: { binding, playerID },
|
|
63
|
+
},
|
|
64
|
+
payload,
|
|
65
|
+
} = action;
|
|
66
|
+
const { activePlayers } = state;
|
|
67
|
+
|
|
68
|
+
if (!playerID || !activePlayers[playerID]) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (binding === '') {
|
|
73
|
+
activePlayers[playerID].dataState.allBindings = payload;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
activePlayers[playerID].dataState.selectedBinding = payload;
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
builder.addCase(
|
|
82
|
+
actions['player-execute-expression'].fulfilled,
|
|
83
|
+
(state, action) => {
|
|
84
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
85
|
+
|
|
86
|
+
if (!selectedPlayerId) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
activePlayers[selectedPlayerId].consoleState?.history?.push({
|
|
91
|
+
id: action.meta.requestId,
|
|
92
|
+
result: action.payload,
|
|
93
|
+
expression: action.payload?.exp ?? '',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
builder.addCase(
|
|
99
|
+
actions['player-start-profiler-request'].fulfilled,
|
|
100
|
+
(state, action) => {
|
|
101
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
102
|
+
|
|
103
|
+
if (!selectedPlayerId) return;
|
|
104
|
+
|
|
105
|
+
activePlayers[selectedPlayerId].profilerInfo = action.payload?.data;
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
builder.addCase(
|
|
110
|
+
actions['player-stop-profiler-request'].fulfilled,
|
|
111
|
+
(state, action) => {
|
|
112
|
+
const { activePlayers, selectedPlayerId } = state;
|
|
113
|
+
|
|
114
|
+
if (!selectedPlayerId) return;
|
|
115
|
+
|
|
116
|
+
activePlayers[selectedPlayerId].profilerInfo = action.payload?.data;
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
};
|
package/src/rpc/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Runtime as PlayerRuntime,
|
|
3
|
+
RPCRequestMessageEvent,
|
|
4
|
+
RPCRequestHandler,
|
|
5
|
+
} from '@player-tools/devtools-common';
|
|
6
|
+
import {
|
|
7
|
+
createRPCRequest,
|
|
8
|
+
PANEL_SOURCE,
|
|
9
|
+
Runtime,
|
|
10
|
+
} from '@player-tools/devtools-common';
|
|
11
|
+
|
|
12
|
+
export type RuntimeRPCRequestHandlers = {
|
|
13
|
+
[key in Runtime.RuntimeRPCTypes]: RPCRequestHandler<any>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
export const buildRPCRequests = (
|
|
20
|
+
onRequestMessage: (
|
|
21
|
+
message: RPCRequestMessageEvent<PlayerRuntime.RuntimeRPC>
|
|
22
|
+
) => void
|
|
23
|
+
): RuntimeRPCRequestHandlers =>
|
|
24
|
+
Runtime.RuntimeRPCTypes.reduce(
|
|
25
|
+
(acc, rpcType) => (
|
|
26
|
+
(acc[rpcType] = createRPCRequest(
|
|
27
|
+
rpcType,
|
|
28
|
+
PANEL_SOURCE,
|
|
29
|
+
onRequestMessage
|
|
30
|
+
)),
|
|
31
|
+
acc
|
|
32
|
+
),
|
|
33
|
+
{} as RuntimeRPCRequestHandlers
|
|
34
|
+
);
|