Преглед изворни кода

Merge branch 'pubnub' of fyindr/siimee into dev

tags/0.0.1^2
maeda пре 3 година
родитељ
комит
6c87f10a18

+ 2
- 2
backend/lib/schemas/health.js Прегледај датотеку

@@ -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 }

+ 10
- 8276
backend/package-lock.json
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 1
- 1
backend/package.json Прегледај датотеку

@@ -43,4 +43,4 @@
43 43
         "nyc": "^15.1.0",
44 44
         "sinon": "^11.1.2"
45 45
     }
46
-}
46
+}

+ 0
- 1
backend/server/index.js Прегледај датотеку

@@ -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 Прегледај датотеку

@@ -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: {

+ 914
- 7794
frontend/package-lock.json
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 31
- 10
frontend/src/components/ProfileCardList.vue Прегледај датотеку

@@ -19,6 +19,7 @@ section.profile-card-list(:style="{'display': 'flex', 'overflow':'auto',}")
19 19
                     h4 {{ profile.name }}
20 20
                     nav.swipe_icons
21 21
                         //- Accept
22
+                        button(@click="chat(profile.pid)") chat
22 23
                         button(@click="accept") Accept
23 24
                         button(@click="view(profile.pid)") view
24 25
                         //- Pass
@@ -26,18 +27,19 @@ section.profile-card-list(:style="{'display': 'flex', 'overflow':'auto',}")
26 27
     
27 28
     .match-layout(
28 29
         v-else
29
-        :key="profile.pid"
30 30
         v-for="(profile, i) in loadedProfiles"
31
+        :key="`${profile.pid}-${i}`"
31 32
     )
32
-            .card.bg-cover(
33
-                :style="{ 'background-image': `url(${profile.avatar})` }"
34
-            )
35
-                .card--content
36
-                    p(style="color: magenta;") profile: {{ profile.pid }}
37
-                    .card--content--lower
38
-                        h4 {{ profile.name }}
39
-                        nav.swipe_icons
40
-                            button(@click="view(profile.pid)") view
33
+        .card.bg-cover(
34
+            :style="{ 'background-image': `url(${profile.avatar})` }"
35
+        )
36
+            .card--content
37
+                p(style="color: magenta;") profile: {{ profile.pid }}
38
+                .card--content--lower
39
+                    h4 {{ profile.name }}
40
+                    nav.swipe_icons
41
+                        button(@click="view(profile.pid)") view
42
+                        button(@click="chat(profile.pid)") chat
41 43
 </template>
42 44
 
43 45
 <script setup>
@@ -46,6 +48,7 @@ import {
46 48
     updateQueueByProfileId,
47 49
     fetchMembershipsByProfileId,
48 50
     postMembershipByProfileId,
51
+    currentProfile,
49 52
 } from '../services'
50 53
 
51 54
 const router = useRouter()
@@ -104,6 +107,24 @@ const accept = async () => {
104 107
 const view = pid => {
105 108
     router.push({ path: `/matches/${pid}` })
106 109
 }
110
+const chat = async pid => {
111
+    // create a chatter reference from the current profile
112
+    const chatter = currentProfile.chatter
113
+    // console.log('mock sender:', pid)
114
+    
115
+    /**  publish a new message to the chatter with the channel and the message
116
+     *  
117
+     *  title is optional
118
+     */
119
+    const res = await chatter.publish(chatter.subscriptions[1], {
120
+        title: 'New Message',
121
+        description: 'This is the start of a chat conversation!',
122
+    })
123
+    // PubNub response will be a timecode of when the message was published
124
+    console.log('res:', res)
125
+
126
+    //router.push({ path: `/chat/${pid}` })
127
+}
107 128
 const pass = () => {
108 129
     const targetId = props.profiles[0].pid
109 130
     updateQueueByProfileId(props.pid, targetId, true)

+ 32
- 25
frontend/src/services/chat.service.js Прегледај датотеку

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

+ 2
- 1
frontend/src/services/login.service.js Прегледај датотеку

@@ -102,7 +102,8 @@ class Login {
102 102
     }
103 103
     setupChatter() {
104 104
         this.chatter = new Chatter()
105
-        const testAccountUUID = import.meta.env.VITE_TEST_ACCOUNT_UUID
105
+        // Use the reactive id object
106
+        const testAccountUUID = this.id.value
106 107
         this.chatter.setup(testAccountUUID)
107 108
     }
108 109
 }

Loading…
Откажи
Сачувај