Comments (4)
I tried the following code in my deno function.
import { serve } from "https://deno.land/[email protected]/http/server.ts"
import { AccessToken } from "https://esm.sh/[email protected]";
const corsHeaders = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
}
serve(async (req) => {
const roomName = 'my_room';
const participantName = 'dimitri';
const at = new AccessToken('SECRET', 'SECRET', {
identity: participantName,
});
// This is needed if you're planning to invoke your function from a browser.
if (req.method === 'OPTIONS') {
return new Response('ok', { headers: corsHeaders })
}
try {
const { name } = await req.json()
at.addGrant({ roomJoin: true, room: roomName });
const token = at.toJwt();
const data = {
message: `Hello ${name}!`,
token: token,
identity: participantName,
roomName: roomName,
}
return new Response(JSON.stringify(data), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 200,
})
} catch (error) {
return new Response(JSON.stringify({ error: error.message }), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 400,
})
}
})
I'm getting the following error during execution: "Identifier 'mod' has already been declared at file:///src/main.ts:3163:7".
It seems like there's something conflicting with Deno.
from node-sdks.
I believe it should work. There's nothing we explicitly require Node for. Do you want to give it a try and report back with any issues that you are finding?
from node-sdks.
This is working with Deno but wont work in Supabase Functions. If you want to work with supabase functions copy the AccessToken file from the repo and replace jsonwebtoken with jose. Check the pull request #59
import { serve } from 'https://deno.land/[email protected]/http/server.ts';
import { AccessToken } from "https://esm.sh/[email protected]";
const corsHeaders = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
}
interface RequestBody {
name: string;
roomName: string;
identity: string;
}
serve(async (req: Request) => {
// This is needed if you're planning to invoke your function from a browser.
if (req.method === 'OPTIONS') {
return new Response('ok', { headers: corsHeaders });
}
if (req.method !== 'POST') {
return new Response(JSON.stringify({ error: 'Method Not Allowed' }), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 405,
});
}
try {
const { name, roomName, identity }: RequestBody = await req.json();
const at = new AccessToken('SECRET', 'SECRET', {
identity: identity,
name: name,
metadata: 'contact',
ttl: '1h',
});
at.addGrant({
roomJoin: true,
room: roomName,
canPublish: true,
canSubscribe: true,
canPublishData: true,
});
const token = await at.toJwt();
const data = {
accessToken: token,
identity: identity,
roomName: roomName,
};
return new Response(JSON.stringify(data), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 200,
});
} catch (error) {
console.error('Invalid JSON payload:', error);
return new Response(JSON.stringify({ error: error.message }), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 400,
});
}
}, { port: 8082 });
from node-sdks.
Las missing piece for this should be #122, closing
from node-sdks.
Related Issues (20)
- EgressClient failed to export stream. HOT 1
- Text Chat via WebRTC Data Channel is unusable HOT 3
- Join room using the sdk from server HOT 1
- AccessToken.addGrant() should not replace previous grants HOT 1
- Cloudflare Worker support - avoid using 'crypto' from Node HOT 1
- updateParticipant throws uncatchable 500 error
- Documentation Update: `emptyTimeout` in `CreateOptions`
- key "name" missing in WebhookEvent type HOT 1
- After upgrading to v2, all functions like `createIngress()` are broken
- Import error in nestjs typescript HOT 8
- sendData is not working HOT 1
- Migration Doc: In `listRooms` response, field `creationTime` has been changed from Int to BigInt HOT 1
- Dependency Dashboard
- Livekit importing err when working with nestjs. HOT 1
- Dependency issue livekit-server-sdk HOT 1
- Issue with Parallel Room Instances and Audio Publishing HOT 2
- IO error: invalid peer certificate: UnknownIssuer HOT 2
- Problem with publishing video frame with realtime SDK HOT 4
- Expose WebhookEvent type HOT 1
- Cannot find module 'long' HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-sdks.