brett
05/11/2021, 1:43 PMvans163
05/11/2021, 1:51 PMbrett
05/11/2021, 1:52 PMWallacy
05/11/2021, 3:15 PMWallacy
05/11/2021, 3:15 PMvans163
05/11/2021, 3:16 PMvans163
05/11/2021, 3:17 PMvans163
05/11/2021, 3:17 PMWallacy
05/11/2021, 3:24 PMWallacy
05/11/2021, 3:25 PMWallacy
05/11/2021, 3:40 PMGavin
05/12/2021, 1:13 PMDeebster
05/12/2021, 3:06 PMscheduled(request: ScheduledEvent, env)
handler if that module only handles crons. https://github.com/cloudflare/workers-types/blob/master/index.d.ts says you should expect
> interface ScheduledEvent {
> /**
> * The type of event. This will always return "scheduled"
.
> */
> type: string;
> /**
> * The time the ScheduledEvent
was scheduled to be executed in
> * milliseconds since January 1, 1970, UTC.
> * It can be parsed as new Date(event.scheduledTime)
> */
> scheduledTime: number;
> /**
> * Use this method to notify the runtime to wait for asynchronous tasks
> * (e.g. logging, analytics to third-party services, streaming and caching).
> * The first event.waitUntil
to fail will be observed and recorded as the
> * status in the Cron Trigger Past Events table. Otherwise, it will be
> * reported as a Success.
> */
> waitUntil(promise: Promise): void;
> }Gavin
05/12/2021, 3:08 PMDeebster
05/12/2021, 3:14 PMeidam | SuperSaaS
05/12/2021, 3:22 PMGavin
05/12/2021, 3:56 PMDeebster
05/13/2021, 3:58 AMGavin
05/13/2021, 7:52 AMJuicyIce
05/13/2021, 9:08 AMlet url = new URL(request.url);
switch (url.pathname) {
case '/connect-websocket':
if (request.headers.get('Upgrade') !== 'websocket') {
return new Response('expected websocket', {status: 400});
}
let ip = request.headers.get('CF-Connecting-IP');
let pair = new WebSocketPair();
await this.handleSession(pair[1], ip);
return new Response(null, {status: 101, webSocket: pair[0]})
break;
case '/init-data':
this.data = await request.json();
return new Response(JSON.stringify({message: 'Data initialized'}), {headers: corsHeaders});
break;
default:
return new Response('Not found', {status: 404});
}
Client side:
this.websocketConnection = new WebSocket('wss://secretdomain/connect-websocket?userId=20');
this.websocketConnection.addEventListener('error', (err) => {
console.log(err);
});
this.websocketConnection.addEventListener('open', (event) => {
console.log(event);
});
The only error I get is WebSocket connection to blabla failed
Btw I can make an HTTP request just fine.
Have tried to debug this for several hours 😄JuicyIce
05/13/2021, 9:08 AMasync handleSession(webSocket, ip) {
webSocket.accept();
webSocket.addEventListener('message', async (message) => {
try {
this.siteData = message.data;
} catch (e) {
console.log(e);
}
})
}
JuicyIce
05/13/2021, 10:20 AMErwin
05/13/2021, 10:56 AMtaro
05/13/2021, 5:39 PMidFromName
always be slower than lookups using IDs created with newUniqueId
?taro
05/13/2021, 5:40 PMeidam | SuperSaaS
05/13/2021, 7:04 PMvans163
05/13/2021, 7:45 PMvans163
05/13/2021, 7:46 PMexport default {
async fetch(request, env) { ... }
async scheduled(scheduledevent, env) { .. }
}
?vans163
05/13/2021, 7:57 PMvans163
05/13/2021, 7:57 PM