Help with conference demo

Julien

Member
Hello,
I am porting an existing application to WCS and i'm going to use the conference demo as a starting point.

I wanted to check all the REST urls called by that demo to know which REST hooks i should setup in my backend application so i created a node.js application to accepts any url that simply returns the body of the received request.
Then i created an app using the command line in WCS that points to my node.js app and added all rest methods to it.
After that i try the conference demo adding my app's appKey when connecting to the room but the demo doesn't work, it stays at the "ESTABLISHED" message but never starts broadcasting, while if i remove the appKey and connect to the default app it works fine.
Is there something specific needed to be done during the REST hooks for the conference demo to work?
Where can i see the code of the app used by the conference demo, i looked in the /usr/local/FlashphonerWebCallServer folder but couldn't find anything there.
 

Max

Administrator
Staff member
Hello

The Conference app is demo server-side application, deployed on local address: http://localhost:9091/ConferenceApp
This server-side application is built-in and ensures conference signaling such as delivering events, states, etc.
We didn't share source code of this application, but we plan to do that in future.

For now you have two options.
1. Implement your server-side hooks from scratch.
So if user A publishes a stream, your hook should keep this in memory, and if user B joined, you have to share the stream with user B, etc.
This is how ConferenceApp works. It is implemented compeltely based on REST hooks.
2. Another option, you can implement your own application and delegate all requests to ConferenceApp, then pass-through all responses back to WCS server
Code:
WCS - [REST] - [YourApp] - [ConferenceApp]
So you can intercept REST requestst in middle and modify responses if it is needed. For example you can intercept and record all messages.
 

Julien

Member
The Conference app is demo server-side application, deployed on local address: http://localhost:9091/ConferenceApp
This server-side application is built-in and ensures conference signaling such as delivering events, states, etc.
We didn't share source code of this application, but we plan to do that in future.
.
Hi, I was wondering, did you release the code of that application already? If not, any idea when that is happening?
 

Julien

Member
Hi,
I've been going over the code of RoomApp and it is pretty straight forward but i am wondering why i don't see anywhere the hook for "/unPublishStream" handled anywhere.
The file where all those hooks are handled is room/RoomApp.java but there is no conditional statement to handle what i am guessing should be (method.equals(APIMethods.UN_PUBLISH_STREAM).
Is it because it is enough to just echo back the request received?
Seems to me there should be some clean up when that hook happens, no?
 

Max

Administrator
Staff member
Hello
Method unpublishStream is not used in the RoomApp because it is not helpful in such a case.
When WCS sends /unpublishStream it means that user has pressed 'stop publishing' button or disconnected in browser.
However it does not mean that stream is really unpublished. It just means that unpublishing process has began for this stream.
Once the unpublishing process is complete, WCS sends APIMethods.STREAM_STATUS_EVENT stream.status='UNPUBLISHED'
Here you can see full flow
https://flashphoner.com/docs/wcs5/w...aming_video-publishing_a_stream-call_flow.htm
So you have to handle /StreamStatusEvent and check stream final state.
 

Max

Administrator
Staff member
Hello
It is old API hook related SIP SUBSCRIBE method.
Currently it is not used.
 

Julien

Member
Hi again, i am trying to pass additional custom data to the backend when joining a conference but i am so far unable to do it.
I tried to pass a custom object when creating the session like it is possible in the IP cam example but here it does nothing and looking at the code of Flashphoner.js it seems it completely ignores any extra data sent.
This is what i tried:
Code:
connection = Flashphoner.roomApi.connect({urlServer: url, username: username, appKey: 'myapp', custom: { user_type: 'some type' } })
but the user_type never reaches the backend. Looking in Flashphoner.js i see the following in the appSession object, starting on line 29624 for version 0.5.25.2455-8ff16:
Code:
var session = Flashphoner.createSession({
        urlServer: options.urlServer,
        mediaOptions: options.mediaOptions,
        appKey: (options.appKey && options.appKey.length!=0) ? options.appKey: ROOM_REST_APP,
        custom: {
            login: options.username,
            token: options.token
        }
    }
which seems to discard any custom data, meaning that creating a session with the room api has no way of sending additional parameters, am i missing something or is this correct?
I need to pass custom data to the backend when creating rooms and participants and when sending messages and have that custom data available on client side alongside the rest of the data already sent during events (user joined / left / message received).

How can i do that?
 

Max

Administrator
Staff member
Hello
You can pass your custom data through the token string
Code:
connection = Flashphoner.roomApi.connect({urlServer: url, username: username, appKey: 'myapp', token: 'user_type=myUserType' });
The token object is not used by the back-end. So you can pass any custom data within this line.
 

Julien

Member
Hi,
that solves the problem of sending custom data during connection creation to the backend but this data is not returned to the client anywhere, so i still have no way to send additional custom data from the backend to the client on ROOM_EVENTs (JOIN / LEFT / MESSAGE) because the room API doesn't take in account any possible custom data sent, which seems very restrictive to me, unless i am missing something or not looking at it right.

Is there really no way of doing that?
For example i need a few parameters when a message is sent like the type of user, emoticons enabled, etc, I understand i could do something like:
Code:
text: "user_type=student;emoticons=false;message=hello"
and then parse that on the client side and handle the data accordingly but this is a hack around the problem and pron to errors.
It seems to me you could easily have a "custom" field that gets passed along all events and kept during participants and messages creations in Flashphoner.js right?
 

Max

Administrator
Staff member
Hello
Please describe a user case in detail. Then we will be able to offer a solution.
For example
1. User1 receives a message from User2 in the room.
2. User1 should display
- type of User2
- emotions if t is enabled in settings of User1

Solution

To display type of User2 you need to have a public service on your back-end which returns type by username.
Example:
Code:
https://host/get_type_by_username.php?username=alice2018
To display emotions of User1 you need to have a public service on your back-end which returns if emotions enabled by username, or you can combine these two services:
Example:
Code:
https://host/get_public_profile_by_username.php?username=alice2018
So the particular usecase can be resolved fully on your back-end, without WCS at all.
If you provide more detail use case and explain why it should be implemented on WCS / Room API end, we will take it in consideration.
 

Julien

Member
Hi,
I understand that i could just keep fetching any additional data i need from the backend on every event but this is highly ineffective, why make additionals calls to the backend if we could simply send any custom data we need during the events of the Room API.

For example with the message event when the backend sends the payload, it can add a "custom" property like so:
Code:
{ nodeId: 'jQXuTX3aLHV73N1Z3scevdQ3dujA4LQi@62.212.93.98',
  sessionId: '/89.102.15.20:47792/172.29.40.131:8443',
  payload:
   { name: 'MESSAGE',
     roomName: 'room-ccb9bd',
     info:
      { roomConfig: { name: 'room-ccb9bd' },
        from: 'user1',
        to: 'user2',
        text: 'hello',
        custom: { user_type: 'teacher' }       // <--- this would be the property used
} } }
the only change needed on the Flashphoner Room API would be (using as example version 0.5.25.2455-8ff16 of Flashphoner.js starting on line 29809):
Code:
           if (data.name == "MESSAGE") {
                if (callbacks["MESSAGE"]) {
                    callbacks["MESSAGE"]({
                        from: participants[data.info.from],
                        text: data.info.text,
                        custom: data.info.custom      // <--- this new line to add the custom data sent from the backend to the object returned to the client
                    });
                }
            }
As you can see it would take only one line of code to have custom data enabled on message events. Then basically the same for the rest of the events (JOIN / LEFT / STATE) so that the participant object returned to the client would also have a custom property with whatever data we need to have available.
This allows much more flexibility for us users of WCS to have additional data exchanged during events in the applications that we build. :)
 

Julien

Member
By the way if it helps I can make a pull request if you have the code in a public repository like Github or Bitbucket.
 

Max

Administrator
Staff member
Thanks for detailed explanation.
The Room API is based on low-level Web SDK method sendData
var payload = {"name1","value1", "name1":"value1"};
Code:
sendData(payload);
So you can send any arbitrary data object.

As you mentioned, the ROOM API does not have such a method.
So you have to care and wrap your custom data as text.
For example, you would convert your custom object to Base64, hex or encode to another text format and then decode on receiver end.
This is how some of our customers work with custom data over the Room API. For example if you want to pass png image, you can wrap this as Base64.

We plan improvements on the Room API in our roadmap.
For now you can build your own rooms based on sendData() or use text-based object serialization within the Room API.
 
Top