Skip to content

Commit b1aa55a

Browse files
committed
send feedback event
1 parent ff6450c commit b1aa55a

File tree

10 files changed

+138
-2
lines changed

10 files changed

+138
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ The project contains demo application which connect to https://demo.callstats.io
2929
- [ ] Device Events
3030
- [ ] Special Events
3131
- [x] Application Log
32-
- [ ] Feedback
32+
- [x] Feedback
3333
- [ ] SSRC
3434
- [ ] Callstats Internal Events

app/src/main/java/io/callstats/demo/CallActivity.kt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ package io.callstats.demo
33
import android.os.Bundle
44
import android.provider.Settings
55
import android.support.v4.view.GravityCompat
6+
import android.support.v7.app.AlertDialog
67
import android.support.v7.app.AppCompatActivity
8+
import android.support.v7.view.ContextThemeWrapper
9+
import android.view.LayoutInflater
710
import android.view.WindowManager
811
import android.widget.ArrayAdapter
12+
import android.widget.RatingBar
913
import android.widget.Toast
1014
import io.callstats.demo.csiortc.CsioRTC
1115
import kotlinx.android.synthetic.main.activity_call.*
@@ -52,7 +56,7 @@ class CallActivity : AppCompatActivity(), CsioRTC.Callback {
5256
count_text.text = getString(R.string.call_no_participant, 0)
5357

5458
chat_button.setOnClickListener { drawer_layout.openDrawer(GravityCompat.END) }
55-
hang_button.setOnClickListener { finish() }
59+
hang_button.setOnClickListener { showFeedbackAndHang() }
5660

5761
mic_button.setOnClickListener {
5862
val selected = !it.isSelected
@@ -123,6 +127,25 @@ class CallActivity : AppCompatActivity(), CsioRTC.Callback {
123127
csioRTC.addRemoteVideoRenderer(peerId, remote_video_view)
124128
}
125129

130+
private fun showFeedbackAndHang() {
131+
val view = LayoutInflater.from(this).inflate(R.layout.dialog_feedback, null)
132+
val ratingBar = view.findViewById<RatingBar>(R.id.rating)
133+
ratingBar.setOnRatingBarChangeListener { ratingBar, rating, b ->
134+
if(rating < 1f) ratingBar.rating = 1f
135+
}
136+
AlertDialog.Builder(ContextThemeWrapper(this, R.style.AppTheme_Dialog))
137+
.setView(view)
138+
.setTitle(R.string.feedback_title)
139+
.setPositiveButton(R.string.feedback_submit, { dialogInterface, _ ->
140+
val rating = ratingBar.rating
141+
csioRTC.sendFeedback(rating.toInt())
142+
dialogInterface.dismiss()
143+
})
144+
.setNegativeButton(R.string.feedback_cancel, null)
145+
.setOnDismissListener { finish() }
146+
.show()
147+
}
148+
126149
// CsioRTC callback
127150

128151
override fun onCsioRTCConnect() {}

app/src/main/java/io/callstats/demo/csiortc/CsioRTC.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ class CsioRTC(
210210
peerDataChannels.forEach { _, dataChannel -> dataChannel.send(data) }
211211
}
212212

213+
// Others
214+
215+
/**
216+
* Submit feedback of current call
217+
*/
218+
fun sendFeedback(rating: Int, comment: String? = null) {
219+
callstats.feedback(rating, comment)
220+
}
221+
213222
// Peer connection
214223

215224
private fun createConnection(peerId: String): PeerConnection? {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:gravity="center"
7+
android:orientation="vertical"
8+
android:padding="16dp">
9+
10+
<RatingBar
11+
android:id="@+id/rating"
12+
android:layout_width="wrap_content"
13+
android:layout_height="wrap_content"
14+
android:max="5"
15+
android:rating="5"
16+
android:numStars="5"
17+
android:stepSize="1"/>
18+
19+
</LinearLayout>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@
1111
<string name="call_no_participant">No. of participant : %d</string>
1212
<string name="call_disconnect">Disconnected</string>
1313
<string name="chat_send_message_hint">Send a message</string>
14+
<string name="feedback_title">Meeting Feedback</string>
15+
<string name="feedback_cancel">Cancel</string>
16+
<string name="feedback_submit">Submit</string>
1417
</resources>

app/src/main/res/values/styles.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@
99
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
1010
</style>
1111

12+
<style name="AppTheme.Dialog" parent="Theme.AppCompat.Light.Dialog">
13+
<item name="colorPrimary">@color/primary</item>
14+
<item name="colorAccent">@color/accent</item>
15+
</style>
16+
1217
</resources>

library/src/main/java/io/callstats/Callstats.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import io.callstats.event.user.UserLeftEvent
1010
import io.callstats.event.EventManager
1111
import io.callstats.event.EventManagerImpl
1212
import io.callstats.event.EventSenderImpl
13+
import io.callstats.event.info.Feedback
14+
import io.callstats.event.special.FeedbackEvent
1315
import io.callstats.event.special.LogEvent
1416
import io.callstats.event.stats.SystemStatusStats
1517
import io.callstats.utils.SystemStatus
@@ -134,6 +136,25 @@ class Callstats(
134136
sender.send(LogEvent(level.name.toLowerCase(), message, type.name.toLowerCase()))
135137
}
136138

139+
/**
140+
* Give feedback on this conference call
141+
*/
142+
fun feedback(
143+
rating: Int,
144+
comment: String? = null,
145+
audioQuality: Int? = null,
146+
videoQuality: Int? = null,
147+
remoteUserID: String? = null)
148+
{
149+
val info = Feedback(rating).apply {
150+
comments = comment
151+
audioQualityRating = audioQuality
152+
videoQualityRating = videoQuality
153+
remoteID = remoteUserID
154+
}
155+
sender.send(FeedbackEvent(info))
156+
}
157+
137158
// region Timers
138159

139160
private fun startKeepAlive() {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.callstats.event.info
2+
3+
/**
4+
* Feedback info
5+
*/
6+
data class Feedback(val overallRating: Int) {
7+
8+
/**
9+
* It is provided by the developer.
10+
* Non-empty remoteID means that the feedback was given explicitly about the connection between these two parties.
11+
* Otherwise it is regarded as general conference feedback.
12+
*/
13+
var remoteID: String? = null
14+
15+
/**
16+
* Rating from 1 to 5
17+
*/
18+
var videoQualityRating: Int? = null
19+
20+
/**
21+
* Rating from 1 to 5
22+
*/
23+
var audioQualityRating: Int? = null
24+
25+
/**
26+
* Comments from the participant
27+
*/
28+
var comments: String? = null
29+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.callstats.event.special
2+
3+
import io.callstats.event.SessionEvent
4+
import io.callstats.event.info.Feedback
5+
6+
/**
7+
* You can submit overall rating to conference and add comments as well.
8+
* It is also possible to give separate ratings for audio and video.
9+
*
10+
* @param feedback [Feedback] info
11+
*/
12+
class FeedbackEvent(val feedback: Feedback) : SessionEvent() {
13+
override fun path() = "events/feedback"
14+
}

library/src/test/java/io/callstats/CallstatsTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import io.callstats.event.EventSender
1313
import io.callstats.event.KeepAliveEvent
1414
import io.callstats.event.auth.TokenRequest
1515
import io.callstats.event.fabric.FabricSetupFailedEvent
16+
import io.callstats.event.special.FeedbackEvent
1617
import io.callstats.event.special.LogEvent
1718
import io.callstats.event.stats.SystemStatusStats
1819
import io.callstats.event.user.UserLeftEvent
@@ -152,4 +153,16 @@ class CallstatsTest {
152153
it is LogEvent && it.message == "msg" && it.level == "info" && it.messageType == "text"
153154
})
154155
}
156+
157+
@Test
158+
fun feedbackSendValidEvent() {
159+
callstats.feedback(3, "test", 1, 2, "remote1")
160+
verify(sender).send(argWhere {
161+
it is FeedbackEvent
162+
&& it.feedback.comments == "test"
163+
&& it.feedback.audioQualityRating == 1
164+
&& it.feedback.videoQualityRating == 2
165+
&& it.feedback.remoteID == "remote1"
166+
})
167+
}
155168
}

0 commit comments

Comments
 (0)