| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
For advanced/power users, Synapse X contains a easy to use WebSocket API to allow third party plugins to interface with Synapse X. The documentation for the API is below:
This guide is going to be advanced and go into technical details on how this system fully works. If you are a regular user of Synapse X and do not wish to create plugins to interface with Synapse X, this guide is probably not for you.
For regular users though, this guide will allow developers to make plugins which can improve your user experience by a ton. Expect a lot of developers to make your life a lot easier with this.
You can even execute scripts from the browser, and create all sorts of cool things via this API. See below for more details.
Security concerns are a big problem for the Synapse X WebSocket API. Since this API allows applications to arbitrarily execute scripts, some security features were implemented to prevent abuse of this API.
All applications that use this API must be whitelisted. Whitelists for the API are split into two categories:
Note: Applications running on the end users machine (ex: native applications) are presumed to be trusted by default and do not require whitelisting.
You can contact me on Discord about whitelisting your application. Please be prepared to show your application to me before getting whitelisted.
Abusing the API with your whitelist will result in you being blacklisted from both the API and Synapse X itself.
The WebSocket API uses WebSockets, meaning you will have to use a WebSocket library to connect. Some libraries for different languages are below:
You can also test the API directly via browser from this Google Chrome extension - it is pre-whitelisted.
The rest of this tutorial will use WebSocket-Sharp (C#) and WebSockets (Node) for examples.
The Synapse X WebSocket API is not enabled by default, and requires you to manually enable it in theme-wpf.json. You can find the toggle for it in Main.WebSocket.Enabled.
After enabling the Synapse X WebSocket, you can then connect via the following base URL: ws://localhost:24892. "Services" (explained in the next section) are extensions of this base URL, and are separate.
The Synapse X WebSocket API currently has 4 services: Execute, Editor, Attach, and Custom. Each service can be accessed by appending the service name to the end of the URL: (ex: ws://localhost:24892/execute)
You can then connect to the service by using that completed URL as the WebSocket URL. After authentication completes, your WebSocket will be opened and you can execute commands.
ws://localhost:24892/execute
The execute service is the most simple service of the Synapse X WebSocket API. Sending data to the service will simply execute it in Synapse X. After execution completes, a response code will be sent back to you.
Response Codes:
Examples:
const WebSocket = require("ws");
const ws = new WebSocket("ws://localhost:24892/execute");
ws.on("open", function open()
{
ws.send("print'Hello world!'");
});
ws.on("message", function incoming(data)
{
console.log(data); //Response Code - "OK" in most cases
});using System;
using WebSocketSharp;
namespace TestWebSocket
{
public class Program
{
public static void Main(string[] args)
{
using (var ws = new WebSocket("ws://localhost:24892/execute"))
{
ws.OnMessage += (sender, e) =>
Console.WriteLine(e.Data); //Response Code - usually "OK"
ws.Connect();
ws.Send("print'Hello world!'");
Console.ReadKey(true);
}
}
}
}ws://localhost:24892/editor
The editor service has the same interface of the execute service, except it will set the data sent to the editor instead of being executed. Examples are the same, except the NOT_READY response code is never sent for the editor service.
ws://localhost:24892/attach
The attach service is the most complex service of the 4 current services. It contains 2 specific commands: ATTACH, and IS_READY.
Commands:
Response Events:
Examples:
const WebSocket = require("ws");
const Alert = require("alert-node");
const ws = new WebSocket("ws://localhost:24892/attach");
ws.on("open", function open()
{
ws.send("ATTACH");
});
ws.on("message", function incoming(data)
{
//This will be called back multiple times during the attaching process
console.log(data);
if (data == "READY")
{
Alert("Synapse has attached!");
}
else if (data == "ALREADY_ATTACHED")
{
Alert("Synapse is already attached!");
}
else if(data == "INTERRUPT")
{
Alert("Synapse has failed to attach!");
}
});using System;
using System.Windows.Forms;
using WebSocketSharp;
namespace TestWebSocket
{
public class Program
{
[STAThread]
public static void Main(string[] args)
{
using (var ws = new WebSocket("ws://localhost:24892/attach"))
{
ws.OnMessage += (sender, e) =>
{
Console.WriteLine(e.Data);
switch (e.Data)
{
case "READY":
MessageBox.Show("Synapse has attached!");
Environment.Exit(0);
break;
case "ALREADY_ATTACHED":
MessageBox.Show("Synapse is already attached!");
Environment.Exit(0);
break;
case "INTERRUPT":
MessageBox.Show("Synapse has failed to attach!");
Environment.Exit(0);
break;
}
};
ws.Connect();
ws.Send("ATTACH");
Console.ReadKey();
}
}
}
}ws://localhost:24892/custom?channel=CHANNEL_NAME
The custom service allows you to communicate between Synapse X scripts and your own applications. There is no commands or response codes for this service, all communication is handled on your side.
Examples:
const WebSocket = require("ws");
const ws = new WebSocket("ws://localhost:24892/custom?channel=metoothx");
ws.on("open", function open()
{
ws.send("Hello world!");
});
ws.on("message", function incoming(data)
{
console.log(data);
});using System;
namespace TestWebSocket
{
public class Program
{
[STAThread]
public static void Main(string[] args)
{
using (var ws = new WebSocket("ws://localhost:24892/custom?channel=metoothx"))
{
ws.OnMessage += (sender, e) =>
{
Console.WriteLine(e.Data);
};
ws.Connect();
ws.Send("Hello world!");
Console.ReadKey();
}
}
}
}local Socket = syn.open_web_socket("metoothx") --"metoothx" is the channel name
Socket:Connect(function(msg)
* print(msg) --Hello world!
end)
while wait(5) do
* Socket:Send("aaaaaaa") --Will be sent back every 5 seconds
endconst WebSocket = require("ws");
const Alert = require("alert-node");
const ws = new WebSocket("ws://localhost:24892/attach");
const ws2 = new WebSocket("ws://localhost:24892/execute");
ws.on("open", function open()
{
ws.send("ATTACH");
});
ws.on("message", function incoming(data)
{
//This will be called back multiple times during the attaching process
console.log(data);
if (data == "READY")
{
* Alert("Synapse has attached!");
* //You can then execute after attaching completes.
* ws2.send("print'Hello world!'");
}
else if (data == "ALREADY_ATTACHED")
{
* Alert("Synapse is already attached!");
}
else if(data == "INTERRUPT")
{
* Alert("Synapse has failed to attach!");
}
});Enjoy using the WebSocket API! Have fun!
Sources:
| Back | FazBrowse Home | New Git URL |