Permalink
Browse files

Public key now shows correctly in web ui

  • Loading branch information...
1 parent c2b972c commit 911e13ca435866290c0b476fd362ae6715ba17ff @Detegr committed Feb 28, 2014
Showing with 41 additions and 13 deletions.
  1. +1 −1 core/core.c
  2. +1 −1 core/handlers.c
  3. +7 −1 ui/web/index.html
  4. +32 −10 ui/web/js/tapi2p-backbone.js
View
2 core/core.c
@@ -719,6 +719,7 @@ int core_start(void)
{// Config file created
pipe_event_addlistener(Setup, &handlesetup, NULL);
pipe_event_addlistener(Status, &handlestatus, &setupstatus);
+ pipe_event_addlistener(GetPublicKey, &handlegetpublickey, NULL);
while(run_threads==1)
{
pipe_accept();
@@ -767,7 +768,6 @@ int core_start(void)
pipe_event_addlistener(ListPeers, &handlelistpeers, getconfig());
pipe_event_addlistener(Status, &handlestatus, &setupstatus);
pipe_event_addlistener(FileTransferStatus, &handlefiletransferstatus, NULL);
- pipe_event_addlistener(GetPublicKey, &handlegetpublickey, NULL);
event_addlistener(RequestFileTransfer, &handlefiletransfer, NULL);
event_addlistener(RequestFileTransferLocal, &handlefiletransferlocal, NULL);
event_addlistener(RequestFilePart, &handlefilepartrequest, NULL);
View
2 core/handlers.c
@@ -612,5 +612,5 @@ void handlegetpublickey(pipeevt_t *e, void *data)
fprintf(stderr, "Failed to load private key. Have you set up tapi2p correctly?\n");
return;
}
- pipe_event_send_back_to_caller(e, selfkey.keyastext, strlen(selfkey.keyastext));
+ pipe_event_send_back_to_caller(e, selfkey.keyastext, strnlen(selfkey.keyastext, 800));
}
View
8 ui/web/index.html
@@ -46,9 +46,15 @@
<body>
<script type="text/template" id="tapi2p-main-template">
<div class="header">
- <h1><%= welcome_message %></h1>
+ <h1 id="welcome"><%= welcome_message %></h1>
<h2>Please use the navigation menu to get started</h2>
</div>
+ <form class="pure-form pure-form-stacked" style="margin-top: 1em;">
+ <legend style="margin-top: 1em;">Share this public key with your peers to allow them to communicate with you</legend>
+ <textarea readonly style="width: 100%;" rows="18" id="publickey">
+<%= publicKey %>
+ </textarea>
+ </form>
</script>
<script type="text/template" id="tapi2p-setup-template">
<div class="header">
View
42 ui/web/js/tapi2p-backbone.js
@@ -19,6 +19,9 @@ var ChatModel = Backbone.Model.extend({
}
});
+var KeyModel = Backbone.Model.extend({});
+var keyModel = new KeyModel();
+
var chatModel = new ChatModel();
chatModel.set({chatHistory: []});
@@ -45,13 +48,22 @@ function RenderableTemplate(name) {
var MainView = Backbone.View.extend({
el: $("#tapi2p-main"),
tagName: "div",
- className: null,
- initialize: function(params) {
- this.welcome=params.welcome;
+ model: keyModel,
+ className: "tapi2p-main",
+ initialize: function() {
+ this.model.on("change:welcome", function()
+ {
+ $("#welcome").text(this.model.get("welcome"));
+ }, this);
+ this.model.on("change:publicKey", function()
+ {
+ $("#publickey").text(this.model.get("publicKey"));
+ }, this);
this.render();
},
render: function() {
- var template=_.template($("#" + this.className + "-template").html(), {welcome_message: this.welcome});
+ var template=_.template($("#" + this.className + "-template").html(), {welcome_message: this.model.get("welcome"), publicKey: this.model.get("publicKey")});
+ console.log(template);
this.$el.html(template);
}
});
@@ -83,7 +95,7 @@ var ChatView = Backbone.View.extend({
render: function() {
if(!this.$el.is(":visible")) return this;
- var template=_.template($("#" + this.className + "-template").html(), {welcome_message: this.welcome, chatHistory: this.model.get("chatHistory")});
+ var template=_.template($("#" + this.className + "-template").html(), {welcome_message: keyModel.get("welcome"), chatHistory: this.model.get("chatHistory")});
this.$el.html(template);
}
});
@@ -141,7 +153,12 @@ var SetupView = Backbone.View.extend({
el: $("#tapi2p-main"),
tagName: "div",
className: "tapi2p-setup",
+ model: keyModel,
initialize: function() {
+ this.model.on("change:publicKey", function()
+ {
+ $("#publickey").text(this.model.get("publicKey"));
+ }, this);
this.render();
},
render: function() {
@@ -185,6 +202,7 @@ var Router = Backbone.Router.extend({
var r=new Router();
r
+.on("route:root", render(MainView))
.on("route:chat", render(ChatView))
.on("route:peers", render(PeerView))
.on("route:newpeer", render(NewPeerView))
@@ -216,9 +234,16 @@ function tapi2p_handle_message(e)
var d=JSON.parse(e.data);
switch(d.cmd)
{
+ case backend.Commands.GetPublicKey:
+ {
+ console.log("PUBKEY");
+ keyModel.set({publicKey: d.data});
+ break;
+ }
case backend.Commands.PeerConnected:
{
peermap[d.peers.addr] = d.peers.nick;
+ break;
}
case backend.Commands.PeerDisconnected:
{
@@ -237,11 +262,7 @@ function tapi2p_handle_message(e)
peermap.localhost={};
peermap.localhost.nick = d.own_nick;
d.data += d.own_nick;
- r.on("route:root", function() {
- new MainView({className: "tapi2p-main", welcome: d.data});
- });
- r.navigate("", {trigger: true, replace: true});
- Backbone.history.loadUrl();
+ keyModel.set({welcome: d.data});
break;
}
var nick=peermap[d.addr];
@@ -261,6 +282,7 @@ function tapi2p_handle_message(e)
}
case backend.Commands.Status:
{
+ backend.sendCommand(backend.Commands.GetPublicKey);
if(d.data.status)
{
backend.sendCommand(backend.Commands.Hello);

0 comments on commit 911e13c

Please sign in to comment.