GetStream / stream-chat-js

JS / Browser Client - Build Chat with GetStream.io
https://getstream.io/chat/
Other
182 stars 76 forks source link

Support For Deno #1054

Closed rlee1990 closed 2 years ago

rlee1990 commented 2 years ago

Wanted to know if this already supports Deno? If not is it possible to add support?

rlee1990 commented 2 years ago

Update: as of now using

import * as _ from "https://deno.land/x/websocket@v0.1.4/mod.ts";
import { StreamChat } from "https://esm.sh/stream-chat@7.2.0"

both as of now seems to work. There is an issue using just the stream-chat option in Deno due to the WS package. Will keep testing to see if everything else works

rlee1990 commented 2 years ago

Well this does not work I get the below error:

Error: Error bundling function: exit status 1
error: Import 'https://esm.sh/v96/isomorphic-ws@4.0.1/deno/isomorphic-ws.js' failed: 500 Internal Server Error
    at https://esm.sh/v96/stream-chat@7.2.0/deno/stream-chat.js:2:1120
madsroskar commented 2 years ago

Hi, @rlee1990. We don't currently plan to support Deno. I don't know if the compatability mode would work, but this repo at the moment only supports node.

fekoch commented 1 year ago

Hey @madsroskar, just asking if anything changed recently as you published a blog post about deno some time ago?

rlee1990 commented 1 year ago

@fkoch-tgm that wasn't me that made this but I managed to get it all working on deno.

fekoch commented 1 year ago

@fkoch-tgm that wasn't me that made this but I managed to get it all working on deno.

oh sorry😅 How did you get it to work? I always have an issue with the crypto implementation...

rlee1990 commented 1 year ago

Sorry for the late replay. This is my function in Deno for this. I use supabase as a backend.

import { serve } from "https://deno.land/std@0.131.0/http/server.ts"
import { create, Header, Payload, } from "https://deno.land/x/djwt@v2.7/mod.ts"
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.0.0-rc.12'

const STREAM_SECRET = Deno.env.get("stream_secret")

const encoder = new TextEncoder()
  const keyBuf = encoder.encode(STREAM_SECRET)
  const key = await crypto.subtle.importKey(
    'raw',
    keyBuf,
    { name: 'HMAC', hash: 'SHA-256' },
    true,
    ['sign', 'verify']
  )
  const header: Header = {
    alg: 'HS256',
    typ: 'JWT',
  }

  const supabase = createClient(
    Deno.env.get("SUPABASE_URL")!,
    Deno.env.get("SUPABAS_ROLE_KEY")!
  );

serve(async (req) => {

  const body = await req.json()

  const {record} = body;

  const payload: Payload = {
    user_id: record.id,
  }

  const token = await create(header, payload, key)

//Save the token

  return new Response(
    null,
    {status: 200, headers: { "Content-Type": "application/json" } },
  )
})
rlee1990 commented 1 year ago

@fkoch-tgm if you are still having issues make sure your using the latest version of Deno and if using supabase like I am update that too and then you can use this link like this: import {StreamChat} from 'https://esm.sh/stream-chat@8.9.0'