Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto invoke onDown method to close websocket. #331

Open
HydroCarbon opened this issue Mar 6, 2024 · 1 comment
Open

Auto invoke onDown method to close websocket. #331

HydroCarbon opened this issue Mar 6, 2024 · 1 comment

Comments

@HydroCarbon
Copy link

When i send a stream to wss server, The onDown method be invoked auto
Someone help me? There is my demo code:

record stream and send code:

Stream<Uint8List> recordStream = await _recorder.startStream(config);

    recordStream.listen(
      (data) {
        List<int> binaryData =
            _recorder.convertBytesToInt16(Uint8List.fromList(data));
        _channel.sink.addStream(Stream.fromIterable(binaryData));
      },
      onDone: () {
        print('Record done.');
      },
      onError: (error) {
        print('Record occur error: $error');
      },

wss channel connect code:

await _channel.ready;

    _channel.stream.listen(
      (message) {
        print(message);
      },
      onDone: () {
        print('Ws is done.');

        print(_channel.closeReason);
        if (_channel.closeCode != status.goingAway) {
          print('Ws is closed.');
        }
      },
      onError: (error) {
        print('Ws occur error: $error');
      },
    );

I had try to use add() method, issue is still there.

@HydroCarbon
Copy link
Author

At first, I build a channel to wss: _channel = WebSocketChannel.connect(wsUrl);
Then send a text frame to it , it work perfect and i got listen callback: _channel.sink.add(payload);

but i send a stream next, websocket closed by no reason.
There is my logs:

flutter: {"header":{"appkey":"xxxxxxx","message_id":"7aefd166623b4b9f80d452a580a8f2f7","task_id":"b49441934424490795240605d7799505","namespace":"SpeechTranscriber","name":"StartTranscription"},"payload":{"format":"pcm","sample_rate":16000,"enable_punctuation_prediction":true}}

flutter: {"header":{"namespace":"SpeechTranscriber","name":"TranscriptionStarted","status":20000000,"message_id":"7d4ceda2dfbe4789b07f648637c803e8","task_id":"b49441934424490795240605d7799505","status_text":"Gateway:SUCCESS:Success."}}

flutter: Ws is done.

flutter: 

flutter: Ws is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant