Bladeren bron

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

tags/0.0.1^2
J 3 jaren geleden
bovenliggende
commit
fff83e348c

+ 2
- 2
backend/lib/schemas/health.js Bestand weergeven

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

+ 0
- 1
backend/server/index.js Bestand weergeven

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

+ 1
- 2
backend/server/manifest.js Bestand weergeven

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

+ 20
- 27
frontend/src/components/ProfileCardList.vue Bestand weergeven

17
                     h4 {{ profile.name }}
17
                     h4 {{ profile.name }}
18
                     nav.swipe_icons
18
                     nav.swipe_icons
19
                         //- Accept
19
                         //- Accept
20
+                        button(@click="chat(profile.pid)") chat
20
                         button(@click="accept") Accept
21
                         button(@click="accept") Accept
21
                         button(@click="view(profile.pid)") view
22
                         button(@click="view(profile.pid)") view
22
                         //- Pass
23
                         //- Pass
24
     
25
     
25
     .match-layout(
26
     .match-layout(
26
         v-else
27
         v-else
27
-        :key="profile.pid"
28
         v-for="(profile, i) in loadedProfiles"
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
 </template>
41
 </template>
41
 
42
 
42
 <script setup>
43
 <script setup>
104
 const view = pid => {
105
 const view = pid => {
105
     router.push({ path: `/matches/${pid}` })
106
     router.push({ path: `/matches/${pid}` })
106
 }
107
 }
107
-const chat = pid => {
108
-   
108
+const chat = async pid => {
109
     const chatter = currentProfile.chatter
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
     //router.push({ path: `/chat/${pid}` })
117
     //router.push({ path: `/chat/${pid}` })
125
 }
118
 }
126
 const pass = () => {
119
 const pass = () => {

+ 25
- 23
frontend/src/services/chat.service.js Bestand weergeven

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

Laden…
Annuleren
Opslaan