Sfoglia il codice sorgente

:bug: passing messages to chatter in correct format | altering borked joi import

tags/0.0.1^2
J 3 anni fa
parent
commit
fff83e348c

+ 2
- 2
backend/lib/schemas/health.js Vedi File

@@ -1,10 +1,10 @@
1 1
 'use strict'
2 2
 
3
-const Joi = require('Joi')
3
+const Joi = require('joi')
4 4
 
5 5
 const stats = Joi.object({
6 6
     date: Joi.string().required(),
7 7
     users: Joi.number().required(),
8 8
 }).label('stats')
9 9
 
10
-module.exports = { stats }
10
+module.exports = { stats }

+ 0
- 1
backend/server/index.js Vedi File

@@ -8,7 +8,6 @@ const Manifest = require('./manifest')
8 8
  */
9 9
 exports.deployment = async ({ start } = {}) => {
10 10
     const manifest = Manifest.get('/', process.env)
11
-    console.log(__dirname)
12 11
     const server = await Glue.compose(manifest, { relativeTo: __dirname })
13 12
 
14 13
     if (start) {

+ 1
- 2
backend/server/manifest.js Vedi File

@@ -1,11 +1,10 @@
1
-const Dotenv = require('dotenv').config({path: './server/.env'})
1
+const Dotenv = require('dotenv').config({ path: './server/.env' })
2 2
 const Confidence = require('@hapipal/confidence')
3 3
 const Inert = require('@hapi/inert')
4 4
 const Vision = require('@hapi/vision')
5 5
 const Schwifty = require('@hapipal/schwifty')
6 6
 const HapiSwagger = require('hapi-swagger')
7 7
 
8
-
9 8
 /** Glue manifest as a confidence store */
10 9
 module.exports = new Confidence.Store({
11 10
     server: {

+ 20
- 27
frontend/src/components/ProfileCardList.vue Vedi File

@@ -17,6 +17,7 @@ section.profile-card-list
17 17
                     h4 {{ profile.name }}
18 18
                     nav.swipe_icons
19 19
                         //- Accept
20
+                        button(@click="chat(profile.pid)") chat
20 21
                         button(@click="accept") Accept
21 22
                         button(@click="view(profile.pid)") view
22 23
                         //- Pass
@@ -24,19 +25,19 @@ section.profile-card-list
24 25
     
25 26
     .match-layout(
26 27
         v-else
27
-        :key="profile.pid"
28 28
         v-for="(profile, i) in loadedProfiles"
29
+        :key="`${profile.pid}-${i}`"
29 30
     )
30
-            .card.bg-cover(
31
-                :style="{ 'background-image': `url(${profile.avatar})` }"
32
-            )
33
-                .card--content
34
-                    p(style="color: magenta;") profile: {{ profile.pid }}
35
-                    .card--content--lower
36
-                        h4 {{ profile.name }}
37
-                        nav.swipe_icons
38
-                            button(@click="view(profile.pid)") view
39
-                            button(@click="chat(profile.pid)") chat
31
+        .card.bg-cover(
32
+            :style="{ 'background-image': `url(${profile.avatar})` }"
33
+        )
34
+            .card--content
35
+                p(style="color: magenta;") profile: {{ profile.pid }}
36
+                .card--content--lower
37
+                    h4 {{ profile.name }}
38
+                    nav.swipe_icons
39
+                        button(@click="view(profile.pid)") view
40
+                        button(@click="chat(profile.pid)") chat
40 41
 </template>
41 42
 
42 43
 <script setup>
@@ -104,23 +105,15 @@ const accept = async () => {
104 105
 const view = pid => {
105 106
     router.push({ path: `/matches/${pid}` })
106 107
 }
107
-const chat = pid => {
108
-   
108
+const chat = async pid => {
109 109
     const chatter = currentProfile.chatter
110
-    // chatter._listenFor('hello_world')
111
-    chatter._subscribe(['hello_world'])
112
-    chatter.publish({
113
-    channel: "hello_world",
114
-    message: {"text": "This is my first realtime message!"}
115
-  }).then((publishResponse) => {
116
-    console.log(publishResponse);
117
-    });
118
-    
119
-    
120
-
121
-
122
-
123
-console.log('chatter', chatter.subscriptions)
110
+    console.log('chatter', chatter)
111
+    const res = await chatter.publish(chatter.subscriptions[0], {
112
+        title: 'pong',
113
+        description: 'This is my first realtime message!',
114
+    })
115
+    console.log('chatter', res)
116
+    console.log('chatter', chatter.subscriptions)
124 117
     //router.push({ path: `/chat/${pid}` })
125 118
 }
126 119
 const pass = () => {

+ 25
- 23
frontend/src/services/chat.service.js Vedi File

@@ -1,34 +1,33 @@
1
-import { processExpression } from '@vue/compiler-core'
2 1
 import PubNub from 'pubnub'
3 2
 
4
-/** 
3
+/**
5 4
  * Provider method holder
6 5
  * We always reference this object so
7 6
  * we don't have to hardcode provider specific
8 7
  * methods for doing chat things.
9
- * 
8
+ *
10 9
  * This gets overloaded later in the program
11 10
  */
12 11
 const providerMethods = {
13 12
     publish: () => console.error('no provider publish method set'),
14 13
     subscribe: () => console.error('no provider subscribe method set'),
15
-    listen: () => console.error('no provider listen method set')
14
+    listen: () => console.error('no provider listen method set'),
16 15
 }
17 16
 
18
-/** 
17
+/**
19 18
  * Breaking out as much pubnub specific flavor
20 19
  */
21 20
 const setupPubnub = async uuid => {
22 21
     const publishKey = 'pub-c-73f35484-396f-47ff-b4b6-45bed079fd3b'
23
-    const subscribeKey= 'sub-c-6cb7f5d0-94e2-11ec-b249-a68c05a281ab'
22
+    const subscribeKey = 'sub-c-6cb7f5d0-94e2-11ec-b249-a68c05a281ab'
24 23
     // console.log('publishKey: ' , publishKey)
25
-    if(!uuid) return console.error('no pubnub uuid set')
26
-    
24
+    if (!uuid) return console.error('no pubnub uuid set')
25
+
27 26
     const pubnubClient = await new PubNub({
28 27
         publishKey: publishKey,
29 28
         subscribeKey: subscribeKey,
30 29
         logVerbosity: true,
31
-        uuid
30
+        uuid,
32 31
     })
33 32
     // Pass pubnub specific methods to our placeholder obj
34 33
     providerMethods['publish'] = pubnubClient.publish
@@ -38,19 +37,17 @@ const setupPubnub = async uuid => {
38 37
     return pubnubClient
39 38
 }
40 39
 
41
-
42 40
 class ChatMessage {
43 41
     constructor({ title, description }) {
44
-        this.title = title,
45
-        this.description = description
42
+        ;(this.title = title), (this.description = description)
46 43
     }
47 44
 }
48 45
 
49 46
 const testMessage = new ChatMessage({
50
-    title: "testing",
51
-    description: "hello world!",
47
+    title: 'testing',
48
+    description: 'hello world!',
52 49
 })
53
-const MAIN_CHANNEL = 'hello_world'
50
+const MAIN_CHANNEL = 'Channel-Barcelona'
54 51
 
55 52
 /** Singleton that holds all our chat information */
56 53
 class Chatter {
@@ -72,11 +69,11 @@ class Chatter {
72 69
         this.subscriptions = [MAIN_CHANNEL]
73 70
         this.listeners = {
74 71
             status: async e => {
75
-                if (e.category !== "PNConnectedCategory") return
76 72
                 await this.publish(this.subscriptions[0], testMessage)
73
+                if (e.category !== 'PNConnectedCategory') return
77 74
             },
78 75
             message: this._onMessage,
79
-            presence: this._onPresence
76
+            presence: this._onPresence,
80 77
         }
81 78
     }
82 79
     /**
@@ -84,7 +81,12 @@ class Chatter {
84 81
      * @param {event} e
85 82
      */
86 83
     async _onMessage(e) {
87
-        console.log(`received message: ${e.message.title} - ${e.message.description}`)
84
+        if (e.message) {
85
+            console.log(
86
+                `received message: ${e.message.title} - ${e.message.description}`,
87
+                e,
88
+            )
89
+        }
88 90
     }
89 91
     async _onPresence(e) {
90 92
         return
@@ -107,21 +109,21 @@ class Chatter {
107 109
     async publish(channel, message) {
108 110
         return await providerMethods['publish']({ channel, message })
109 111
     }
110
-    /** 
112
+    /**
111 113
      * Subscribe to a channels
112 114
      * Facade so we can hide provider specific methods
113 115
      * @param {array} channels
114
-    */
116
+     */
115 117
     _subscribe(channels) {
116 118
         providerMethods['subscribe']({ channels })
117 119
     }
118
-    /** 
120
+    /**
119 121
      * Listen to events and set callbacks
120 122
      * Facade so we can hide provider specific methods
121
-    */
123
+     */
122 124
     _listenFor({ listeners }) {
123 125
         providerMethods['listen'](listeners)
124 126
     }
125 127
 }
126 128
 
127
-export { Chatter }
129
+export { Chatter }

Loading…
Annulla
Salva