Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const https = require('https');
- const WebSocket = require('ws');
- const isJSON = function (str) {
- try {
- const data = JSON.parse(str);
- if(data === null) {
- return false;
- }
- return typeof(data) === "object"? true : false;
- } catch (e) {
- return false;
- }
- };
- const ws = new WebSocket('wss://zentroidz.com/socket/');
- ws.on('open', function open() {
- ws.send(JSON.stringify({hub: "zentroidz-hub"}));
- //super secret line of code here
- ws.send(JSON.stringify({request: "id"}));
- });
- var serverid;
- const createOptions = function (options) {
- if (options.url !== undefined) {
- if (options.url.startsWith("https://")) {
- options.port = 443;
- options.url = options.url.slice(8, Infinity);
- } else {
- options.port = 80;
- }
- if (options.url.startsWith("http://")) {
- options.url = options.url.slice(7, Infinity);
- }
- options.hostname = options.url.split("/")[0];
- options.path = options.url.split("/").slice(1, Infinity).join("/");
- delete options.url;
- } else {
- if (options.port === undefined) {
- options.port = 80;
- }
- if (options.path === undefined) {
- options.path = "/";
- }
- }
- if (options.method === undefined) {
- options.method = "GET";
- }
- return options;
- };
- ws.on('message', function (jsonData) {
- if (isJSON(jsonData)) {
- var data = JSON.parse(jsonData).data;
- var id = JSON.parse(jsonData).id;
- try {
- if (data.id && serverid === undefined) {
- serverid = data.id;
- }
- } catch (e) {}
- if (isJSON(data)) {
- var obj = JSON.parse(data);
- if (obj.request === true && typeof obj.payload === "object") {
- var payload = obj.payload;
- const req = https.request(createOptions(payload), (res) => {
- res.on('data', (data) => {
- // ws.send(JSON.stringify({id: id, message: JSON.stringify({
- // headers: res.headersdata,
- // statusCode: res.statusCode,
- // data: data
- // })}));
- });
- });
- req.end();
- }
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement