| 186 | } |
| 187 | |
| 188 | int main(int argc, char *argv[]) |
| 189 | { |
| 190 | if (argc > 1) { |
| 191 | startPeerStatus = PeerStatus::WAITING; |
| 192 | startPeerId = std::stol(argv[1]); |
| 193 | } |
| 194 | // Initialize the core library |
| 195 | humblenet_init(); |
| 196 | |
| 197 | // Initialize the P2P subsystem connecting to the named peer server |
| 198 | // Client token and secret are defined in the peer server configuration |
| 199 | // the 4th argument is for user authentication (future feature) |
| 200 | humblenet_p2p_init(HUMBLENET_SERVER_URL, client_token, client_secret, NULL); |
| 201 | |
| 202 | #ifdef EMSCRIPTEN |
| 203 | EM_ASM( |
| 204 | var canvasParent = Module.canvas.parentNode; |
| 205 | var wrap = document.createElement('div'); |
| 206 | canvasParent.insertBefore(wrap, Module.canvas); |
| 207 | |
| 208 | // data |
| 209 | var remotePeer = 0; |
| 210 | |
| 211 | // Messages |
| 212 | var connectToPeer = Module.cwrap('connectToPeer', 'void', ['number']); |
| 213 | var sendChat = Module.cwrap('sendChat', 'void', ['number', 'string']); |
| 214 | |
| 215 | var peerInput = document.createElement('input'); |
| 216 | peerInput.setAttribute('type','number'); |
| 217 | peerInput.setAttribute('placeholder', 'Peer #'); |
| 218 | wrap.appendChild(peerInput); |
| 219 | |
| 220 | var button = document.createElement('button'); |
| 221 | button.innerText = 'Connect'; |
| 222 | button.setAttribute('type','button'); |
| 223 | button.addEventListener('click', function(e) { |
| 224 | var val = parseInt(peerInput.value); |
| 225 | if (val > 0) { |
| 226 | remotePeer = val; |
| 227 | connectToPeer(val); |
| 228 | } |
| 229 | }); |
| 230 | wrap.appendChild(button); |
| 231 | |
| 232 | wrap.appendChild(document.createElement('br')); |
| 233 | |
| 234 | var chatInput = document.createElement('input'); |
| 235 | chatInput.setAttribute('type','text'); |
| 236 | chatInput.setAttribute('placeholder', 'Message'); |
| 237 | wrap.appendChild(chatInput); |
| 238 | |
| 239 | var button = document.createElement('button'); |
| 240 | button.id = 'ChatButton'; |
| 241 | button.innerText = 'Chat'; |
| 242 | button.setAttribute('type','button'); |
| 243 | button.disabled = true; |
| 244 | button.addEventListener('click', function(e) { |
| 245 | var val = chatInput.value; |
nothing calls this directly
no test coverage detected