I ve got code to open a websocket connection and want simply put out a public readable textfile on the webconsole. I’ ll attach the code, the sharing for test.txt and the console output so far. any help appreciated.
Hi @ewingson the call to the display () function is missing in the socket.on message see complete example here
When the test.txt file is changed, the socket receive a ‘pub’ message, and the socket.onmessage is activated, the we launch the display function, remove the 4 first char to get the URL of the changed file, and then we run a fetch to that url, then we transform r, the response to text with .text() , then we console.log the result
I still havn’ t got it. lets begin as simple as possible. can I fire a GET and just output the content ? only read from the file ? a manual call of the function instead of on.change ? I’ m coming from procedural programming originally and still find it hard to follow the flow of javascript
[edit] die on change message konnte ich nachvollziehen. I could reproduce the on change message. learning success !!!
no not yet … I’ m trying to do everything manual, so I can understand and reproduce whats going on. Login and write would be the second step. can I use a xmlhttprequest for a GET ?
[edit] or do you think I should do it the SOLID-way from the very beginning ? I’ m doing things manual and low-level with intention…
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- IMPORT SOLID-AUTH-CLIENT AND SOLID-FILE-CLIENT LIBRARIES
-->
<script src="https://cdn.jsdelivr.net/npm/solid-auth-client@2.3.0/dist-lib/solid-auth-client.bundle.js"></script>
<script src="https://cdn.jsdelivr.net/npm/solid-file-client@1.0.0/dist/window/solid-file-client.bundle.js"></script>
<script>
// INSTANTIATE AUTH AND FILE-CLIENT OBJECTS
//
const auth = solid.auth
const fc = new SolidFileClient(auth)
const someUrl = 'https://[url_you_want_to_read]'
// DEFINE A URI THAT CONTAINS A POPUP LOGIN SCREEN
//
const popUri = 'https://solidcommunity.net/common/popup.html'
// USE THE AUTH OBJECT TO LOGIN AND CHECK THE SESSION
// USE THE FILE-CLIENT OBJECT TO READ AND WRITE
//
async function run(){
let session = await auth.currentSession()
if (!session) { session = await auth.popupLogin({ popupUri:popUri }) }
console.log(`Logged in as ${session.webId}.`)
let content = await fc.readFile( someUrl )
console.log(content)
}
run()
</script>
</head>
<body>
Take a look in the console
</body>
</html>
I’ m on a Solid learning journey. I don’ t have a particular task to work through yet, I want to explore the read and write abilities. and I am trying to do on a single-page-level, because then I can best follow the code. I appreciate your help. if I stumble upon further probs, I will let you know. but your feedback has been very valuable. I have opened a socket and additional on-message, on-close and on-error functions. but because its asynchron, I couldnt close clean yet. its a follow-your-nose-trip. exploring the Solidoverse