Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
84b36a71
Commit
84b36a71
authored
Nov 11, 2014
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
retabed files
parent
dea68f07
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
476 additions
and
474 deletions
+476
-474
httprpc.js
lib/httprpc.js
+53
-54
main.js
lib/main.js
+366
-366
qt.js
lib/qt.js
+17
-16
websocket.js
lib/websocket.js
+40
-38
No files found.
lib/httprpc.js
View file @
84b36a71
...
...
@@ -21,74 +21,73 @@
* @date 2014
*/
if
(
process
.
env
.
NODE_ENV
!==
"build"
)
{
if
(
process
.
env
.
NODE_ENV
!==
"build"
)
{
var
XMLHttpRequest
=
require
(
'xmlhttprequest'
).
XMLHttpRequest
;
// jshint ignore:line
}
var
HttpRpcProvider
=
function
(
host
)
{
this
.
handlers
=
[];
this
.
host
=
host
;
};
var
HttpRpcProvider
=
function
(
host
)
{
this
.
handlers
=
[];
this
.
host
=
host
;
function
formatJsonRpcObject
(
object
)
{
return
{
jsonrpc
:
'2.0'
,
method
:
object
.
call
,
params
:
object
.
args
,
id
:
object
.
_id
};
}
function
formatJsonRpcObject
(
object
)
{
return
{
jsonrpc
:
'2.0'
,
method
:
object
.
call
,
params
:
object
.
args
,
id
:
object
.
_id
};
}
function
formatJsonRpcMessage
(
message
)
{
var
object
=
JSON
.
parse
(
message
);
return
{
_id
:
object
.
id
,
data
:
object
.
result
,
error
:
object
.
error
};
}
HttpRpcProvider
.
prototype
.
sendRequest
=
function
(
payload
,
cb
)
{
var
data
=
formatJsonRpcObject
(
payload
);
function
formatJsonRpcMessage
(
message
)
{
var
object
=
JSON
.
parse
(
message
);
var
request
=
new
XMLHttpRequest
();
request
.
open
(
"POST"
,
this
.
host
,
true
);
request
.
send
(
JSON
.
stringify
(
data
));
request
.
onreadystatechange
=
function
()
{
if
(
request
.
readyState
===
4
&&
cb
)
{
cb
(
request
);
}
};
return
{
_id
:
object
.
id
,
data
:
object
.
result
,
error
:
object
.
error
};
}
HttpRpcProvider
.
prototype
.
send
=
function
(
payload
)
{
var
self
=
this
;
this
.
sendRequest
(
payload
,
function
(
request
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
handler
.
call
(
self
,
formatJsonRpcMessage
(
request
.
responseText
));
});
});
HttpRpcProvider
.
prototype
.
sendRequest
=
function
(
payload
,
cb
)
{
var
data
=
formatJsonRpcObject
(
payload
);
var
request
=
new
XMLHttpRequest
();
request
.
open
(
"POST"
,
this
.
host
,
true
);
request
.
send
(
JSON
.
stringify
(
data
));
request
.
onreadystatechange
=
function
()
{
if
(
request
.
readyState
===
4
&&
cb
)
{
cb
(
request
);
}
};
};
HttpRpcProvider
.
prototype
.
poll
=
function
(
payload
,
id
)
{
var
self
=
this
;
this
.
sendRequest
(
payload
,
function
(
request
)
{
var
parsed
=
JSON
.
parse
(
request
.
responseText
);
if
(
parsed
.
error
||
(
parsed
.
result
instanceof
Array
?
parsed
.
result
.
length
===
0
:
!
parsed
.
result
))
{
return
;
}
self
.
handlers
.
forEach
(
function
(
handler
)
{
handler
.
call
(
self
,
{
_event
:
payload
.
call
,
_id
:
id
,
data
:
parsed
.
result
});
});
HttpRpcProvider
.
prototype
.
send
=
function
(
payload
)
{
var
self
=
this
;
this
.
sendRequest
(
payload
,
function
(
request
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
handler
.
call
(
self
,
formatJsonRpcMessage
(
request
.
responseText
));
});
};
});
};
Object
.
defineProperty
(
HttpRpcProvider
.
prototype
,
"onmessage"
,
{
set
:
function
(
handler
)
{
this
.
handlers
.
push
(
handler
);
HttpRpcProvider
.
prototype
.
poll
=
function
(
payload
,
id
)
{
var
self
=
this
;
this
.
sendRequest
(
payload
,
function
(
request
)
{
var
parsed
=
JSON
.
parse
(
request
.
responseText
);
if
(
parsed
.
error
||
(
parsed
.
result
instanceof
Array
?
parsed
.
result
.
length
===
0
:
!
parsed
.
result
))
{
return
;
}
self
.
handlers
.
forEach
(
function
(
handler
)
{
handler
.
call
(
self
,
{
_event
:
payload
.
call
,
_id
:
id
,
data
:
parsed
.
result
});
});
});
};
Object
.
defineProperty
(
HttpRpcProvider
.
prototype
,
"onmessage"
,
{
set
:
function
(
handler
)
{
this
.
handlers
.
push
(
handler
);
}
});
module
.
exports
=
HttpRpcProvider
;
lib/main.js
View file @
84b36a71
This diff is collapsed.
Click to expand it.
lib/qt.js
View file @
84b36a71
...
...
@@ -16,29 +16,30 @@
*/
/** @file qt.js
* @authors:
* Jeffrey Wilcke <jeff@ethdev.com>
* Marek Kotewicz <marek@ethdev.com>
* @date 2014
*/
var
QtProvider
=
function
()
{
this
.
handlers
=
[];
var
QtProvider
=
function
()
{
this
.
handlers
=
[];
var
self
=
this
;
navigator
.
qt
.
onmessage
=
function
(
message
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
handler
.
call
(
self
,
JSON
.
parse
(
message
.
data
));
});
};
var
self
=
this
;
navigator
.
qt
.
onmessage
=
function
(
message
)
{
self
.
handlers
.
forEach
(
function
(
handler
)
{
handler
.
call
(
self
,
JSON
.
parse
(
message
.
data
));
});
};
};
QtProvider
.
prototype
.
send
=
function
(
payload
)
{
navigator
.
qt
.
postMessage
(
JSON
.
stringify
(
payload
));
};
QtProvider
.
prototype
.
send
=
function
(
payload
)
{
navigator
.
qt
.
postMessage
(
JSON
.
stringify
(
payload
));
};
Object
.
defineProperty
(
QtProvider
.
prototype
,
"onmessage"
,
{
set
:
function
(
handler
)
{
this
.
handlers
.
push
(
handler
);
}
});
Object
.
defineProperty
(
QtProvider
.
prototype
,
"onmessage"
,
{
set
:
function
(
handler
)
{
this
.
handlers
.
push
(
handler
);
}
});
module
.
exports
=
QtProvider
;
lib/websocket.js
View file @
84b36a71
...
...
@@ -16,59 +16,61 @@
*/
/** @file websocket.js
* @authors:
* Jeffrey Wilcke <jeff@ethdev.com>
* Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com>
* @date 2014
*/
if
(
process
.
env
.
NODE_ENV
!==
"build"
)
{
if
(
process
.
env
.
NODE_ENV
!==
"build"
)
{
var
WebSocket
=
require
(
'ws'
);
// jshint ignore:line
}
var
WebSocketProvider
=
function
(
host
)
{
// onmessage handlers
this
.
handlers
=
[];
// queue will be filled with messages if send is invoked before the ws is ready
this
.
queued
=
[];
this
.
ready
=
false
;
var
WebSocketProvider
=
function
(
host
)
{
// onmessage handlers
this
.
handlers
=
[];
// queue will be filled with messages if send is invoked before the ws is ready
this
.
queued
=
[];
this
.
ready
=
false
;
this
.
ws
=
new
WebSocket
(
host
);
this
.
ws
=
new
WebSocket
(
host
);
var
self
=
this
;
this
.
ws
.
onmessage
=
function
(
event
)
{
for
(
var
i
=
0
;
i
<
self
.
handlers
.
length
;
i
++
)
{
self
.
handlers
[
i
].
call
(
self
,
JSON
.
parse
(
event
.
data
),
event
);
}
};
this
.
ws
.
onopen
=
function
()
{
self
.
ready
=
true
;
for
(
var
i
=
0
;
i
<
self
.
queued
.
length
;
i
++
)
{
// Resend
self
.
send
(
self
.
queued
[
i
]);
}
};
var
self
=
this
;
this
.
ws
.
onmessage
=
function
(
event
)
{
for
(
var
i
=
0
;
i
<
self
.
handlers
.
length
;
i
++
)
{
self
.
handlers
[
i
].
call
(
self
,
JSON
.
parse
(
event
.
data
),
event
);
}
};
WebSocketProvider
.
prototype
.
send
=
function
(
payload
)
{
if
(
this
.
ready
)
{
var
data
=
JSON
.
stringify
(
payload
);
this
.
ws
.
send
(
data
);
}
else
{
this
.
queued
.
push
(
payload
);
this
.
ws
.
onopen
=
function
()
{
self
.
ready
=
true
;
for
(
var
i
=
0
;
i
<
self
.
queued
.
length
;
i
++
)
{
// Resend
self
.
send
(
self
.
queued
[
i
]);
}
};
};
WebSocketProvider
.
prototype
.
onMessage
=
function
(
handler
)
{
this
.
handlers
.
push
(
handler
);
}
;
WebSocketProvider
.
prototype
.
send
=
function
(
payload
)
{
if
(
this
.
ready
)
{
var
data
=
JSON
.
stringify
(
payload
)
;
WebSocketProvider
.
prototype
.
unload
=
function
()
{
this
.
ws
.
close
();
};
Object
.
defineProperty
(
WebSocketProvider
.
prototype
,
"onmessage"
,
{
set
:
function
(
provider
)
{
this
.
onMessage
(
provider
);
}
});
this
.
ws
.
send
(
data
);
}
else
{
this
.
queued
.
push
(
payload
);
}
};
WebSocketProvider
.
prototype
.
onMessage
=
function
(
handler
)
{
this
.
handlers
.
push
(
handler
);
};
WebSocketProvider
.
prototype
.
unload
=
function
()
{
this
.
ws
.
close
();
};
Object
.
defineProperty
(
WebSocketProvider
.
prototype
,
"onmessage"
,
{
set
:
function
(
provider
)
{
this
.
onMessage
(
provider
);
}
});
module
.
exports
=
WebSocketProvider
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment