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

Merge branch 'pubnub' of fyindr/siimee into dev

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

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

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 }

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


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

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

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

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

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

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


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

19
                     h4 {{ profile.name }}
19
                     h4 {{ profile.name }}
20
                     nav.swipe_icons
20
                     nav.swipe_icons
21
                         //- Accept
21
                         //- Accept
22
+                        button(@click="chat(profile.pid)") chat
22
                         button(@click="accept") Accept
23
                         button(@click="accept") Accept
23
                         button(@click="view(profile.pid)") view
24
                         button(@click="view(profile.pid)") view
24
                         //- Pass
25
                         //- Pass
26
     
27
     
27
     .match-layout(
28
     .match-layout(
28
         v-else
29
         v-else
29
-        :key="profile.pid"
30
         v-for="(profile, i) in loadedProfiles"
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
 </template>
43
 </template>
42
 
44
 
43
 <script setup>
45
 <script setup>
46
     updateQueueByProfileId,
48
     updateQueueByProfileId,
47
     fetchMembershipsByProfileId,
49
     fetchMembershipsByProfileId,
48
     postMembershipByProfileId,
50
     postMembershipByProfileId,
51
+    currentProfile,
49
 } from '../services'
52
 } from '../services'
50
 
53
 
51
 const router = useRouter()
54
 const router = useRouter()
104
 const view = pid => {
107
 const view = pid => {
105
     router.push({ path: `/matches/${pid}` })
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
 const pass = () => {
128
 const pass = () => {
108
     const targetId = props.profiles[0].pid
129
     const targetId = props.profiles[0].pid
109
     updateQueueByProfileId(props.pid, targetId, true)
130
     updateQueueByProfileId(props.pid, targetId, true)

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

1
 import PubNub from 'pubnub'
1
 import PubNub from 'pubnub'
2
 
2
 
3
-/** 
3
+/**
4
  * Provider method holder
4
  * Provider method holder
5
  * We always reference this object so
5
  * We always reference this object so
6
  * we don't have to hardcode provider specific
6
  * we don't have to hardcode provider specific
7
  * methods for doing chat things.
7
  * methods for doing chat things.
8
- * 
8
+ *
9
  * This gets overloaded later in the program
9
  * This gets overloaded later in the program
10
  */
10
  */
11
 const providerMethods = {
11
 const providerMethods = {
12
     publish: () => console.error('no provider publish method set'),
12
     publish: () => console.error('no provider publish method set'),
13
     subscribe: () => console.error('no provider subscribe method set'),
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
  * Breaking out as much pubnub specific flavor
18
  * Breaking out as much pubnub specific flavor
19
  */
19
  */
20
 const setupPubnub = async uuid => {
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
     const pubnubClient = await new PubNub({
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
     // Pass pubnub specific methods to our placeholder obj
32
     // Pass pubnub specific methods to our placeholder obj
29
     providerMethods['publish'] = pubnubClient.publish
33
     providerMethods['publish'] = pubnubClient.publish
33
     return pubnubClient
37
     return pubnubClient
34
 }
38
 }
35
 
39
 
36
-
37
 class ChatMessage {
40
 class ChatMessage {
38
     constructor({ title, description }) {
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
 const testMessage = new ChatMessage({
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
 /** Singleton that holds all our chat information */
52
 /** Singleton that holds all our chat information */
51
 class Chatter {
53
 class Chatter {
64
         this.uuid = null
66
         this.uuid = null
65
 
67
 
66
         // Setup the main channel
68
         // Setup the main channel
67
-        this.subscriptions = [MAIN_CHANNEL]
69
+        this.subscriptions = [MAIN_CHANNEL, 'Channel-LosAngeles']
68
         this.listeners = {
70
         this.listeners = {
69
             status: async e => {
71
             status: async e => {
70
-                if (e.category !== "PNConnectedCategory") return
71
                 await this.publish(this.subscriptions[0], testMessage)
72
                 await this.publish(this.subscriptions[0], testMessage)
73
+                if (e.category !== 'PNConnectedCategory') return
72
             },
74
             },
73
             message: this._onMessage,
75
             message: this._onMessage,
74
-            presence: this._onPresence
76
+            presence: this._onPresence,
75
         }
77
         }
76
     }
78
     }
77
     /**
79
     /**
79
      * @param {event} e
81
      * @param {event} e
80
      */
82
      */
81
     async _onMessage(e) {
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
     async _onPresence(e) {
91
     async _onPresence(e) {
85
         return
92
         return
86
     }
93
     }
87
     async setup(uuid) {
94
     async setup(uuid) {
88
-        this.uuid = uuid
95
+        this.uuid = `${uuid}`
89
         this.provider = await setupPubnub(this.uuid)
96
         this.provider = await setupPubnub(this.uuid)
90
 
97
 
91
         this._listenFor({ listeners: this.listeners })
98
         this._listenFor({ listeners: this.listeners })
102
     async publish(channel, message) {
109
     async publish(channel, message) {
103
         return await providerMethods['publish']({ channel, message })
110
         return await providerMethods['publish']({ channel, message })
104
     }
111
     }
105
-    /** 
112
+    /**
106
      * Subscribe to a channels
113
      * Subscribe to a channels
107
      * Facade so we can hide provider specific methods
114
      * Facade so we can hide provider specific methods
108
      * @param {array} channels
115
      * @param {array} channels
109
-    */
116
+     */
110
     _subscribe(channels) {
117
     _subscribe(channels) {
111
         providerMethods['subscribe']({ channels })
118
         providerMethods['subscribe']({ channels })
112
     }
119
     }
113
-    /** 
120
+    /**
114
      * Listen to events and set callbacks
121
      * Listen to events and set callbacks
115
      * Facade so we can hide provider specific methods
122
      * Facade so we can hide provider specific methods
116
-    */
123
+     */
117
     _listenFor({ listeners }) {
124
     _listenFor({ listeners }) {
118
         providerMethods['listen'](listeners)
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
     }
102
     }
103
     setupChatter() {
103
     setupChatter() {
104
         this.chatter = new Chatter()
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
         this.chatter.setup(testAccountUUID)
107
         this.chatter.setup(testAccountUUID)
107
     }
108
     }
108
 }
109
 }

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