ionorg / ion-sdk-js

ion javascript sdk
MIT License
102 stars 70 forks source link

example bug #222

Closed memsethz closed 2 years ago

memsethz commented 3 years ago

Browser: chrome 95.0.4638.54 ion-sdk-js: 1.7.2

Hi, I'm trying to integrate this sdk in angular and I've built the ion-sfu service locally. Here is my client integration code

const signal = new IonSFUGRPCWebSignal('ws://localhost:7000/ws');
const client = new Client(signal, {
  certificates: [],
  codec: 'h264',
  rtcpMuxPolicy: 'require'
});
this.signal = signal;
this.client = client;
signal.onopen = () => client.join('123456', '1');
signal.onerror = (error: any) => {
  console.log(error);
};
client.ontrack = (track: MediaStreamTrack, stream: RemoteStream) => {
  if (track.kind === 'video') {
    // prefer a layer
    stream.preferLayer('high');
  }
};
// Get a local stream
const local = await LocalStream.getUserMedia({
  resolution: 'vga',
  audio: true,
  codec: 'vp8'
});
client.publish(local);

The code was mostly consistent with the readme, but I soon encountered the first error

ERROR Error: Uncaught (in promise): Error: Websocket transport constructed with non-https:// or http:// host. Error: Websocket transport constructed with non-https:// or http:// host.

I found out that grpc-web is detecting that the url must start with http, so I changed ws://localhost:7000/ws to http://localhost:7000/ws, and then I got the second error

grpc-web-client.umd.js:1 WebSocket connection to 'ws://localhost:7000/ws/sfu.SFU/Signal' failed:

Can anyone tell me what this is about?

adwpc commented 3 years ago

https://github.com/pion/ion-sfu/blob/master/examples/pubsubtest/main.js as a reference, jsonrpc

memsethz commented 2 years ago

https://github.com/pion/ion-sfu/blob/master/examples/pubsubtest/main.js as a reference, jsonrpc

OK, I found my mistake, thanks