|
| 1 | +let client; |
| 2 | + |
| 3 | +const button = document.createElement('button'); |
| 4 | +button.onclick = () => { |
| 5 | + console.log('button clicked, going to send message'); |
| 6 | + const barejid = client.activeStanzaInstance?.jid?.match(/(.+\.com)/)?.[1]; |
| 7 | + const message = { |
| 8 | + to: barejid, |
| 9 | + from: client.activeStanzaInstance?.jid, |
| 10 | + mediaMessage: { id: '123', method: 'headsetControlsRequest', params: { requestType: 'mediaHelper' }} |
| 11 | + } |
| 12 | + client.activeStanzaInstance?.sendMessage(message); |
| 13 | +}; |
| 14 | +button.textContent = 'Send message'; |
| 15 | +document.body.appendChild(button); |
| 16 | + |
| 17 | +const button2 = document.createElement('button'); |
| 18 | +button2.textContent = 'Invalidate token'; |
| 19 | +button2.onclick = async () => { |
| 20 | + console.log('button clicked, invalidating auth token'); |
| 21 | + client.setAccessToken(''); |
| 22 | + await client.disconnect(); |
| 23 | + client.connect({ keepTryingOnFailure: true }); |
| 24 | +} |
| 25 | +document.body.appendChild(button2); |
| 26 | + |
| 27 | + |
| 28 | +const authButon = document.createElement('button'); |
| 29 | +authButon.textContent = 'Set auth token'; |
| 30 | +authButon.onclick = () => { |
| 31 | + const input = document.querySelector('input'); |
| 32 | + const token = input?.value; |
| 33 | + console.log('auth token', token); |
| 34 | + window.scConfig = { |
| 35 | + authToken: token, |
| 36 | + host: 'wss://streaming.inindca.com', |
| 37 | + optOutOfWebrtcStatsTelemetry: true |
| 38 | + }; |
| 39 | + client = new window.GenesysCloudStreamingClient(window.scConfig); |
| 40 | + console.log('client'); |
| 41 | + window.client = client; |
| 42 | + client.connect({ keepTryingOnFailure: true }) |
| 43 | + .then(() => { |
| 44 | + console.log('Client connected 1'); |
| 45 | + }); |
| 46 | + |
| 47 | + client.on('error', (error) => { |
| 48 | + console.log('RECEIVED Streaming Client Error!!!!', error); |
| 49 | + }); |
| 50 | + |
| 51 | + client.on('disconnected', (e) => { |
| 52 | + console.log('Client disconnected'); |
| 53 | + console.log(e); |
| 54 | + }) |
| 55 | +} |
| 56 | +document.body.appendChild(authButon); |
| 57 | + |
| 58 | +const authInput = document.createElement('input'); |
| 59 | +authInput.type = 'text'; |
| 60 | +document.body.appendChild(authInput); |
| 61 | + |
| 62 | +const clearAccessTokenBtn = document.createElement('button'); |
| 63 | +clearAccessTokenBtn.textContent = 'Clear access token'; |
| 64 | +clearAccessTokenBtn.onclick = () => { |
| 65 | + window.client.setAccessToken(''); |
| 66 | +} |
| 67 | +document.body.appendChild(clearAccessTokenBtn); |
| 68 | + |
| 69 | + |
| 70 | +const disconnect = document.createElement('button'); |
| 71 | +disconnect.textContent = 'Disconnect'; |
| 72 | +disconnect.onclick = () => { |
| 73 | + window.client.disconnect(); |
| 74 | +} |
| 75 | +document.body.appendChild(disconnect); |
| 76 | + |
| 77 | + |
| 78 | +// |
| 79 | + |
| 80 | + |
| 81 | + |
0 commit comments