MCPcopy Index your code
hub / github.com/ptmt/react-native-macos / Device

Class Device

local-cli/server/util/inspectorProxy.js:104–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102const DEVTOOLS_URL_BASE = 'https://chrome-devtools-frontend.appspot.com/serve_file/@60cd6e859b9f557d2312f5bf532f6aec5f284980/inspector.html?ws=';
103
104class Device {
105 name: string;
106
107 _id: string;
108 _socket: WebSocket;
109 _handlers: Map<string, (result?: Object) => void>;
110 _connections: Map<string, WebSocket>;
111
112 constructor(id: string, name: string, socket: WebSocket) {
113 this.name = name;
114 this._id = id;
115 this._socket = socket;
116 this._handlers = new Map();
117 this._connections = new Map();
118
119 this._socket.on('message', this._onMessage.bind(this));
120 this._socket.on('close', this._onDeviceDisconnected.bind(this));
121 }
122
123 getPages(): Promise<Array<DevicePage>> {
124 return this._callMethod('getPages');
125 }
126
127 connect(pageId: string, socket: WebSocket) {
128 socket.on('message', (message: string) => {
129 if (!this._connections.has(pageId)) {
130 // Not connected, silently ignoring
131 return;
132 }
133
134 // TODO: This should be handled way earlier, preferably in the inspector itself.
135 // That is how it works it newer versions but it requires installing hooks.
136 if (message.indexOf('Network.loadResourceForFrontend') !== -1) {
137 this._loadResourceForFrontend(socket, JSON.parse(message));
138 return;
139 }
140
141 this._send({
142 event: 'wrappedEvent',
143 payload: {
144 pageId,
145 wrappedEvent: message,
146 },
147 });
148 });
149 socket.on('close', () => {
150 if (this._connections.has(pageId)) {
151 this._send({event: 'disconnect', payload: {pageId: pageId}});
152 this._removeConnection(pageId);
153 }
154 });
155 this._connections.set(pageId, socket);
156 this._send({event: 'connect', payload: {pageId: pageId}});
157 }
158
159 _callMethod(name: 'getPages'): Promise<any> {
160 const promise = new Promise((fulfill, reject) => {
161 const timerId = setTimeout(() => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…