Skip to content

Commit

Permalink
fix: documentation code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjackwills committed Feb 13, 2023
1 parent 093a1b7 commit 421076d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 65 deletions.
13 changes: 7 additions & 6 deletions src/components/Documentation/DocBinary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@ const websocket_connection = new WebSocket(\`${props.address_wss_pi}/\${response
const photo_as_b64 = await readFile('./keyboard_cat.jpg', { encoding: 'base64'} );
const binary_structured_message = JSON.stringify( { data : { name: "cat_photo", photo: photo_as_b64 } } );
websocket_connection.send(binary_structured_message);
});`;
`;
});
const b64_received = computed((): string => {
return `websocket_connection.addEventListener('message', (event) => {
let message = JSON.parse(event.data);
if (message.data?.name === "cat_photo") {
document.getElementById("cat_photo").src = \`data:image/jpeg;base64,\${message.data.photo}\`
}
});`;
const message = JSON.parse(event.data);
if (message.data?.name === "cat_photo") {
document.getElementById("cat_photo").src = \`data:image/jpeg;base64,\${message.data.photo}\`
}
});
`;
});
const props = defineProps({
Expand Down
55 changes: 25 additions & 30 deletions src/components/Documentation/DocConnect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,24 @@ const code_basic_connect_client = computed((): string => {
key: "${props.apiKey}"
};
const connect_client = async () => {
const token_request = await fetch('${props.address_token}/client', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(token_body)
});
const { response } = await token_request.json();
const websocket_connection = new WebSocket(\`${props.address_wss_client}/\${response}\` );
websocket_connection.addEventListener('open', (event) => {
console.log('client connected');
});
const token_request = await fetch('${props.address_token}/client', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(token_body)
});
const { response } = await token_request.json();
websocket_connection.addEventListener('message', (event) => {
console.log(\`message received on client: \${event.data}\`);
});
const websocket_connection = new WebSocket(\`${props.address_wss_client}/\${response}\` );
}`;
websocket_connection.addEventListener('open', (event) => {
console.log('client connected');
});
websocket_connection.addEventListener('message', (event) => {
console.log(\`message received on client: \${event.data}\`);
});`;
});
const code_basic_connect_pi = computed((): string => {
Expand All @@ -98,20 +96,17 @@ const token_body = {
key: "${props.apiKey}"
};
const connect_pi = async () => {
const { data } = await axios.post('${props.address_token}/pi', token_body)
const websocket_connection = new WebSocket(\`${props.address_wss_pi}/\${data.response}\`);
websocket_connection.on('open', function open() {
console.log('pi connected');
websocket_connection.send('Hello world');
});
const { data } = await axios.post('${props.address_token}/pi', token_body)
const websocket_connection = new WebSocket(\`${props.address_wss_pi}/\${data.response}\`);
websocket_connection.on('message', function message(data) {
console.log(\`message received on pi: \${data}\`);
});
websocket_connection.on('open', function open() {
console.log('pi connected');
websocket_connection.send('Hello world');
});
}`;
websocket_connection.on('message', function message(data) {
console.log(\`message received on pi: \${data}\`);
});`;
});
Expand Down
38 changes: 17 additions & 21 deletions src/components/Documentation/DocConnectWithPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,17 @@ const token_request = await fetch('${props.address_token}/client', {
},
body: JSON.stringify(token_body)
});
const { response } = await token_request.json();
const websocket_connection = new WebSocket(\`${props.address_wss_client}/\${response}\` );
websocket_connection.addEventListener('open', (event) => {
console.log('client connected');
});
const { response } = await token_request.json();
websocket_connection.addEventListener('message', (event) => {
console.log(\`message received on client: \${event.data}\`);
});
}
const websocket_connection = new WebSocket(\`${props.address_wss_client}/\${response}\` );
websocket_connection.addEventListener('open', (event) => {
console.log('client connected');
});
`;
websocket_connection.addEventListener('message', (event) => {
console.log(\`message received on client: \${event.data}\`);
});`;
});
const code_password_connect_pi = computed((): string => {
Expand All @@ -52,18 +50,16 @@ const code_password_connect_pi = computed((): string => {
password: "your_secret_pi_password"
};
const connect_client_password = async () => {
const { data } = await axios.get('${props.address_token}/pi', token_body)
const websocket_connection = new WebSocket(\`${props.address_wss_pi}/\${response.data}\` );
const { data } = await axios.get('${props.address_token}/pi', token_body)
const websocket_connection = new WebSocket(\`${props.address_wss_pi}/\${data.response}\` );
websocket_connection.addEventListener('open', (event) => {
console.log('pi connected');
});
websocket_connection.addEventListener('open', (event) => {
console.log('pi connected');
});
websocket_connection.addEventListener('message', (event) => {
console.log(\`message received on pi: \${event.data}\`);
});
}`;
websocket_connection.addEventListener('message', (event) => {
console.log(\`message received on pi: \${event.data}\`);
});`;
});
const props = defineProps({
Expand Down
16 changes: 8 additions & 8 deletions src/components/Documentation/DocStructuredData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
the three accepted key names are:
<br>
<br>
• <router-link :to='structured_id("data")' class='text-primary'>"data"</router-link>
• <router-link :to='structured_id("data")' class='font-weight-bold text-primary'>"data"</router-link>
<br>
• <router-link :to='structured_id("cache")' class='text-primary'>"cache"</router-link>
• <router-link :to='structured_id("cache")' class='font-weight-bold text-primary'>"cache"</router-link>
<br>
• <router-link :to='structured_id("unique")' class='text-primary'>"unique"</router-link>
• <router-link :to='structured_id("unique")' class='font-weight-bold text-primary'>"unique"</router-link>
<br>
<br>
• <router-link :to='structured_id("error")' class='text-primary'>"error"</router-link> is reserved exclusively for use by the servers of staticPi.
• <router-link :to='structured_id("error")' class='font-weight-bold text-primary'>"error"</router-link> is reserved exclusively for use by the servers of staticPi.

<v-divider color='secondary' class='my-2' thickness='2' />
<span class='text-h6 font-weight-bold text-pi' :id='structured_key_id("data")'>
Expand Down Expand Up @@ -169,10 +169,10 @@ websocket_connection.addEventListener('open', (event) => {
const code_structured_data_parse = computed((): string => {
return `websocket_connection.addEventListener('message', (event) => {
const message = JSON.parse(event.data);
console.log(message?.data?.anything)
// "I_want_here"
}
const message = JSON.parse(event.data);
console.log(message?.data?.anything)
// "I_want_here"
}
});`;
});
Expand Down

0 comments on commit 421076d

Please sign in to comment.