Browse Source

publish trbie config to tribes server

feature/dockerfile-arm
Evan Feenstra 5 years ago
parent
commit
a61f8b6001
  1. 2
      .gitignore
  2. 9
      api/controllers/chats.ts
  3. 2
      api/grpc/index.ts
  4. 18
      api/utils/tribes.ts
  5. 2
      config/app.json

2
.gitignore

@ -1,6 +1,8 @@
notes.md notes.md
todo.md todo.md
sphinx.db
# just for testing # just for testing
binaries/nodeapp-macos binaries/nodeapp-macos
binaries/nodeapp-alpine binaries/nodeapp-alpine

9
api/controllers/chats.ts

@ -44,8 +44,8 @@ async function createGroupChat(req, res) {
name, name,
is_tribe, is_tribe,
is_listed, is_listed,
// price_per_message, price_per_message,
// price_to_join, price_to_join,
} = req.body } = req.body
const contact_ids = req.body.contact_ids||[] const contact_ids = req.body.contact_ids||[]
@ -68,6 +68,11 @@ async function createGroupChat(req, res) {
chatParams = await createTribeChatParams(owner, contact_ids, name) chatParams = await createTribeChatParams(owner, contact_ids, name)
if(is_listed){ if(is_listed){
// publish to tribe server // publish to tribe server
tribes.declare({
...chatParams,
pricePerMessage: price_per_message,
priceToJoin: price_to_join
})
} }
// make me owner when i create // make me owner when i create
members[owner.publicKey].role = constants.chat_roles.owner members[owner.publicKey].role = constants.chat_roles.owner

2
api/grpc/index.ts

@ -16,7 +16,7 @@ function subscribeInvoices(parseKeysendInvoice) {
var call = lightning.subscribeInvoices(); var call = lightning.subscribeInvoices();
call.on('data', async function(response) { call.on('data', async function(response) {
// console.log('subscribed invoices', { response }) console.log('subscribeInvoices response', response)
if (response['state'] !== 'SETTLED') { if (response['state'] !== 'SETTLED') {
return return
} }

18
api/utils/tribes.ts

@ -17,8 +17,8 @@ export async function connect(onMessage) {
async function reconnect(){ async function reconnect(){
client = null client = null
const pwd = await genSignedTimestamp() const pwd = await genSignedTimestamp()
console.log('[tribes] try to connect:',`tls://${config.tribes_host}`) console.log('[tribes] try to connect:',`tls://${config.tribes_host}:8883`)
client = mqtt.connect(`tls://${config.tribes_host}`,{ client = mqtt.connect(`tls://${config.tribes_host}:8883`,{
username:info.identity_pubkey, username:info.identity_pubkey,
password:pwd, password:pwd,
reconnectPeriod:0, // dont auto reconnect reconnectPeriod:0, // dont auto reconnect
@ -52,6 +52,20 @@ export function publish(topic,msg){
if(client) client.publish(topic,msg) if(client) client.publish(topic,msg)
} }
export async function declare({uuid,name,groupKey,host,pricePerMessage,priceToJoin}) {
const r = await fetch('https://' + host + '/tribes', {
method: 'POST' ,
body: JSON.stringify({
uuid,name,groupKey,host,
pricePerMessage:pricePerMessage||0,
priceToJoin:priceToJoin||0
}),
headers: { 'Content-Type': 'application/json' }
})
const j = await r.json()
console.log(j)
}
export async function genSignedTimestamp(){ export async function genSignedTimestamp(){
const now = moment().unix() const now = moment().unix()
const tsBytes = Buffer.from(now.toString(16), 'hex') const tsBytes = Buffer.from(now.toString(16), 'hex')

2
config/app.json

@ -12,7 +12,7 @@
"hub_invite_url": "http://lvh.me/invites", "hub_invite_url": "http://lvh.me/invites",
"hub_check_invite_url": "http://lvh.me/check_invite", "hub_check_invite_url": "http://lvh.me/check_invite",
"media_host": "localhost:5000", "media_host": "localhost:5000",
"tribes_host": "tribes.sphinx.chat:8883" "tribes_host": "tribes.sphinx.chat"
}, },
"production": { "production": {
"senza_url": "https://staging.senza.us/api/v2/", "senza_url": "https://staging.senza.us/api/v2/",

Loading…
Cancel
Save