Skip to content

Extensions Communication Protocol

Daniel Di Sarli edited this page May 4, 2015 · 5 revisions

Extensions Communication Protocol

WARNING: THIS IS AN ALPHA FEATURE. YOU WON'T FIND IT IN THE NOTEPADQQ MASTER BRANCH.

Each extension is a separate process that interacts with Notepadqq via local sockets. All messages are JSON objects. Each message should NOT contain newlines. The following examples are written on multiple lines just for sake of clarity.

Messages from an extension to nqq, used to call a method on an object:

{
    objectId: number,
    method: string,
    args: array of value
}

objectId is the identifier of the object. It can be a standard object identifier, or an identifier returned by another call. method is a string containing the name of the method to call, and args is an array of arguments for the method. For example, this message prints "Hello World" on Notepadqq's stdout:

{
    objectId: 1,
    method: "print",
    args: ["Hello World"]
}

Replies from nqq to the previous type of messages:

{
    result: value,     # Always present
    err: number,
    errStr: string,
}

If err is 0, no error occurred. result is the returned value.

A special object can appear in any position within result to represent a Stub:

{"$__nqq__stub_type": string, "id": number}

Events (sent from notepadqq to an extension):

{
    objectId: number,
    event: string,
    args: array of value
}

objectId is the id of the sender of the event. event is the event name, args are the arguments.

A special object can appear in any position within args to represent a Stub:

{"$__nqq__stub_type": string, "id": number}

Example event:

{
    objectId: 1,
    event: "newWindow",
    args: [ {"$__nqq__stub_type": "Window", "id": 102} ]
}