-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
171 lines (147 loc) · 5.31 KB
/
Copy pathindex.html
File metadata and controls
171 lines (147 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Banuba SDK Web AR demo</title>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/fomantic-ui@2.8.6/dist/semantic.min.css">
<script src="https://cdn.jsdelivr.net/npm/fomantic-ui@2.8.6/dist/semantic.min.js"></script>
<link rel="stylesheet" href="styles.css">
<script src="https://download.agora.io/sdk/web/AgoraRTC_N-4.1.0.js"></script>
</head>
<body class="ui container">
<aside>
<div id="webar">
<button class="ui icon button" id="sound">
<i class="volume up icon"></i>
</button>
</div>
<div id="effect-controls">
<h2>Select an effect:</h2>
<button class="circular ui icon button" id="reset" title="Reset">
<i class="undo icon"></i>
</button>
</div>
<div id="effects"></div>
<div class="fps-container">
<p class="ui horizontal divider header">
fps
</p>
<span id="fps">
Webcam FPS: <span id="cam"></span>
</br>
Processing FPS: <span id="processing"></span>
</br>
Render FPS: <span id="render"></span>
</span>
</div>
</aside>
<main></main>
<script src="AgoraAppId.js"></script>
<script src="BanubaClientToken.js"></script>
<script type="module">
import { Effect, Webcam, Player, Module, Dom, MediaStreamCapture, MediaStream } from "https://cdn.jsdelivr.net/npm/@banuba/webar/dist/BanubaSDK.browser.esm.min.js"
const effects = [
"Glasses",
"Hipster3",
"MonsterFactory",
"test_BG",
];
//const stream = new MediaStream(
// await AgoraRTCRemoteUser.videoTrack
//)
(async () => {
const wcam = new Webcam({ width: 640, height: 480 })
//const rcam = new AgoraRTCRemoteUser.videoTrack
//const wcam = new Webcam(video)
const [player, modules] = await Promise.all([
Player.create({
devicePixelRatio: 1,
clientToken: window.BANUBA_CLIENT_TOKEN,
}),
// Find more about available modules:
// https://docs.banuba.com/face-ar-sdk-v1/generated/typedoc/classes/Module.html
Module.preload(["background", "face_tracker"].map(m => `https://cdn.jsdelivr.net/npm/@banuba/webar/dist/modules/${m}.zip`)),
])
await player.addModule(...modules)
player.use(wcam)
//player.use(stream)
//player.use(video)
//player.use(client)
Dom.render(player, "#webar")
//#region fps
const fps = {
cam: 0,
processing: 0,
render: 0,
}
player.addEventListener("framereceived", () => fps.cam++)
player.addEventListener("frameprocessed", ({ detail }) => fps.processing = 1. / detail.averagedDuration)
player.addEventListener("framerendered", () => fps.render++)
setInterval(() => {
Object
.entries(fps)
.forEach(([name, value]) => {
fps[name] = 0
$(`#${name}`).text(value.toFixed(1))
})
}, 1000)
//#endregion
//#region effects
$.each(effects, async (idx, effectName) => {
const btn = $(
`<button class="ui tertiary button elastic loading">
${effectName}
</button>`
)
.prependTo("#effects")
const effect = await Effect.preload(`effects/${effectName}.zip`)
btn.on("click", () => player.applyEffect(effect))
btn.removeClass("loading")
})
$("#reset").on("click", () => player.clearEffect())
//#endregion
//#endregion
//#region agora set up
const client = AgoraRTC.createClient({ mode: "rtc", codec: "h264" })
client.on("user-published", async (user, mediaType) => {
await client.subscribe(user, mediaType);
if (mediaType === "video") user.videoTrack.play($("main")[0]);
if (mediaType === "audio") user.audioTrack.play();
})
//#region participants view
const adjustParticipantsView = () => {
const usersCount = client.remoteUsers.length
const columnsCount = Math.ceil(Math.sqrt(usersCount))
$("main").css("grid-template-columns", `repeat(${columnsCount}, 1fr)`)
}
client.on("user-joined", adjustParticipantsView)
client.on("user-left", adjustParticipantsView)
//#endregion
await client.join(
window.AGORA_APP_ID,
window.AGORA_CHANNEL_NAME,
window.AGORA_TOKEN,
)
//#endregion
//#region Banuba Web AR SDK and Agora Web SDK integration
const stream = new MediaStreamCapture(player)
//const video = await AgoraRTC.createCustomVideoTrack({ mediaStreamTrack: stream.getVideoTrack() })
const video = await AgoraRTC.createCustomVideoTrack({ mediaStreamTrack: stream.getVideoTrack})
//#endregion
const audio = await AgoraRTC.createMicrophoneAudioTrack()
await client.publish([ video, audio ])
//#region sound
let volume = 100
const toggleSound = () => {
volume = volume ? 0 : 100
audio.setVolume(volume)
$("#sound > i").toggleClass("up mute")
}
$("#sound").on("click", toggleSound)
//#endregion
})()
</script>
</body>
</html>