public class

SkylinkConnection

extends Object
java.lang.Object
   ↳ sg.com.temasys.skylink.sdk.rtc.SkylinkConnection

Class Overview

Main class to connect to the skylink infrastructure.

Summary

Nested Classes
enum SkylinkConnection.SkylinkState Possible states of the SkylinkConnection instance. 
Constants
int DEFAULT_DURATION Duration in hours after the start time when the room will be closed by the signalling server.
Public Methods
boolean connectToRoom(String secret, String roomName, Object userData)
Connects to a room with the default duration of 24 hours and with the current time.
boolean connectToRoom(String skylinkConnectionString, Object userData)
Connects to a room using a SkylinkConnectionString that caller MUST ensure is URL safe.
boolean disconnectFromRoom()
Disconnects from the room we are currently in.
SkylinkCaptureFormat getCaptureFormat()
Return the SkylinkCaptureFormat that is currently being used by the camera.
SkylinkCaptureFormat[] getCaptureFormats(SkylinkConfig.VideoDevice videoDevice)
Get the possible capture format(s) of the specified camera device in an array.
String getCurrentCameraName()
Get the name of the current camera being used.
SkylinkConfig.VideoDevice getCurrentVideoDevice()
Get the current VideoDevice being used.
DataTransferListener getDataTransferListener()
FileTransferListener getFileTransferListener()
void getInputVideoResolution()
Get the current resolution of the input video being captured by the local camera and the SkylinkCaptureFormat used.
synchronized static SkylinkConnection getInstance()
LifeCycleListener getLifeCycleListener()
MediaListener getMediaListener()
MessagesListener getMessagesListener()
OsListener getOsListener()
String getPeerId()
Get our PeerId, or return null if not available.
String[] getPeerIdList()
Return a String array of PeerIds of connected Peers, including self.
void getReceivedVideoResolution(String peerId)
Get the current resolution of the video received from a specific Peer.
RecordingListener getRecordingListener()
RemotePeerListener getRemotePeerListener()
String getRoomId()
Provides the room ID of the room currently connected to.
void getSentVideoResolution(String peerId)
Get the current resolution of the video being sent to a specific Peer.
SkylinkConnection.SkylinkState getSkylinkState()
Gets the current SkylinkState of the current SkylinkConnection instance.
static String getSkylinkVersion()
Gets the version of this Skylink SDK for Android as a String, for e.g.
StatsListener getStatsListener()
boolean getTransferSpeeds(String peerId, int mediaDirection, int mediaType)
Request for the instantaneous transfer speed(s) of media stream(s), at the moment of request.
Object getUserData(String peerId)
Retrieves the user defined data object of a peer.
UserInfo getUserInfo(String peerId)
Retrieves the UserInfo object of a Peer.
SurfaceViewRenderer getVideoView(String peerId)
Return the video view of Peer whose PeerId was provided.
boolean getWebrtcStats(String peerId, int mediaDirection, int mediaType)
Request for WebRTC statistics of the specified media stream.
void init(String appKey, SkylinkConfig config, Context applicationContext)
Initialize a SkylinkConnection object with the specified parameters.
boolean isConnected()
Deprecated - Use getSkylinkState() to determine if SkylinkConnection is connected.
boolean isRecording()
Checks if we are currently recording room.
boolean isRoomLocked()
Checks if the room is locked.
void lockRoom()
Locks the room if its not already locked
void muteLocalAudio(boolean isMuted)
Mutes the local user's audio and notifies all the peers in the room.
void muteLocalVideo(boolean isMuted)
Mutes the local user's video and notifies all the peers in the room.
boolean processPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
Process Android Runtime permission result received by App via Android callback onRequestPermissionsResult.
String[] refreshConnection(String remotePeerId, boolean iceRestart)
Refreshes a connection with a specific peer or all connections if remotePeerId is null Able to indicate preference for ICE restart.
void restartConnection(String remotePeerId)
Refreshes the connection with a specific peer or all connections if remotePeerId is null.
void sendData(String remotePeerId, byte[] data)
Sends a byte array to a specified remotePeer or to all participants of the room if the remotePeerId is null The byte array cannot be null, and its maximum size is 65456 bytes.
void sendFileTransferPermissionRequest(String remotePeerId, String fileName, String filePath)
Sends request(s) to share file with a specific remote peer or to all remote peers in a direct peer to peer manner in the same room.
void sendFileTransferPermissionResponse(String remotePeerId, String filePath, boolean isPermitted)
Call this method to accept or reject the file share request from a remote peer.
void sendLocalUserData(Object userData)
Sends local user data related to oneself, to all remote peers in our room.
void sendP2PMessage(String remotePeerId, Object message)
Sends a user defined message to a specific remote peer or to all remote peers in a direct peer to peer manner.
void sendServerMessage(String remotePeerId, Object message)
Sends a user defined message to a specific remote peer or to all remote peers via a server.
void setDataTransferListener(DataTransferListener dataTransferListener)
Sets the specified data transfer listener object.
void setFileTransferListener(FileTransferListener fileTransferListener)
Sets the specified file transfer listener object.
void setInputVideoResolution(int width, int height, int fps)
If the current local input video device is a camera, change the current captured video stream to the specified resolution, and the specified resolution will be set into SkylinkConfig.
void setLifeCycleListener(LifeCycleListener lifeCycleListener)
Sets the specified life cycle listener object.
void setMediaListener(MediaListener mediaListener)
Sets the specified media listener object that will receive callbacks related to Media Stream.
void setMessagesListener(MessagesListener messagesListener)
Sets the specified messages listener object.
void setOsListener(OsListener osListener)
Sets the specified OS listener object.
void setRecordingListener(RecordingListener recordingListener)
void setRemotePeerListener(RemotePeerListener remotePeerListener)
Sets the specified remote peer listener object.
void setStatsListener(StatsListener statsListener)
boolean startRecording()
Start recording if conditions allows: - We must be using Skylink Media Relay.
boolean stopRecording()
Stop recording if conditions allows: - We must be already be recording.
void switchCamera()
Call this method to switch between available camera.
boolean toggleCamera(boolean restart)
Stop or restart the local camera based on the parameter |restart|, given that the local video source is available, i.e., had been started and not removed.
boolean toggleCamera()
Stop or restart the local camera given that the local video source is available, i.e., had been started and not removed.
void unlockRoom()
Unlocks the room if its already locked
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int DEFAULT_DURATION

Duration in hours after the start time when the room will be closed by the signalling server.

Constant Value: 24 (0x00000018)

Public Methods

public boolean connectToRoom (String secret, String roomName, Object userData)

Connects to a room with the default duration of 24 hours and with the current time. Local media (if any exists) will be disposed and then obtained according to the SkylinkConfig provided in init. It is encouraged to use the method connectToRoom(String connectionString, Object userData)

Parameters
secret The secret associated with the key as registered with the Skylink Developer Console
roomName The name of the room
userData User defined data relating to oneself. May be a 'java.lang.String', 'org.json.JSONObject' or 'org.json.JSONArray'.
Returns
  • 'false' if the connection is already established

public boolean connectToRoom (String skylinkConnectionString, Object userData)

Connects to a room using a SkylinkConnectionString that caller MUST ensure is URL safe. Local media (if any exists) will be disposed and then obtained according to the SkylinkConfig provided in init. Call on .

Parameters
skylinkConnectionString SkylinkConnectionString Generated with room name, appKey, secret, startTime and duration. This string MUST be URL safe.
userData User defined data relating to oneself. May be a 'java.lang.String', 'org.json.JSONObject' or 'org.json.JSONArray'.
Returns
  • 'false' if unable to make the connection attempt. Possible reason include: connection is already established;

public boolean disconnectFromRoom ()

Disconnects from the room we are currently in.

Once disconnect is complete, onDisconnect(int, String) will be called.

To connect to a room after this, init(String, SkylinkConfig, Context) and connectToRoom(String, Object) will have to be called.

Returns
  • False if unable or unnecessary to disconnect, for e.g., if a disconnect attempt is already in progress, or if we are already disconnected.

public SkylinkCaptureFormat getCaptureFormat ()

Return the SkylinkCaptureFormat that is currently being used by the camera. Note that the current CaptureFormat may change whenever the video resolution dimensions change.

Returns
  • null if there is no CaptureFormat in use now, e.g. if video is not capturing.

public SkylinkCaptureFormat[] getCaptureFormats (SkylinkConfig.VideoDevice videoDevice)

Get the possible capture format(s) of the specified camera device in an array. Return null if provided VideoDevice was not a camera, or if it was not possible to get the capture formats.

Parameters
videoDevice Use null to specific the current VideoDevice.

public String getCurrentCameraName ()

Get the name of the current camera being used. If no camera is being used, return null.

public SkylinkConfig.VideoDevice getCurrentVideoDevice ()

Get the current VideoDevice being used. If none are active, return null.

public DataTransferListener getDataTransferListener ()

Returns
  • The data transfer listener object.

public FileTransferListener getFileTransferListener ()

Returns
  • The file transfer listener object.

public void getInputVideoResolution ()

Get the current resolution of the input video being captured by the local camera and the SkylinkCaptureFormat used. If resolution is available, it will be returned in onInputVideoResolutionObtained(int, int, int, SkylinkCaptureFormat). Note: - Resolution may not always be available, e.g. if no video is captured. - This might be different from the resolution of the video actually sent to Peers as WebRTC may adjust resolution dynamically to try to match its bandwidth criteria.

public static synchronized SkylinkConnection getInstance ()

Returns
  • Existing instance of SkylinkConnection Object if it exists or a new instance if it doesn't exist.

public LifeCycleListener getLifeCycleListener ()

Returns
  • The life cycle listener object.

public MediaListener getMediaListener ()

Returns
  • The media listener object

public MessagesListener getMessagesListener ()

Returns
  • The messages listener object.

public OsListener getOsListener ()

Returns
  • The OS listener object.

public String getPeerId ()

Get our PeerId, or return null if not available.

public String[] getPeerIdList ()

Return a String array of PeerIds of connected Peers, including self. Size of array is number of Peers connected, including self. Return null if we do not have a PeerId, e.g. when not connected to the room.

Returns
  • An array of PeerIds, where the first one is the self PeerId. Null if no PeerId is available.

public void getReceivedVideoResolution (String peerId)

Get the current resolution of the video received from a specific Peer. If resolution is available, it will be returned in onReceivedVideoResolutionObtained(String, int, int, int). Note: - Resolution may not always be available, e.g. if no video is received or PeerId is invalid.

Parameters
peerId PeerId of the remote Peer from whom we want to get received video resolution. Use Null to get received video resolutions of all connected remote Peers.

public RecordingListener getRecordingListener ()

Returns
  • The recording listener object.

public RemotePeerListener getRemotePeerListener ()

Returns
  • The remote peer listener object.

public String getRoomId ()

Provides the room ID of the room currently connected to. This is sometimes also referred to as the meeting ID.

Returns
  • The room ID as a String, or null if not available.

public void getSentVideoResolution (String peerId)

Get the current resolution of the video being sent to a specific Peer. If resolution is available, it will be returned in onSentVideoResolutionObtained(String, int, int, int). Note: - Resolution may not always be available, e.g. if no video is sent or PeerId is invalid. - This might be different from the resolution of the video actually captured by camera as WebRTC may adjust resolution dynamically to try to match its bandwidth criteria.

Parameters
peerId PeerId of the remote Peer from whom we want to get sent video resolution. Use Null to get sent video resolutions of all connected remote Peers.

public SkylinkConnection.SkylinkState getSkylinkState ()

Gets the current SkylinkState of the current SkylinkConnection instance.

Returns

public static String getSkylinkVersion ()

Gets the version of this Skylink SDK for Android as a String, for e.g. "0.9.8".

public StatsListener getStatsListener ()

Returns
  • The Stats listener object.

public boolean getTransferSpeeds (String peerId, int mediaDirection, int mediaType)

Request for the instantaneous transfer speed(s) of media stream(s), at the moment of request. It is calculated from the WebRTC provided statistics of the specified media stream(s), over a short time interval. Results will be reported via onTransferSpeedReceived(String, int, int, double)

Parameters
peerId PeerId of the remote Peer for which we are getting transfer speed on.
mediaDirection Info Integer that defines the direction of media stream(s) reported on, such as sending, receiving or both.
mediaType Info Integer that defines the type(s) of media reported on, such as audio, video, or all.
Returns
  • False if request was invalid, for e.g. when provided PeerId was invalid.

public Object getUserData (String peerId)

Retrieves the user defined data object of a peer.

Parameters
peerId The PeerId of the peer whose UserData is to be retrieved, or NULL for self.
Returns
  • May be a 'java.lang.String', 'org.json.JSONObject' or 'org.json.JSONArray'.

public UserInfo getUserInfo (String peerId)

Retrieves the UserInfo object of a Peer.

Parameters
peerId The PeerId of the peer whose UserInfo is to be retrieved, or NULL for self.
Returns
  • UserInfo

public SurfaceViewRenderer getVideoView (String peerId)

Return the video view of Peer whose PeerId was provided. If peerId is null, local video view will be returned. Return null if: - No video view exists for given PeerId. - Including if given PeerId does not exist.

Parameters
peerId PeerId of the Peer whose videoView to be returned.
Returns
  • Video View of Peer or null if none present.

public boolean getWebrtcStats (String peerId, int mediaDirection, int mediaType)

Request for WebRTC statistics of the specified media stream. Results will be reported via onWebrtcStatsReceived(String, int, int, HashMap)

Parameters
peerId PeerId of the remote Peer for which we are getting stats on.
mediaDirection Info Integer that defines the direction of media stream(s) reported on, such as sending, receiving or both.
mediaType Info Integer that defines the type(s) of media reported on, such as audio, video, or all.
Returns
  • False if request was invalid, for e.g. when provided PeerId was invalid.

public void init (String appKey, SkylinkConfig config, Context applicationContext)

Initialize a SkylinkConnection object with the specified parameters. Any Listeners set before will be removed (i.e. set to null). Can only be done when disconnected from room.

Parameters
appKey The App key from the Skylink Developer Console
config The SkylinkConfig object to configure the type of call.
applicationContext The Android ApplicationContext.

public boolean isConnected ()

Deprecated - Use getSkylinkState() to determine if SkylinkConnection is connected.

Checks if we are currently connected to the Room. Note that even if we are in the process of disconnecting, as long as the connection to the Room is still there, this will still return true.

Returns
  • True if we are connected to the Room, and false if not.

public boolean isRecording ()

Checks if we are currently recording room. Notes: - Recording status may change immediately after query. - If recording was on and we just tried to stop recording, it would be considered as recording is still on, even if the Recording Server had stopped recording, but whose signal had yet to reach us. This is to avoid accidental recording of unintended material when a user believed that recording had stopped before it actually does.

Returns
  • True if recording, false otherwise.

public boolean isRoomLocked ()

Checks if the room is locked.

Returns
  • True if room is locked, false otherwise.

public void lockRoom ()

Locks the room if its not already locked

public void muteLocalAudio (boolean isMuted)

Mutes the local user's audio and notifies all the peers in the room.

Parameters
isMuted Flag that specifies whether audio should be mute

public void muteLocalVideo (boolean isMuted)

Mutes the local user's video and notifies all the peers in the room. Note that black video frames (consuming bandwidth) are still being sent to remote Peer(s).

Parameters
isMuted Flag that specifies whether video should be mute

public boolean processPermissionsResult (int requestCode, String[] permissions, int[] grantResults)

Process Android Runtime permission result received by App via Android callback onRequestPermissionsResult. The permission request may or may not have been prompted by the Skylink SDK.

  • If it was, the SDK will take actions depending on whether permission requested was granted.
  • If it was not, the SDK will not process the permission results and will return false. The user should then process the permission result in the App.

Parameters
requestCode The requestCode in the Android callback.
permissions The permissions in the Android callback.
grantResults The grantResults in the Android callback.
Returns
  • True if requestCode is recognised by SDK.

public String[] refreshConnection (String remotePeerId, boolean iceRestart)

Refreshes a connection with a specific peer or all connections if remotePeerId is null Able to indicate preference for ICE restart. ICE will only restart if both the Peers of the connection being restarted allow ICE restart. Note that when Skylink Media Relay is active: - Refresh will be done with all Peers, even if a specific remotePeerId was provided. - ICE restart will not occur, even if it was set to true.

Parameters
remotePeerId Id of the remote peer to whom we will refresh connection. Use 'null' if refresh is to be done with all our remote peers in the room.
iceRestart Specify if ICE restart should be performed. ICE restart is recommended if network conditions had changed, for e.g. a different network is used.
Returns
  • If refresh signal sent, returns null. If failed to send restart for some Peer(s), return PeerId(s) of the Peer(s) in an array. If there is no Peer to send to, return array with 1 element of empty string.

public void restartConnection (String remotePeerId)

Refreshes the connection with a specific peer or all connections if remotePeerId is null. ICE restart will NOT be carried out. Note that when Skylink Media Relay is active, Refresh will be done with all Peers, even if a specific remotePeerId was provided.

Parameters
remotePeerId Id of the remote peer to whom we will refresh connection. Use 'null' if refresh is to be done with all our remote peers in the room.

public void sendData (String remotePeerId, byte[] data)

Sends a byte array to a specified remotePeer or to all participants of the room if the remotePeerId is null The byte array cannot be null, and its maximum size is 65456 bytes. Notes: - This operation is currently not supported with Skylink Media Relay. - This operation is currently only supported between Skylink Mobile SDKs.

Parameters
remotePeerId remotePeerID of a specified peer
data Array of bytes
Throws
SkylinkException When byte array is not of a size allowed.

public void sendFileTransferPermissionRequest (String remotePeerId, String fileName, String filePath)

Sends request(s) to share file with a specific remote peer or to all remote peers in a direct peer to peer manner in the same room. Only 1 file may be sent to the same Peer at the same time. Sending and receiving concurrently with a non-Mobile (e.g. Web or C++) Peer is not supported.

Parameters
remotePeerId The id of the remote peer to send the file to. Use 'null' if the file is to be sent to all our remote peers in the room.
fileName The name of the file that is to be shared.
filePath The absolute path of the file in the filesystem

public void sendFileTransferPermissionResponse (String remotePeerId, String filePath, boolean isPermitted)

Call this method to accept or reject the file share request from a remote peer.

Parameters
remotePeerId The id of the remote peer that requested to share with us a file.
filePath The absolute path of the file where we want it to be saved.
isPermitted Whether permission was granted for the file share to proceed.

public void sendLocalUserData (Object userData)

Sends local user data related to oneself, to all remote peers in our room.

Parameters
userData User defined data relating to the peer. May be a 'java.lang.String', 'org.json.JSONObject' or 'org.json.JSONArray'.

public void sendP2PMessage (String remotePeerId, Object message)

Sends a user defined message to a specific remote peer or to all remote peers in a direct peer to peer manner.

Parameters
remotePeerId Id of the remote peer to whom we will send a message. Use 'null' if the message is to be sent to all our remote peers in the room.
message User defined data. May be a 'java.lang.String', 'org.json.JSONObject' or 'org.json.JSONArray'.
Throws
SkylinkException if the system was unable to send the message.

public void sendServerMessage (String remotePeerId, Object message)

Sends a user defined message to a specific remote peer or to all remote peers via a server.

Parameters
remotePeerId Id of the remote peer to whom we will send a message. Use 'null' if the message is to be broadcast to all remote peers in the room.
message User defined data. May be a 'java.lang.String', 'org.json.JSONObject' or 'org.json.JSONArray'.

public void setDataTransferListener (DataTransferListener dataTransferListener)

Sets the specified data transfer listener object.

Parameters
dataTransferListener The data transfer listener object that will receive callbacks related to DataTransfer

public void setFileTransferListener (FileTransferListener fileTransferListener)

Sets the specified file transfer listener object.

Parameters
fileTransferListener The file transfer listener object that will receive callbacks related to FileTransfer

public void setInputVideoResolution (int width, int height, int fps)

If the current local input video device is a camera, change the current captured video stream to the specified resolution, and the specified resolution will be set into SkylinkConfig. Non-camera supported resolution can be accepted, but a camera supported resolution will be used when opening camera. There is no guarantee that a specific camera resolution will be maintained as WebRTC may adjust the resolution dynamically to match its bandwidth criteria.

public void setLifeCycleListener (LifeCycleListener lifeCycleListener)

Sets the specified life cycle listener object.

Parameters
lifeCycleListener The life cycle listener object that will receive callbacks related to the SDK's Lifecycle.

public void setMediaListener (MediaListener mediaListener)

Sets the specified media listener object that will receive callbacks related to Media Stream.

Callbacks include those for the local user and remote peers.

Parameters
mediaListener The media listener object

public void setMessagesListener (MessagesListener messagesListener)

Sets the specified messages listener object.

Parameters
messagesListener The messages listener object that will receive callbacks related to Message Transmissions.

public void setOsListener (OsListener osListener)

Sets the specified OS listener object.

Parameters
osListener The OS listener object that will receive callbacks related to Android OS operations.

public void setRecordingListener (RecordingListener recordingListener)

Parameters
recordingListener The RecordingListener object that will receive callbacks related to recording.

public void setRemotePeerListener (RemotePeerListener remotePeerListener)

Sets the specified remote peer listener object.

Parameters
remotePeerListener The remote peer listener object that will receive callbacks related to remote Peers.

public void setStatsListener (StatsListener statsListener)

Parameters
statsListener The stats listener object that will receive callbacks related to statistics.

public boolean startRecording ()

Start recording if conditions allows: - We must be using Skylink Media Relay. - Recording should not be already started. - We should not have just tried to start recording.

Actual start of recording will be notified via relevant callback on the RecordingListener.

Returns
  • True if we tried to signal Recording Server to start recording, false otherwise.

public boolean stopRecording ()

Stop recording if conditions allows: - We must be already be recording. - We should not have just tried to stop recording.

Actual stop of recording will be notified via relevant callback on the RecordingListener.

Returns
  • True if we tried to signal Recording Server to stop recording, false otherwise.

public void switchCamera ()

Call this method to switch between available camera. Outcome of operation delivered via callback at LifeCycleListener.onReceiveLog, with 3 possible Info: -- Info.CAM_SWITCH_FRONT (successfully switched to the front camera) -- Info.CAM_SWITCH_NON_FRONT (successfully switched to a non front camera) -- Info.CAM_SWITCH_NO (camera could not be switched)

public boolean toggleCamera (boolean restart)

Stop or restart the local camera based on the parameter |restart|, given that the local video source is available, i.e., had been started and not removed. However, if the intended state of the camera (started or stopped) is already the current state, then no change will be effected. Trigger LifeCycleListener.onWarning if an error occurs, for e.g. with: errorCode VIDEO_UNABLE_TO_SWITCH_CAMERA_ERROR if local video source is not available.

Returns
  • True if camera state had changed, false if not.

public boolean toggleCamera ()

Stop or restart the local camera given that the local video source is available, i.e., had been started and not removed. When camera is toggled to stopped, it is accessible by other apps, for e.g. it can be used to take pictures. Toggling camera off and on is slower than muting and unmuting, however no video packets will be sent when camera is toggled off, unlike muting where black video frames (consuming bandwidth) are still sent. Trigger LifeCycleListener.onWarning if an error occurs, for e.g. with: errorCode VIDEO_UNABLE_TO_SWITCH_CAMERA_ERROR if local video source is not available.

Returns
  • True if local camera has been restarted, false if it has been stopped.

public void unlockRoom ()

Unlocks the room if its already locked