| 264 | } |
| 265 | |
| 266 | int main(int argc, char* argv[]) |
| 267 | { |
| 268 | std::string peerServer = HUMBLENET_SERVER_URL; |
| 269 | if (argc == 2) { |
| 270 | peerServer = argv[1]; |
| 271 | } |
| 272 | humblenet_p2p_init(peerServer.c_str(), "client_token", "client_secret", NULL); |
| 273 | |
| 274 | #ifdef EMSCRIPTEN |
| 275 | EM_ASM( |
| 276 | var canvasParent = Module.canvas.parentNode; |
| 277 | var wrap = document.createElement('div'); |
| 278 | canvasParent.insertBefore(wrap, Module.canvas); |
| 279 | |
| 280 | // Connect |
| 281 | var connectToPeer = Module.cwrap('connectToPeer', 'void', ['number']); |
| 282 | |
| 283 | var peerInput = document.createElement('input'); |
| 284 | peerInput.setAttribute('type','number'); |
| 285 | peerInput.setAttribute('placeholder', 'Peer #'); |
| 286 | |
| 287 | wrap.appendChild(peerInput); |
| 288 | |
| 289 | var button = document.createElement('button'); |
| 290 | button.innerText = 'Connect'; |
| 291 | button.setAttribute('type','button'); |
| 292 | button.addEventListener('click', function(e) { |
| 293 | var val = parseInt(peerInput.value); |
| 294 | if (val > 0) { |
| 295 | connectToPeer(val); |
| 296 | } |
| 297 | }); |
| 298 | |
| 299 | wrap.appendChild(button); |
| 300 | |
| 301 | wrap.appendChild(document.createElement('br')); |
| 302 | |
| 303 | // Chat |
| 304 | var sendChat = Module.cwrap('sendChat', 'void', ['string']); |
| 305 | |
| 306 | var chatInput = document.createElement('input'); |
| 307 | chatInput.setAttribute('type','text'); |
| 308 | chatInput.setAttribute('placeholder', 'Message'); |
| 309 | |
| 310 | wrap.appendChild(chatInput); |
| 311 | |
| 312 | var button = document.createElement('button'); |
| 313 | button.innerText = 'Chat'; |
| 314 | button.setAttribute('type','button'); |
| 315 | button.addEventListener('click', function(e) { |
| 316 | var val = chatInput.value; |
| 317 | sendChat(val); |
| 318 | }); |
| 319 | |
| 320 | wrap.appendChild(button); |
| 321 | ); |
| 322 | |
| 323 | emscripten_set_main_loop( main_loop, 60, 1 ); |
nothing calls this directly
no test coverage detected