|
2 | 2 |
|
3 | 3 | extern PSampleConfiguration gSampleConfiguration;
|
4 | 4 |
|
| 5 | +// onMessage callback for a message received by the viewer on a data channel |
| 6 | +VOID dataChannelOnMessageCallback(UINT64 customData, PRtcDataChannel pDataChannel, BOOL isBinary, PBYTE pMessage, UINT32 pMessageLen) |
| 7 | +{ |
| 8 | + UNUSED_PARAM(customData); |
| 9 | + UNUSED_PARAM(pDataChannel); |
| 10 | + if (isBinary) { |
| 11 | + DLOGI("DataChannel Binary Message"); |
| 12 | + } else { |
| 13 | + DLOGI("DataChannel String Message: %.*s\n", pMessageLen, pMessage); |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +// onOpen callback for the onOpen event of a viewer created data channel |
| 18 | +VOID dataChannelOnOpenCallback(UINT64 customData, PRtcDataChannel pDataChannel) { |
| 19 | + STATUS retStatus = STATUS_SUCCESS; |
| 20 | + DLOGI("New DataChannel has been opened %s \n", pDataChannel->name); |
| 21 | + dataChannelOnMessage(pDataChannel, customData, dataChannelOnMessageCallback); |
| 22 | + ATOMIC_INCREMENT((PSIZE_T) customData); |
| 23 | + // Sending first message to the master over the data channel |
| 24 | + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) VIEWER_DATA_CHANNEL_MESSAGE, STRLEN(VIEWER_DATA_CHANNEL_MESSAGE)); |
| 25 | + if(retStatus != STATUS_SUCCESS){ |
| 26 | + DLOGI("[KVS Viewer] dataChannelSend(): operation returned status code: 0x%08x \n", retStatus); |
| 27 | + } |
| 28 | +} |
| 29 | + |
5 | 30 | INT32 main(INT32 argc, CHAR* argv[])
|
6 | 31 | {
|
7 | 32 | STATUS retStatus = STATUS_SUCCESS;
|
@@ -81,13 +106,11 @@ INT32 main(INT32 argc, CHAR* argv[])
|
81 | 106 | // Initialize streaming session
|
82 | 107 | MUTEX_LOCK(pSampleConfiguration->sampleConfigurationObjLock);
|
83 | 108 | locked = TRUE;
|
84 |
| - |
85 | 109 | retStatus = createSampleStreamingSession(pSampleConfiguration, NULL, FALSE, &pSampleStreamingSession);
|
86 | 110 | if (retStatus != STATUS_SUCCESS) {
|
87 | 111 | printf("[KVS Viewer] createSampleStreamingSession(): operation returned status code: 0x%08x \n", retStatus);
|
88 | 112 | goto CleanUp;
|
89 | 113 | }
|
90 |
| - |
91 | 114 | printf("[KVS Viewer] Creating streaming session...completed\n");
|
92 | 115 | pSampleConfiguration->sampleStreamingSessionList[pSampleConfiguration->streamingSessionCount++] = pSampleStreamingSession;
|
93 | 116 |
|
@@ -165,6 +188,28 @@ INT32 main(INT32 argc, CHAR* argv[])
|
165 | 188 | goto CleanUp;
|
166 | 189 | }
|
167 | 190 |
|
| 191 | +#ifdef ENABLE_DATA_CHANNEL |
| 192 | + PRtcDataChannel pDataChannel = NULL; |
| 193 | + PRtcPeerConnection pPeerConnection = pSampleStreamingSession->pPeerConnection; |
| 194 | + SIZE_T datachannelLocalOpenCount = 0; |
| 195 | + |
| 196 | + // Creating a new datachannel on the peer connection of the existing sample streaming session |
| 197 | + retStatus = createDataChannel(pPeerConnection, pChannelName, NULL, &pDataChannel); |
| 198 | + if(retStatus != STATUS_SUCCESS) { |
| 199 | + printf("[KVS Viewer] createDataChannel(): operation returned status code: 0x%08x \n", retStatus); |
| 200 | + goto CleanUp; |
| 201 | + } |
| 202 | + printf("[KVS Viewer] Creating data channel...completed\n"); |
| 203 | + |
| 204 | + // Setting a callback for when the data channel is open |
| 205 | + retStatus = dataChannelOnOpen(pDataChannel, (UINT64) &datachannelLocalOpenCount, dataChannelOnOpenCallback); |
| 206 | + if(retStatus != STATUS_SUCCESS) { |
| 207 | + printf("[KVS Viewer] dataChannelOnOpen(): operation returned status code: 0x%08x \n", retStatus); |
| 208 | + goto CleanUp; |
| 209 | + } |
| 210 | + printf("[KVS Viewer] Data Channel open now...\n"); |
| 211 | +#endif |
| 212 | + |
168 | 213 | // Block until interrupted
|
169 | 214 | while (!ATOMIC_LOAD_BOOL(&pSampleConfiguration->interrupted) && !ATOMIC_LOAD_BOOL(&pSampleStreamingSession->terminateFlag)) {
|
170 | 215 | THREAD_SLEEP(HUNDREDS_OF_NANOS_IN_A_SECOND);
|
|
0 commit comments