zensin
zensin
CDCloudflare Developers
Created by zensin on 2/13/2025 in #workers-help
webrtc peer connection with datachannel
Is it currently possible to establish a webrtc tcp peer connection with a data channel from a worker? I feel like with nodejs compatibility and the fact that sockets are available should mean this is possible with some package idk about. Maybe I even have to code the handshake and whatnot myself. Is it at least possible? I know I can use the Calls API to coordinate client connections but I need my worker to be able to be part of the session.
1 replies
CDCloudflare Developers
Created by zensin on 5/20/2024 in #workers-help
rpc text stream
Does this make sense to do like this if this code is running in a method meant to return over RPC to another worker?
const chatCompletion = await openai.chat.completions.create({
model: 'gpt-4o',
messages: messages,
stream: true,
});
let { readable, writable } = new TransformStream()
const writer = writable.getWriter();
const encoder = new TextEncoder();

(async () => {
try {
for await (const chunk of stream) {
const content = chunk['choices'][0].delta.content;
const encodedMessage = encoder.encode(content);
writer.write(encodedMessage);
}
writer.close();
} catch (e) {
console.error(e);
// writer.abort(e);
return new Response('bad bad error', {
headers: headerCode
});
}
})();
return readable;
const chatCompletion = await openai.chat.completions.create({
model: 'gpt-4o',
messages: messages,
stream: true,
});
let { readable, writable } = new TransformStream()
const writer = writable.getWriter();
const encoder = new TextEncoder();

(async () => {
try {
for await (const chunk of stream) {
const content = chunk['choices'][0].delta.content;
const encodedMessage = encoder.encode(content);
writer.write(encodedMessage);
}
writer.close();
} catch (e) {
console.error(e);
// writer.abort(e);
return new Response('bad bad error', {
headers: headerCode
});
}
})();
return readable;
4 replies