Demo App
An app demonstrating consumption of Huddle01 Android SDK

Initialization

Application.java
1
public class Application extends android.app.Application {
2
@Override
3
public void onCreate() {
4
super.onCreate();
5
HuddleClient.initApp(this);
6
}
7
}
Copied!

UI

Java

MeView.java
PeerView.java
PeerAdapter.java
BindingAdapter.java
1
public class MeView extends RelativeLayout {
2
3
public MeView(@NonNull Context context) {
4
super(context);
5
init(context);
6
}
7
8
public MeView(@NonNull Context context, @Nullable AttributeSet attrs) {
9
super(context, attrs);
10
init(context);
11
}
12
13
public MeView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
14
super(context, attrs, defStyleAttr);
15
init(context);
16
}
17
18
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
19
public MeView(
20
@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
21
super(context, attrs, defStyleAttr, defStyleRes);
22
init(context);
23
}
24
25
com.rohg007.android.huddle01_android_sdk.databinding.ViewMeBindingImpl mBinding;
26
27
private void init(Context context) {
28
mBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.view_me, this, true);
29
mBinding.peerView.videoRenderer.init(PeerConnectionUtils.getEglContext(), null);
30
}
31
32
public void setProps(MeProps props, final HuddleClient huddleClient) {
33
34
// set view model.
35
mBinding.peerView.setPeerViewProps(props);
36
37
// register click listener.
38
mBinding.peerView.info.setOnClickListener(
39
view -> {
40
Boolean showInfo = props.getShowInfo().get();
41
props.getShowInfo().set(showInfo != null && showInfo ? Boolean.FALSE : Boolean.TRUE);
42
});
43
44
mBinding.peerView.meDisplayName.setOnEditorActionListener(
45
(textView, actionId, keyEvent) -> {
46
if (actionId == EditorInfo.IME_ACTION_DONE) {
47
huddleClient.changeDisplayName(textView.getText().toString().trim());
48
return true;
49
}
50
return false;
51
});
52
53
mBinding.peerView.videoRenderer.setZOrderMediaOverlay(true);
54
55
// set view model.
56
mBinding.setMeProps(props);
57
58
// register click listener.
59
mBinding.mic.setOnClickListener(
60
view -> {
61
if (MeProps.DeviceState.ON.equals(props.getMicState().get())) {
62
huddleClient.muteMic();
63
} else {
64
huddleClient.unmuteMic();
65
}
66
});
67
mBinding.cam.setOnClickListener(
68
view -> {
69
if (MeProps.DeviceState.ON.equals(props.getCamState().get())) {
70
huddleClient.disableCam();
71
} else {
72
huddleClient.enableCam();
73
}
74
});
75
mBinding.changeCam.setOnClickListener(view -> huddleClient.changeCam());
76
}
77
}
Copied!
1
public class PeerView extends RelativeLayout {
2
3
public PeerView(@NonNull Context context) {
4
super(context);
5
init(context);
6
}
7
8
public PeerView(@NonNull Context context, @Nullable AttributeSet attrs) {
9
super(context, attrs);
10
init(context);
11
}
12
13
public PeerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
14
super(context, attrs, defStyleAttr);
15
init(context);
16
}
17
18
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
19
public PeerView(
20
@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
21
super(context, attrs, defStyleAttr, defStyleRes);
22
init(context);
23
}
24
25
com.rohg007.android.huddle01_android_sdk.databinding.ViewPeerBinding mBinding;
26
27
private void init(Context context) {
28
mBinding =
29
DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.view_peer, this, true);
30
mBinding.peerView.videoRenderer.init(PeerConnectionUtils.getEglContext(), null);
31
}
32
33
public void setProps(PeerProps props) {
34
// set view model into included layout
35
mBinding.peerView.setPeerViewProps(props);
36
37
// register click listener.
38
mBinding.peerView.info.setOnClickListener(
39
view -> {
40
Boolean showInfo = props.getShowInfo().get();
41
props.getShowInfo().set(showInfo != null && showInfo ? Boolean.FALSE : Boolean.TRUE);
42
});
43
44
// set view model
45
mBinding.setPeerProps(props);
46
}
47
}
48
Copied!
1
public class PeerAdapter extends RecyclerView.Adapter<PeerAdapter.PeerViewHolder> {
2
3
private static final String TAG = "PeerAdapter";
4
5
@NonNull private StateStore mStore;
6
@NonNull private LifecycleOwner mLifecycleOwner;
7
8
private List<Peer> mPeers = new LinkedList<>();
9
10
private int containerHeight;
11
12
public PeerAdapter(
13
@NonNull StateStore store,
14
@NonNull LifecycleOwner lifecycleOwner) {
15
mStore = store;
16
mLifecycleOwner = lifecycleOwner;
17
}
18
19
public void replacePeers(@NonNull List<Peer> peers) {
20
mPeers = peers;
21
notifyDataSetChanged();
22
}
23
24
@NonNull
25
@Override
26
public PeerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
27
containerHeight = parent.getHeight();
28
Context context = parent.getContext();
29
View view = LayoutInflater.from(context).inflate(R.layout.item_remote_peer, parent, false);
30
return new PeerViewHolder(
31
view, new PeerProps(((AppCompatActivity) context).getApplication(), mStore));
32
}
33
34
@Override
35
public void onBindViewHolder(@NonNull PeerViewHolder holder, int position) {
36
// update height
37
ViewGroup.LayoutParams layoutParams = holder.mPeerView.getLayoutParams();
38
layoutParams.height = getItemHeight();
39
holder.mPeerView.setLayoutParams(layoutParams);
40
// bind
41
holder.bind(mLifecycleOwner, mPeers.get(position));
42
}
43
44
@Override
45
public int getItemCount() {
46
return mPeers.size();
47
}
48
49
private int getItemHeight() {
50
int itemCount = getItemCount();
51
if (itemCount <= 1) {
52
return containerHeight;
53
} else if (itemCount <= 3) {
54
return containerHeight / itemCount;
55
} else {
56
return (int) (containerHeight / 3.2);
57
}
58
}
59
60
static class PeerViewHolder extends RecyclerView.ViewHolder {
61
62
@NonNull
63
final PeerView mPeerView;
64
@NonNull final PeerProps mPeerProps;
65
66
PeerViewHolder(@NonNull View view, @NonNull PeerProps peerProps) {
67
super(view);
68
mPeerView = view.findViewById(R.id.remote_peer);
69
mPeerProps = peerProps;
70
}
71
72
void bind(LifecycleOwner owner, @NonNull Peer peer) {
73
mPeerProps.connect(owner, peer.getId());
74
mPeerView.setProps(mPeerProps);
75
}
76
}
77
}
Copied!
1
public class BindingAdapters {
2
3
private static final String TAG = "BindingAdapters";
4
5
@BindingAdapter({"bind:edias_state", "bind:edias_state_animation"})
6
public static void roomState(
7
ImageView view, ConnectionState state, Animation animation) {
8
if (state == null) {
9
return;
10
}
11
if (ConnectionState.CONNECTING.equals(state)) {
12
view.setImageResource(R.drawable.ic_state_connecting);
13
view.startAnimation(animation);
14
} else if (ConnectionState.CONNECTED.equals(state)) {
15
view.setImageResource(R.drawable.ic_state_connected);
16
animation.cancel();
17
view.clearAnimation();
18
} else {
19
view.setImageResource(R.drawable.ic_state_new_close);
20
animation.cancel();
21
view.clearAnimation();
22
}
23
}
24
25
@BindingAdapter({"bind:edias_link"})
26
public static void inviteLink(TextView view, String inviteLink) {
27
view.setVisibility(TextUtils.isEmpty(inviteLink) ? View.INVISIBLE : View.VISIBLE);
28
}
29
30
@SuppressLint("SetTextI18n")
31
@BindingAdapter({"bind:edias_device"})
32
public static void deviceInfo(TextView view, DeviceInfo deviceInfo) {
33
if (deviceInfo == null) {
34
return;
35
}
36
37
int deviceIcon = R.drawable.ic_unknown;
38
if (!TextUtils.isEmpty(deviceInfo.getFlag())) {
39
switch (deviceInfo.getFlag().toLowerCase()) {
40
case "chrome":
41
deviceIcon = R.mipmap.chrome;
42
break;
43
case "firefox":
44
deviceIcon = R.mipmap.firefox;
45
break;
46
case "safari":
47
deviceIcon = R.mipmap.safari;
48
break;
49
case "opera":
50
deviceIcon = R.mipmap.opera;
51
break;
52
case "edge":
53
deviceIcon = R.mipmap.edge;
54
break;
55
case "android":
56
deviceIcon = R.mipmap.android;
57
break;
58
}
59
view.setText(deviceInfo.getName() + " " + deviceInfo.getVersion());
60
} else {
61
view.setText("");
62
}
63
view.setCompoundDrawablesWithIntrinsicBounds(deviceIcon, 0, 0, 0);
64
}
65
66
@BindingAdapter({"edias_mic_state"})
67
public static void deviceMicState(ImageView imageView, MeProps.DeviceState state) {
68
if (state == null) {
69
return;
70
}
71
if (MeProps.DeviceState.ON.equals(state)) {
72
imageView.setBackgroundResource(R.drawable.bg_media_box_on);
73
} else {
74
imageView.setBackgroundResource(R.drawable.bg_media_box_off);
75
}
76
77
switch (state) {
78
case ON:
79
imageView.setImageResource(R.drawable.icon_mic_black_on);
80
break;
81
case OFF:
82
imageView.setImageResource(R.drawable.icon_mic_white_off);
83
break;
84
case UNSUPPORTED:
85
imageView.setImageResource(R.drawable.icon_mic_white_unsupported);
86
break;
87
}
88
}
89
90
@BindingAdapter({"edias_cam_state"})
91
public static void deviceCamState(ImageView imageView, MeProps.DeviceState state) {
92
if (state == null) {
93
return;
94
}
95
if (MeProps.DeviceState.ON.equals(state)) {
96
imageView.setBackgroundResource(R.drawable.bg_media_box_on);
97
} else {
98
imageView.setBackgroundResource(R.drawable.bg_media_box_off);
99
}
100
101
switch (state) {
102
case ON:
103
imageView.setImageResource(R.drawable.icon_webcam_black_on);
104
break;
105
case OFF:
106
imageView.setImageResource(R.drawable.icon_webcam_white_off);
107
break;
108
case UNSUPPORTED:
109
imageView.setImageResource(R.drawable.icon_webcam_white_unsupported);
110
break;
111
}
112
}
113
114
@BindingAdapter({"edias_change_came_state"})
115
public static void changeCamState(View view, MeProps.DeviceState state) {
116
if (state == null) {
117
return;
118
}
119
view.setEnabled(MeProps.DeviceState.ON.equals(state));
120
}
121
122
@BindingAdapter({"edias_share_state"})
123
public static void shareState(View view, MeProps.DeviceState state) {
124
if (state == null) {
125
return;
126
}
127
view.setEnabled(MeProps.DeviceState.ON.equals(state));
128
}
129
130
@BindingAdapter({"edias_render"})
131
public static void render(SurfaceViewRenderer renderer, VideoTrack track) {
132
if (track != null) {
133
track.addSink(renderer);
134
renderer.setVisibility(View.VISIBLE);
135
} else {
136
renderer.setVisibility(View.GONE);
137
}
138
}
139
140
@BindingAdapter({"edias_render_empty"})
141
public static void renderEmpty(View renderer, VideoTrack track) {
142
if (track == null) {
143
renderer.setVisibility(View.VISIBLE);
144
} else {
145
renderer.setVisibility(View.GONE);
146
}
147
}
148
}
Copied!

XML

activity_room.xml
view_me.xml
view_peer.xml
item_remote_peer.xml
view_peer_view.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<layout xmlns:android="http://schemas.android.com/apk/res/android"
3
xmlns:bind="http://schemas.android.com/apk/res-auto"
4
xmlns:tools="http://schemas.android.com/tools">
5
6
<RelativeLayout
7
android:layout_width="match_parent"
8
android:layout_height="match_parent"
9
android:background="@drawable/onboarding_"
10
android:orientation="vertical"
11
tools:context=".RoomActivity">
12
13
<EditText
14
android:id="@+id/chat_input"
15
android:layout_width="match_parent"
16
android:layout_height="wrap_content"
17
android:layout_alignParentBottom="true"
18
android:layout_marginLeft="10dp"
19
android:layout_marginBottom="10dp"
20
android:imeOptions="actionDone"
21
android:singleLine="true" />
22
23
<ImageView
24
android:id="@+id/room_state"
25
android:layout_width="wrap_content"
26
android:layout_height="wrap_content"
27
android:layout_marginStart="10dp"
28
android:layout_marginTop="5dp"
29
android:padding="5dp"
30
android:src="@drawable/ic_state_new_close"
31
bind:edias_state="@{roomProps.connectionState}"
32
bind:edias_state_animation="@{roomProps.getConnectingAnimation}" />
33
34
<TextView
35
android:id="@+id/version"
36
android:layout_width="wrap_content"
37
android:layout_height="wrap_content"
38
android:layout_alignParentRight="true"
39
android:layout_marginTop="5dp"
40
android:layout_marginEnd="10dp"
41
android:padding="5dp"
42
android:textColor="@color/text_color" />
43
44
45
<TextView
46
android:id="@+id/invitation_link"
47
android:layout_width="wrap_content"
48
android:layout_height="wrap_content"
49
android:layout_centerHorizontal="true"
50
android:background="@drawable/bg_area"
51
android:paddingLeft="15dp"
52
android:paddingTop="8dp"
53
android:paddingRight="15dp"
54
android:paddingBottom="8dp"
55
android:text="@string/invitation_link"
56
android:textColor="@color/text_color"
57
android:textSize="15sp"
58
bind:edias_link="@{roomProps.invitationLink}" />
59
60
<androidx.recyclerview.widget.RecyclerView
61
android:id="@+id/remote_peers"
62
android:layout_width="match_parent"
63
android:layout_height="match_parent"
64
android:visibility="gone" />
65
66
<com.leinardi.android.speeddial.SpeedDialView
67
android:id="@+id/reaction_fab"
68
android:layout_width="wrap_content"
69
android:layout_height="wrap_content"
70
android:layout_above="@id/chat_input"
71
android:layout_alignParentEnd="true"
72
bind:sdMainFabClosedSrc="@drawable/ic_baseline_tag_faces_24" />
73
74
<com.rohg007.android.huddle01_android_sdk.views.MeView
75
android:id="@+id/me"
76
android:layout_width="220dp"
77
android:layout_height="200dp"
78
android:layout_alignParentBottom="true"
79
android:layout_marginLeft="10dp"
80
android:layout_marginBottom="60dp" />
81
82
</RelativeLayout>
83
84
<data>
85
86
<variable
87
name="roomProps"
88
type="com.rohg007.android.huddle01_android_sdk.viewmodels.RoomProps" />
89
</data>
90
91
</layout>
Copied!
1
<?xml version="1.0" encoding="utf-8"?>
2
<layout xmlns:android="http://schemas.android.com/apk/res/android"
3
xmlns:bind="http://schemas.android.com/apk/res-auto">
4
5
<data>
6
7
<import type="android.view.View" />
8
9
<variable
10
name="meProps"
11
type="com.rohg007.android.huddle01_android_sdk.viewmodels.MeProps" />
12
13
</data>
14
15
<androidx.cardview.widget.CardView
16
android:layout_width="match_parent"
17
android:layout_height="match_parent"
18
bind:cardBackgroundColor="@color/peer_bg_color"
19
bind:cardCornerRadius="16dp"
20
bind:cardUseCompatPadding="true">
21
22
<include
23
android:id="@+id/peer_view"
24
layout="@layout/view_peer_view"
25
android:layout_width="match_parent"
26
android:layout_height="match_parent"
27
bind:peerViewProps="@{meProps}" />
28
29
<LinearLayout
30
android:id="@+id/controls"
31
android:layout_width="wrap_content"
32
android:layout_height="wrap_content"
33
android:layout_gravity="right"
34
android:gravity="center_vertical"
35
android:padding="5dp"
36
android:visibility="@{meProps.connected ? View.VISIBLE : View.GONE}">
37
38
<ImageView
39
android:id="@+id/mic"
40
android:layout_width="wrap_content"
41
android:layout_height="wrap_content"
42
android:layout_marginEnd="2dp"
43
android:background="@drawable/bg_media_box"
44
android:padding="5dp"
45
android:src="@drawable/icon_mic"
46
bind:edias_mic_state="@{meProps.micState}" />
47
48
<ImageView
49
android:id="@+id/cam"
50
android:layout_width="wrap_content"
51
android:layout_height="wrap_content"
52
android:layout_marginEnd="2dp"
53
android:background="@drawable/bg_media_box"
54
android:clickable="@{!(meProps.me.camInProgress || meProps.me.shareInProgress)}"
55
android:padding="5dp"
56
android:src="@drawable/icon_webcam"
57
bind:edias_cam_state="@{meProps.camState}" />
58
59
<ImageView
60
android:id="@+id/change_cam"
61
android:layout_width="wrap_content"
62
android:layout_height="wrap_content"
63
android:layout_marginEnd="2dp"
64
android:background="@drawable/bg_media_box"
65
android:clickable="@{!(meProps.me.camInProgress || meProps.me.shareInProgress)}"
66
android:padding="5dp"
67
android:src="@drawable/icon_change_cam"
68
bind:edias_change_came_state="@{meProps.camState}" />
69
70
</LinearLayout>
71
72
</androidx.cardview.widget.CardView>
73
</layout>
74
Copied!
1
<?xml version="1.0" encoding="utf-8"?>
2
<layout xmlns:android="http://schemas.android.com/apk/res/android"
3
xmlns:bind="http://schemas.android.com/apk/res-auto">
4
5
<data>
6
7
<import type="android.view.View" />
8
9
<variable
10
name="peerProps"
11
type="com.rohg007.android.huddle01_android_sdk.viewmodels.PeerProps" />
12
</data>
13
14
<androidx.cardview.widget.CardView
15
android:layout_width="match_parent"
16
android:layout_height="match_parent"
17
bind:cardBackgroundColor="@color/peer_bg_color"
18
bind:cardCornerRadius="16dp"
19
bind:cardElevation="5dp"
20
bind:cardUseCompatPadding="true">
21
22
23
<include
24
android:id="@+id/peer_view"
25
layout="@layout/view_peer_view"
26
android:layout_width="match_parent"
27
android:layout_height="match_parent"
28
bind:peerViewProps="@{peerProps}" />
29
30
<LinearLayout
31
android:layout_width="wrap_content"
32
android:layout_height="wrap_content"
33
android:layout_gravity="right"
34
android:padding="5dp">
35
36
<ImageView
37
android:id="@+id/mic_off"
38
android:layout_width="wrap_content"
39
android:layout_height="wrap_content"
40
android:layout_margin="4dp"
41
android:layout_marginEnd="5dp"
42
android:clickable="false"
43
android:src="@drawable/ic_microphone_slash"
44
android:visibility="@{!peerProps.audioEnabled ? View.VISIBLE : View.GONE}" />
45
46
<ImageView
47
android:id="@+id/cam_off"
48
android:layout_width="wrap_content"
49
android:layout_height="wrap_content"
50
android:layout_margin="4dp"
51
android:clickable="false"
52
android:src="@drawable/ic_videocamera_slash"
53
android:visibility="@{!peerProps.videoVisible ? View.VISIBLE : View.GONE}" />
54
55
</LinearLayout>
56
57
</androidx.cardview.widget.CardView>
58
</layout>
Copied!
1
<?xml version="1.0" encoding="utf-8"?>
2
3
<com.rohg007.android.huddle01_android_sdk.views.PeerView
4
xmlns:android="http://schemas.android.com/apk/res/android"
5
android:id="@+id/remote_peer"
6
android:layout_width="match_parent"
7
android:layout_height="match_parent" />
Copied!
1
<?xml version="1.0" encoding="utf-8"?>
2
<layout xmlns:android="http://schemas.android.com/apk/res/android"
3
xmlns:bind="http://schemas.android.com/apk/res-auto">
4
5
<data>
6
7
<import type="androidx.core.util.Consumer" />
8
9
<import type="android.text.TextUtils" />
10
11
<import type="android.view.View" />
12
13
<variable
14
name="peerViewProps"
15
type="com.rohg007.android.huddle01_android_sdk.viewmodels.PeerViewProps" />
16
</data>
17
18
<FrameLayout
19
android:background="@color/peer_bg_color"
20
android:layout_width="match_parent"
21
android:layout_height="match_parent">
22
23
<org.webrtc.SurfaceViewRenderer
24
android:id="@+id/video_renderer"
25
android:layout_width="wrap_content"
26
android:layout_height="wrap_content"
27
android:layout_gravity="center"
28
android:visibility="gone"
29
bind:edias_render="@{peerViewProps.videoTrack}" />
30
31
<LinearLayout
32
android:id="@+id/video_hidden"
33
android:layout_width="match_parent"
34
android:layout_height="match_parent"
35
android:orientation="vertical"
36
bind:edias_render_empty="@{peerViewProps.videoTrack}">
37
38
<View
39
android:layout_width="match_parent"
40
android:layout_height="0dp"
41
android:layout_weight="1" />
42
43
<ImageView
44
android:layout_width="match_parent"
45
android:layout_height="0dp"
46
android:layout_weight="5"
47
android:scaleType="fitCenter"
48
android:src="@drawable/buddy" />
49
</LinearLayout>
50
51
<LinearLayout
52
android:id="@+id/peer"
53
android:layout_width="wrap_content"
54
android:layout_height="wrap_content"
55
android:layout_gravity="bottom"
56
android:gravity="start"
57
android:orientation="vertical"
58
android:background="@color/peer_display_name_bg_color"
59
android:padding="5dp">
60
61
<EditText
62
android:id="@+id/me_display_name"
63
android:layout_width="wrap_content"
64
android:layout_height="wrap_content"
65
android:background="@null"
66
android:textSize="14sp"
67
android:textStyle="bold"
68
android:textColor="@color/peer_display_name_text_color"
69
android:imeOptions="actionDone"
70
android:singleLine="true"
71
android:text="@{peerViewProps.peer.displayName}"
72
android:visibility="@{peerViewProps.me ? View.VISIBLE : View.GONE}"
73
android:layout_marginHorizontal="8dp"/>
74
75
<TextView
76
android:id="@+id/peer_display_name"
77
android:layout_width="wrap_content"
78
android:layout_height="wrap_content"
79
android:layout_margin="5dp"
80
android:singleLine="true"
81
android:text="@{peerViewProps.peer.displayName}"
82
android:textColor="@color/peer_display_name_text_color"
83
android:textSize="14sp"
84
android:textStyle="bold"
85
android:visibility="@{!peerViewProps.me ? View.VISIBLE : View.GONE}"
86
android:layout_marginHorizontal="8dp"/>
87
88
</LinearLayout>
89
90
</FrameLayout>
91
</layout>
92
Copied!

Room

RoomActivity.java
1
public class RoomActivity extends AppCompatActivity {
2
3
private static final String TAG = RoomActivity.class.getSimpleName();
4
private static final int REQUEST_CODE_SETTING = 1;
5
6
private String mRoomId, mPeerId, mDisplayName;
7
8
private ActivityRoomBinding activityRoomBinding;
9
private HuddleClient huddleClient;
10
private StateStore stateStore;
11
private String apiKey = API_KEY_HERE;
12
13
@Override
14
protected void onCreate(Bundle savedInstanceState) {
15
super.onCreate(savedInstanceState);
16
17
activityRoomBinding = DataBindingUtil.setContentView(this, R.layout.activity_room);
18
stateStore = new StateStore();
19
createRoom();
20
checkPermission();
21
setupReactions();
22
}
23
24
@SuppressLint("NonConstantResourceId")
25
private void setupReactions(){
26
activityRoomBinding.reactionFab.inflate(R.menu.reactions_menu);
27
activityRoomBinding.reactionFab.setOnActionSelectedListener(actionItem -> {
28
switch (actionItem.getId()){
29
case R.id.tears_of_joy: {
30
huddleClient.sendReaction(Reactions.TEARS_OF_JOY);
31
activityRoomBinding.reactionFab.close();
32
return true;
33
}
34
case R.id.crying_face: {
35
huddleClient.sendReaction(Reactions.CRYING_FACE);
36
activityRoomBinding.reactionFab.close();
37
return true;
38
}
39
case R.id.hundred: {
40
huddleClient.sendReaction(Reactions.HUNDRED);
41
activityRoomBinding.reactionFab.close();
42
return true;
43
}
44
case R.id.thumbs_up: {
45
huddleClient.sendReaction(Reactions.THUMBS_UP);
46
activityRoomBinding.reactionFab.close();
47
return true;
48
}
49
case R.id.thumbs_down: {
50
huddleClient.sendReaction(Reactions.THUMBS_DOWN);
51
activityRoomBinding.reactionFab.close();
52
return true;
53
}
54
case R.id.rocket: {
55
huddleClient.sendReaction(Reactions.ROCKET);
56
activityRoomBinding.reactionFab.close();
57
return true;
58
}
59
default: {
60
Toast.makeText(this, "invalid reaction", Toast.LENGTH_SHORT).show();
61
activityRoomBinding.reactionFab.close();
62
return false;
63
}
64
}
65
});
66
}
67
68
private void createRoom(){
69
loadRoomConfig();
70
activityRoomBinding.invitationLink.setText("RoomId: "+mRoomId);
71
huddleClient = new HuddleClient.Builder(getApplicationContext(), apiKey)
72
.setPeerId(mPeerId)
73
.setRoomId(mRoomId)
74
.setDisplayName(mDisplayName)
75
.setCanConsume(true)
76
.setCanProduce(true)
77
.setCanUseDataChannel(true)
78
.setRoomEventListener(listener)
79
.setMeListener(meListener)
80
.setFrontCamEnabledOnInit(true)
81
.build();
82
83
getViewModelStore().clear();
84
initViewModel();
85
}
86
87
void joinRoom(){
88
huddleClient.joinRoom();
89
}
90
91
private void loadRoomConfig(){
92
Intent intent = getIntent();
93
String roomId = intent.getStringExtra("roomId");
94
if(roomId!=null){
95
mRoomId = roomId;
96
} else {
97
mRoomId = Utils.getRandomString(8);
98
}
99
mPeerId = Utils.getRandomString(8);
100
mDisplayName = Utils.getRandomString(8);
101
}
102
103
104
private void initViewModel(){
105
EdiasProps.Factory factory = new EdiasProps.Factory(getApplication(), stateStore);
106
RoomProps roomProps = new ViewModelProvider(this, factory).get(RoomProps.class);
107
roomProps.connect(this);
108
activityRoomBinding.invitationLink.setOnClickListener(v -> {
109
String invitationLink = roomProps.getInvitationLink().get();
110
ClipboardCopy.clipboardCopy(getApplication(), invitationLink, R.string.invite_link_copied);
111
});
112
activityRoomBinding.setRoomProps(roomProps);
113
114
MeProps meProps = new ViewModelProvider(this, factory).get(MeProps.class);
115
meProps.connect(this);
116
activityRoomBinding.me.setProps(meProps, huddleClient);
117
118
activityRoomBinding.chatInput.setOnEditorActionListener((v, actionId, event) -> {
119
if(actionId == EditorInfo.IME_ACTION_DONE){
120
huddleClient.sendChatMessage(v.getText().toString());
121
v.setText("");
122
return true;
123
} else
124
return false;
125
});
126
127
PeerAdapter peerAdapter = new PeerAdapter(stateStore, this);
128
activityRoomBinding.remotePeers.setLayoutManager