GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — beet-js/src/index.js at develop · bitshares/beet-js

Expand file tree

/

index.js

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
156 lines (136 loc) · 3.93 KB
/

index.js

Copy path

File metadata and controls

156 lines (136 loc) · 3.93 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import sha256 from "crypto-js/sha256.js";
import BeetConnection from "./lib/BeetConnection.js";
const allowedChains = ["ANY", "BTS", "BNB_TEST", "STEEM", "BTC"];
import { io } from "socket.io-client";
let httpPort = 60555;
let httpsPort = 60554;
/**
* Gets an instance of a beet connected application, and does the identity handling for the requested chain.
*
* @param {String} appName
* @param {String} browser (User browser)
* @param {String} origin (website url)
* @param {String} chain (Target blockchain)
* @param {BeetConnection} existingBeetConnection (Provide stored connection)
* @param {Object} identity
* @returns {BeetConnection}
*/
export const connect = async function (
appName,
browser,
origin,
existingBeetConnection = null,
identity = null
) {
return new Promise(async (resolve, reject) => {
let appHash;
try {
appHash = sha256(browser + ' ' + origin + ' ' + appName).toString();
} catch (error) {
console.log(error);
return;
}
let beetConnection;
try {
beetConnection = existingBeetConnection
? existingBeetConnection // attempt to reconnect
: new BeetConnection(appName, appHash, browser, origin, identity);
} catch (error) {
console.log(error);
return;
}
let ssl;
try {
ssl = await checkBeet(true, httpsPort);
} catch (error) {
console.log(`checkBeet ssl: ${error}`);
}
let http;
try {
http = await checkBeet(false, httpPort);
} catch (error) {
console.log(`checkBeet http: ${error}`);
}
if (!ssl && !http) {
console.log("Beet is offline, launch it then try again.");
return reject("Beet is offline");
}
let authToken;
try {
authToken = await beetConnection.connect(
identity,
ssl ? true : false,
ssl ? httpsPort : httpPort
)
} catch (error) {
console.log(`${ssl ? 'https' : 'http'} connection attempt error: ${error}`);
}
if (!authToken) { // fallback to http
try {
authToken = await beetConnection.connect(identity, false, httpPort)
} catch (error) {
console.log(`http connection attempt error: ${error}`);
}
}
try {
await beetConnection.setAuth(authToken);
} catch (error) {
console.log(error);
return;
}
if (beetConnection.connected) {
console.log(`Connected to Beet`)
}
return resolve(beetConnection);
});
}
/**
* Gets an instance of a beet connected application, and does the identity handling for the requested chain.
*
* @param {String} chain (Target blockchain)
* @param {BeetConnection} beetConnection (Provide stored connection)
* @returns {Object}
*/
export const link = async function (chain = 'ANY', beetConnection) {
if (!chain || !chain in allowedChains) {
console.log("Unable to establish a chain connection without target chain.");
return;
}
if (!beetConnection) {
console.log("No beet connection for link request");
return;
}
let linkage;
try {
linkage = await beetConnection.link(chain);
} catch (error) {
console.log(`Unable to link: ${error}`);
return;
}
}
/**
* Checks for a Beet web socket response
* @param {boolean} enableSSL
* @returns {boolean} Resolves to true (if installed) and false (not installed)
*/
export const checkBeet = async function (enableSSL = true, port = 60554) {
return new Promise((resolve, reject) => {
let socket;
try {
socket = enableSSL
? io(`wss://local.get-beet.io:${port}/`, {transports: ['websocket'], rejectUnauthorized: false})
: io(`ws://localhost:${port}`);
} catch (error) {
console.log(error);
resolve(false);
}
socket.on("connect_error", (error) => {
socket.disconnect();
resolve(false);
});
socket.emit("ping", 'pong');
socket.on("pong", (response) => {
resolve(response);
});
});
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.