Error: Invalid session state CONNECTED

brunoibac

New Member
I am facing the following error when trying to connect an rtsp signal as shown in the example Player

flashphoner.js:9968 Uncaught Error: Invalid session state CONNECTED

How can I fix this or if I really have a session connected, how can I use it?

This error occurs because when opening createSession, SESSION_STATUS.CONNECTED is returning

Code:
function init_api(urlServer = wssUri) {
    Flashphoner.init({});
    //Connect to WCS server over websockets
    session = Flashphoner.createSession({
        urlServer
    }).on(SESSION_STATUS.ESTABLISHED, function(session) {
        console.log("ESTABLISHED");
        startVideos();
        
    }).on(STREAM_STATUS.FAILED, function (stream)  {
        console.log(stream);
        showDangerToast("Erro WSS", "Falha ao se conectar com o WSS", 100000);
        showDangerToast("Reconectando", "Aguarde....", "alert", 8000);
        init_api(wssUriBkp);
    }).on(SESSION_STATUS.CONNECTED, function(session) {
        console.log("CONNECTED");
        startVideos();
    });


    console.log(session);
}
 

Max

Administrator
Staff member
Good day.
A valid session states are: ESTABLISHED, DISCONNECTED, FAILED. See example code here
Code:
    Flashphoner.createSession({urlServer: url}).on(SESSION_STATUS.ESTABLISHED, function(session){
        setStatus(session.status());
        //session connected, start playback
        playStream(session);
    }).on(SESSION_STATUS.DISCONNECTED, function(){
        setStatus(SESSION_STATUS.DISCONNECTED);
        onStopped();
    }).on(SESSION_STATUS.FAILED, function(){
        setStatus(SESSION_STATUS.FAILED);
        onStopped();
    });
Also, STREAM_STATUS.FAILED is a Stream object event, not Session, so it must be handled for proper object.
 

brunoibac

New Member
Good day.
A valid session states are: ESTABLISHED, DISCONNECTED, FAILED. See example code here
Code:
    Flashphoner.createSession({urlServer: url}).on(SESSION_STATUS.ESTABLISHED, function(session){
        setStatus(session.status());
        //session connected, start playback
        playStream(session);
    }).on(SESSION_STATUS.DISCONNECTED, function(){
        setStatus(SESSION_STATUS.DISCONNECTED);
        onStopped();
    }).on(SESSION_STATUS.FAILED, function(){
        setStatus(SESSION_STATUS.FAILED);
        onStopped();
    });
Also, STREAM_STATUS.FAILED is a Stream object event, not Session, so it must be handled for proper object.

My script is no longer able to connect.
I changed it to see the DISCONNECTED event and now it is falling inside DISCONNECTED. How do I fix this?
 

brunoibac

New Member
Good day.
A valid session states are: ESTABLISHED, DISCONNECTED, FAILED. See example code here
Code:
    Flashphoner.createSession({urlServer: url}).on(SESSION_STATUS.ESTABLISHED, function(session){
        setStatus(session.status());
        //session connected, start playback
        playStream(session);
    }).on(SESSION_STATUS.DISCONNECTED, function(){
        setStatus(SESSION_STATUS.DISCONNECTED);
        onStopped();
    }).on(SESSION_STATUS.FAILED, function(){
        setStatus(SESSION_STATUS.FAILED);
        onStopped();
    });
Also, STREAM_STATUS.FAILED is a Stream object event, not Session, so it must be handled for proper object.

I realized that I have a connection that I can't close.

Code:
{
        "appKey": "defaultApp",
        "sessionId": "72a74862-4aa7-423f-ae47-5f8c353a92bd",
        "sipRegisterRequired": false,
        "sipLogin": "o0mj1pul960tu1785v7j3am9ba",
        "sipPort": 0,
        "width": 0,
        "height": 0,
        "supportedResolutions": "0x0",
        "useDTLS": true,
        "useWsTunnel": false,
        "useWsTunnelPacketization2": false,
        "msePacketizationVersion": 1,
        "useBase64BinaryEncoding": false,
        "mediaProviders": [
            "WebRTC"
        ],
        "authToken": "72a74862-4aa7-423f-ae47-5f8c353a92bd",
        "keepAlive": false
    },
I've tried calling the conncetion/terminate method passing the sessionId, but the call returns 200 but the connection is always there

Another strange situation is that when calling an RTSP connection via the rest API rtsp/statup I get 200 and the channel is open. But via js I am having the problem.

Could this be my problem?
 

Max

Administrator
Staff member
Please try to reproduce the issue in Player example https://your-wcs-instance-ip:8444/client2/examples/demo/streaming/player/player.html. If the problem is not reproducing, modify the Player example code minimally to reproduce it and send the code using this form.
If the problem is reproducing in Player example, please provide SSH access to the server and RTSP URL to test using this form.
 

brunoibac

New Member
Please try to reproduce the issue in Player example https://your-wcs-instance-ip:8444/client2/examples/demo/streaming/player/player.html. If the problem is not reproducing, modify the Player example code minimally to reproduce it and send the code using this form.
If the problem is reproducing in Player example, please provide SSH access to the server and RTSP URL to test using this form.

I did the test on the link and it returned diconnected as per the image sent. I monitored the flashphoner.log Following error:


Code:
04:02:55,778 ERROR           RestClient - API-ASYNC-pool-13-thread-9 Got exception in REST
org.codehaus.jackson.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: java.io.StringReader@59f7b546; line: 1, column: 2]
        at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1433)
        at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:521)
        at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:442)
        at org.codehaus.jackson.impl.ReaderBasedParser._handleUnexpectedValue(ReaderBasedParser.java:1198)
        at org.codehaus.jackson.impl.ReaderBasedParser.nextToken(ReaderBasedParser.java:485)
        at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2770)
        at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2718)
        at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1863)
        at com.flashphoner.rest.client.RestClient.postForObject(Unknown Source)
        at com.flashphoner.server.rmi.ManagerApiConnection.processDataObject(Unknown Source)
        at com.flashphoner.server.rmi.ManagerApiConnection.getApiMethodResult(Unknown Source)
        at com.flashphoner.server.client.handler.HandlerUtils.processRestException(Unknown Source)
        at com.flashphoner.server.client.handler.HandlerUtils.lambda$processThroughREST$0(Unknown Source)
        at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:859)
        at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:837)
        at java.base/java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:478)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
        at java.base/java.lang.Thread.run(Thread.java:832)
04:02:55,778 WARN  ManagerApiConnection - API-ASYNC-pool-13-thread-9 Failed to get object from REST with exception:Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: java.io.StringReader@59f7b546; line: 1, column: 2]
04:02:55,778 INFO  ManagerApiConnection - API-ASYNC-pool-13-thread-9 Method error policy is LOG, return same object to client
 

Max

Administrator
Staff member
Please provide SSH access to the server and RTSP URL to test using this form.
We can't help you by just a screenshot. All we can test is other RTSP links playback, and it is working on your server:
1672203536402.png

If you can't provide an access, please do the following:
1. Enable client debug logs on server
Code:
client_log_level=debug
2. Restart WCS
Code:
sudo systemctl restart webcallserver
3. Start to collect traffic dump on server
Code:
sudo tcpdump -npi any -B 10240 -w log.pcap
4. Reproduce a problem
5. Stop traffic dump collection
6. Collect the report on server
Code:
cd /usr/local/FlashphonerWebCallServer/tools
sudo ./report.sh --sysinfo --conf --tar
7. Send the report archive and traffic dump using this form.
 
Top