Skip to content

Commit 442998f

Browse files
committed
Some codes for hello WebRTC tutorial.
1 parent c735233 commit 442998f

File tree

6 files changed

+32
-20
lines changed

6 files changed

+32
-20
lines changed

client/android-webcam/sand-client-android-webcam/src/main/java/com/thefirstlineofcode/sand/client/android/webcam/WebcamWatcher.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,20 @@ public WebcamWatcher(IChatServices chatServices, Context appContext,
8484

8585
@Override
8686
public void watch() {
87-
super.watch();
87+
if (status == Status.WATCHING)
88+
return;
8889

89-
if (eglBase == null)
90+
if (eglBase == null) {
9091
eglBase = EglBase.create();
91-
92-
videoRenderer.init(eglBase.getEglBaseContext(), null);
92+
videoRenderer.init(eglBase.getEglBaseContext(), null);
93+
}
9394

9495
if (peerConnection == null)
9596
createPeerConnection();
9697

9798
addListener(this);
9899

99-
if (!isOpened()) {
100-
processSignal(Signal.ID.OPEN);
101-
}
100+
super.watch();
102101
}
103102

104103
@Override

client/webcam/src/main/java/com/thefirstlineofcode/sand/client/webcam/Webcam.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ public void start() {
6464

6565
logger.info("Try to connect to WebRTC native service.");
6666
nativeClient.connect();
67-
68-
started = true;
6967
logger.info("Webcam has connected to WebRTC native service.");
68+
69+
started = true;
70+
logger.info("Webcam has started.");
7071
}
7172

7273
@Override
@@ -86,6 +87,8 @@ public void stop() {
8687

8788
opened = false;
8889
started = false;
90+
91+
logger.info("Webcam has stopped.");
8992
}
9093

9194
@Override
@@ -179,8 +182,12 @@ public void iceCandidateFound(String jsonCandidate) {
179182
}
180183

181184
protected void askToOpen(JabberId asker) {
182-
if (requestedCapability == null)
185+
if (requestedCapability == null) {
186+
if (logger.isErrorEnabled())
187+
logger.error("Null requested capability.");
188+
183189
throw new IllegalArgumentException("Null requested capability.");
190+
}
184191

185192
if (peer != null && !peer.equals(asker)) {
186193
Iq closed = new Iq(Iq.Type.SET);

demo/app-android/app/src/main/java/com/thefirstlineofcode/sand/demo/app/android/LiveStreamingActivity.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.thefirstlineofcode.sand.demo.app.android;
22

33
import android.Manifest;
4-
import android.app.Activity;
54
import android.app.AlertDialog;
65
import android.content.Context;
76
import android.content.pm.PackageManager;
@@ -16,8 +15,11 @@
1615

1716
import org.slf4j.Logger;
1817
import org.slf4j.LoggerFactory;
18+
import org.webrtc.PeerConnection;
1919
import org.webrtc.SurfaceViewRenderer;
2020

21+
import java.util.List;
22+
2123
public class LiveStreamingActivity extends AppCompatActivity {
2224
private static final Logger logger = LoggerFactory.getLogger(LiveStreamingActivity.class);
2325

@@ -51,8 +53,8 @@ private void onCreate() {
5153

5254
SurfaceViewRenderer videoRenderer = findViewById(R.id.video_renderer);
5355
watcher = ChatClientSingleton.get(this).createApiImpl(WebcamWatcher.class,
54-
new Class<?>[] {Context.class, JabberId.class, SurfaceViewRenderer.class},
55-
new Object[] {this.getApplicationContext(), cameraJid, videoRenderer});
56+
new Class<?>[] {Context.class, JabberId.class, List.class, SurfaceViewRenderer.class},
57+
new Object[] {this.getApplicationContext(), cameraJid, MainApplication.ICE_SERVERS, videoRenderer});
5658
watcher.watch();
5759
}
5860

demo/app-android/app/src/main/java/com/thefirstlineofcode/sand/demo/app/android/ThingsAdapter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ private String[] getAuthorizedThingActions(String model) {
158158
return new String[] {"Flash", "Turn On", "Turn Off", "Stop", "Shutdown System"};
159159
} else if ("HAT".equals(model)) {
160160
return new String[] {"Flash", "Turn On", "Turn Off"};
161+
} else if ("HWT".equals(model)) {
162+
return new String[] {
163+
"Open Live Streaming"
164+
};
161165
} else {
162166
throw new RuntimeException(String.format("Unknown thing model: %s.", model));
163167
}

demo/server/src/main/java/com/thefirstlineofcode/sand/demo/server/AclPipelinePreprocessor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ private Object afterParsingSignal(JabberId from, Iq iq) {
124124
}
125125

126126
private boolean isUser(JabberId to) {
127-
return accountManager.exists(to.getBareIdString());
127+
return accountManager.exists(to.getNode());
128128
}
129129

130130
private boolean isThing(JabberId from) {
131-
return thingManager.thingIdExists(from.getBareIdString());
131+
return thingManager.thingNameExists(from.getNode());
132132
}
133133

134134
private Object afterParsingExecution(JabberId from, Iq iq) {
@@ -139,9 +139,9 @@ private Object afterParsingExecution(JabberId from, Iq iq) {
139139
String thingId = getThingId(iq.getTo());
140140

141141
Execution execution = iq.getObject();
142-
if (isTacpAction(execution.getAction())) {
142+
if (isTuxpAction(execution.getAction())) {
143143
if (!isOwner(sender, thingId))
144-
throw new ProtocolException(new NotAuthorized("TACP actions can be sent by owner only."));
144+
throw new ProtocolException(new NotAuthorized("TUXP actions can be sent by owner only."));
145145

146146
return iq;
147147
}
@@ -152,7 +152,7 @@ private Object afterParsingExecution(JabberId from, Iq iq) {
152152
return iq;
153153
}
154154

155-
private boolean isTacpAction(Object action) {
155+
private boolean isTuxpAction(Object action) {
156156
ProtocolObject pObject = action.getClass().getAnnotation(ProtocolObject.class);
157157
if (pObject == null)
158158
throw new ProtocolException(new InternalServerError("The action isn't a project object."));
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugin.id=sand-demo-server
22
plugin.provider=TheFirstLineOfCode
33
plugin.version=1.0.0-BETA3
4-
plugin.dependencies=sand-server-ibtr,sand-server-notification,sand-server-concentrator,sand-server-location,sand-server-sensor
5-
non-plugin.dependencies=sand-protocols-actuator,basalt-xeps-ping,sand-demo-protocol,sand-emulators-models,sand-protocols-edge,sand-protocols-lora-dac,sand-protocols-lora-gateway,sand-protocols-things-simple-light,sand-protocols-things-simple-camera,sand-protocols-things-simple-temperature-reporter,sand-protocols-webrtc-signaling,sand-protocols-operator
4+
plugin.dependencies=sand-server-ibtr,sand-server-notification,sand-server-concentrator,sand-server-location,sand-server-sensor,sand-server-p2p-webcam
5+
non-plugin.dependencies=sand-protocols-actuator,basalt-xeps-ping,sand-demo-protocol,sand-emulators-models,sand-protocols-edge,sand-protocols-lora-dac,sand-protocols-lora-gateway,sand-protocols-things-simple-light,sand-protocols-things-simple-camera,sand-protocols-things-simple-temperature-reporter,sand-protocols-operator

0 commit comments

Comments
 (0)