Commit d97d8849 authored by lukas.niegsch's avatar lukas.niegsch

fixed attach/detach + instant event loading problems

parent d9f6a733
......@@ -35,10 +35,6 @@
var targetId;
var sessionId;
var base64data;
/**
* todo: detaching should reset session properly
* todo: close target stops receiving messages ...
*/
return gadget.getDeclaredGadget("devtools")
.push(function (subgadget) {
return subgadget.getDevtools();
......@@ -76,7 +72,10 @@
})
.push(function (result) {
base64data = result.data;
// return devtools.Target.closeTarget({targetId: targetId});
return devtools.Target.detachFromTarget({sessionId: sessionId});
})
.push(function () {
return devtools.Target.closeTarget({targetId: targetId});
})
.push(function () {
return base64data;
......
......@@ -69,6 +69,7 @@ var BROWSER_PASSWORD = "ignored";
method: `${domain.domain}.${method.name}`,
params: params,
}
console.log(command);
var message = JSON.stringify(command);
gadget.state.websocket.send(message);
var handler = {
......@@ -78,6 +79,7 @@ var BROWSER_PASSWORD = "ignored";
error: reject
}
gadget.state.handlers.add(handler);
return gadget.changeState({update: true});
}
return RSVP.Queue().push(function () {
return RSVP.Promise(callback);
......@@ -103,6 +105,7 @@ var BROWSER_PASSWORD = "ignored";
error: reject
}
gadget.state.handlers.add(handler);
return gadget.changeState({update: true});
}
return RSVP.Queue().push(function () {
return RSVP.Promise(callback);
......@@ -140,14 +143,9 @@ var BROWSER_PASSWORD = "ignored";
}
let detachFromTarget = devtoolsAPI.Target.detachFromTarget;
devtoolsAPI.Target.detachFromTarget = (params) => {
var response;
return detachFromTarget(params)
.push(function (result) {
response = result;
return gadget.changeState({sessionId: gadget.state.browserId});
})
return gadget.changeState({sessionId: undefined})
.push(function () {
return response;
return detachFromTarget(params);
})
}
return gadget.changeState({devtools: devtoolsAPI});
......@@ -185,14 +183,14 @@ var BROWSER_PASSWORD = "ignored";
* @param {object} message The message that contains the result data.
* @param {object} gadget The gadget that contains all the handlers.
*/
function handleMethodMessage(gadget, message)
{
function handleMethodMessage(gadget, message) {
for (let it = gadget.state.handlers.values(), handler = null; handler = it.next().value;) {
if (handler.id != message.id) {
continue;
}
gadget.state.handlers.delete(handler);
gadget.state.messages.delete(message);
if ('error' in message) {
handler.error(message.error);
......@@ -207,9 +205,12 @@ var BROWSER_PASSWORD = "ignored";
* @param {object} message The message that contains the event data.
* @param {object} gadget The gadget that contains all the handlers.
*/
function handleEventMessage(gadget, message)
{
function handleEventMessage(gadget, message) {
for (let it = gadget.state.handlers.values(), handler = null; handler = it.next().value;) {
setTimeout(function () {
gadget.state.messages.delete(message);
}, 5000);
if (handler.method != message.method) {
continue;
}
......@@ -221,8 +222,8 @@ var BROWSER_PASSWORD = "ignored";
rJS(window)
.setState({
update: false,
websocket: null,
browserId: undefined,
sessionId: undefined,
nextIndex: 0,
handlers: null,
......@@ -236,11 +237,6 @@ var BROWSER_PASSWORD = "ignored";
return getBrowserJSON("json/version")
.push(function (result) {
var browserUrl = result.webSocketDebuggerUrl;
// todo: somehow fetch browser id:
// -> not: browserUrl.split("/").slice(-1)[0]
// -> not: Target.getTargets()[x].browserContextId
// -> not: reopen new websocket on Target.detachFromTarget()
gadget.state.browserId = undefined;
return updateWebsocket(gadget, browserUrl);
})
.push(function () {
......@@ -263,16 +259,15 @@ var BROWSER_PASSWORD = "ignored";
})
.onStateChange(function () {
var gadget = this;
gadget.state.update = false;
for (let it = gadget.state.messages.values(), message = null; message = it.next().value;) {
console.log(message);
if (message.hasOwnProperty("id")) {
handleMethodMessage(gadget, message);
}
if (message.hasOwnProperty("method")) {
handleEventMessage(gadget, message);
}
gadget.state.messages.delete(message);
}
})
}(window, rJS, RSVP));
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment