Android SDK API Reference

Classes | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
io.skyway.Peer.Peer Class Reference

Peer class. More...

Classes

enum  DebugLevelEnum
 Debug output level. More...
 
enum  PeerEventEnum
 Event callback type. More...
 
enum  PeerTypeEnum
 

Public Member Functions

String identity ()
 Get the current Peer ID. More...
 
boolean isDisconnected ()
 Get the disconnection state. More...
 
boolean isDestroyed ()
 Get the disconnection state. More...
 
Context getContext ()
 Get the context for the creation of a Peer object. More...
 
DebugLevelEnum getDebugLevel ()
 Get the current debug level. More...
 
 Peer (Context context, PeerOption options)
 Create a Peer object. More...
 
 Peer (Context context, String peerId, PeerOption options)
 Initialization will be performed with the specified Peer ID and configuration information. More...
 
void finalize ()
 
void on (PeerEventEnum event, OnCallback callback)
 Sets the event callback block for the Peer. More...
 
void disconnect ()
 (deprecated) Disconnect the connection to the signaling server. More...
 
void reconnect ()
 (deprecated) Reconnect to the signaling server. More...
 
void destroy ()
 Close the connection to the signaling server and the already connected mediaConnection and dataConnection. More...
 
void listAllPeers (OnCallback callback)
 Obtain a list of available Peer IDs from the signaling server. More...
 
void fetchPeerExists (String peerId, OnCallback successCallback, OnCallback errorCallBack)
 Fetch whether Peer specified by Peer ID exists from the signaling server. More...
 
DataConnection connect (String peerId)
 Make a data connection to the specified remote and return a DataConnection. More...
 
DataConnection connect (String peerId, ConnectOption option)
 Make a data connection to the specified remote and return a DataConnection. More...
 
MediaConnection call (String peerId, MediaStream stream)
 Makes a media connection to the specified remote and returns a MediaConnection. More...
 
MediaConnection call (String peerId, MediaStream stream, CallOption option)
 Makes a media connection to the specified remote and returns a MediaConnection. More...
 
Room joinRoom (String roomName, RoomOption option)
 Join room. More...
 
void updateCredential (PeerCredential newCredential)
 update credential More...
 
EglBase getEglBase ()
 
MediaStream getUserMedia (MediaConstraints constraints)
 
MediaStream getDisplayMedia (MediaConstraints constraints, Intent mediaProjectionPermissionResultData, MediaProjection.Callback mediaProjectionCallback)
 

Static Public Member Functions

static String getSdkVersion ()
 Getting current SDK version. More...
 

Public Attributes

final Map< String, ArrayList< BaseConnection > > connections = new HashMap<>()
 Connection connection management object. More...
 

Detailed Description

Peer class.

Constructor & Destructor Documentation

◆ Peer() [1/2]

io.skyway.Peer.Peer.Peer ( Context  context,
PeerOption  options 
)

Create a Peer object.

The peer ID is obtained from the server.

Context context = getApplicationContext();
SKWPeerOption options = new SKWPeerOption();
options.key = "{your-dev-key}";
options.domain = ”{your-domain}”;
options.debug = Peer.DebugLevelEnum.ALL_LOGS;
options.turn = true;
options.tryReconnectMedia = true;
options.tryReconnectData = true;
Peer peer = new Peer(context, options)
Parameters
context
options

◆ Peer() [2/2]

io.skyway.Peer.Peer.Peer ( Context  context,
String  peerId,
PeerOption  options 
)

Initialization will be performed with the specified Peer ID and configuration information.

Context context = getApplicationContext();
SKWPeerOption options = new SKWPeerOption();
options.key = "{your-dev-key}";
options.domain = ”{your-domain}”;
options.debug = Peer.DebugLevelEnum.ALL_LOGS;
options.turn = true;
options.tryReconnectMedia = true;
options.tryReconnectData = true;
Peer peer = new Peer(context, null, options)
Parameters
contextSpecify an ApplicationContext object.
peerId
optionsSet the ConnectOption object.

Member Function Documentation

◆ call() [1/2]

MediaConnection io.skyway.Peer.Peer.call ( String  peerId,
MediaStream  stream 
)

Makes a media connection to the specified remote and returns a MediaConnection.

In case of failure, an error event is thrown. Connect with the default connection options.

Peer peer;
String destId;
Navigator.initialize(peer);
MediaConstraints constraints = new MediaConstraints();
MediaStream stream = Navigator.getUserMedia(constraints);
MediaConnection media = peer.call(destId, stream);
Parameters
peerIdThe Peer ID of the remote
streamSets the MediaStream retrieved by getUserMedia() of the Navigator class; if null, no video or audio from the own device will be sent to the other party.
Returns
MediaConnection Object

◆ call() [2/2]

MediaConnection io.skyway.Peer.Peer.call ( String  peerId,
MediaStream  stream,
CallOption  option 
)

Makes a media connection to the specified remote and returns a MediaConnection.

In case of failure, an error event is raised. Connect with the configuration information.

Peer peer;
String destId;
Navigator.initialize(peer);
MediaConstraints constraints = new MediaConstraints();
MediaStream stream = Navigator.getUserMedia(constraints);
CallOption options = new CallOption();
options.metadata = "yourMetadata";
MediaConnection media = peer.call(destId, stream, options);
Parameters
peerIdThe Peer ID of the remote
streamSets the MediaStream retrieved by getUserMedia() of the Navigator class; if null, no video or audio from the own device will be sent to the other party.
optionSet ConnectOption Object
Returns
MediaConnection Object

◆ connect() [1/2]

DataConnection io.skyway.Peer.Peer.connect ( String  peerId)

Make a data connection to the specified remote and return a DataConnection.

In case of failure, an error event is invoked. The connection is made with the default settings.

Peer peer;
String destId;
DataConnection data = peer.connect(destId);
Parameters
peerIdThe Peer ID to connect to
Returns
DataConnection Object

◆ connect() [2/2]

DataConnection io.skyway.Peer.Peer.connect ( String  peerId,
ConnectOption  option 
)

Make a data connection to the specified remote and return a DataConnection.

In case of failure, an error event is called. The connection is made with configuration information.

Peer peer;
String destId;
ConnectOption options = new ConnectOption();
options.label = "chat";
options.metadata = "hi !!!";
options.serialization = DataConnection.SerializationEnum.NONE;
DataConnection data = peer.connect(destId, options);
Parameters
peerIdThe Peer ID to connect to
optionSets the ConnectOption object.
Returns
DataConnection Object

◆ destroy()

void io.skyway.Peer.Peer.destroy ( )

Close the connection to the signaling server and the already connected mediaConnection and dataConnection.

Peer peer;
peer.destroy();

◆ disconnect()

void io.skyway.Peer.Peer.disconnect ( )

(deprecated) Disconnect the connection to the signaling server.

In addition, the connected mediaConnection and dataConnection are continued.

Deprecated:
Use peer's destroy method or close method instead.

◆ fetchPeerExists()

void io.skyway.Peer.Peer.fetchPeerExists ( String  peerId,
OnCallback  successCallback,
OnCallback  errorCallBack 
)

Fetch whether Peer specified by Peer ID exists from the signaling server.

Peer peer;
String peerId;
peer.fetchPeerExists(peerId, new OnCallback() {
@Override public void onCallback(Object object) {
boolean exists = (boolean)object;
}
}, new OnCallback() {
@Override public void onCallback(Object object) {
String error = (String)object;
}
}
);
Parameters
peerIdSpecify the Peer ID of the Peer whose existence you want to check.
successCallbackSet the callback object to be executed when the existence of Peer is fetched.
errorCallbackSet the callback object to be executed when an error is occured.

◆ getContext()

Context io.skyway.Peer.Peer.getContext ( )

Get the context for the creation of a Peer object.

Returns
context

◆ getDebugLevel()

DebugLevelEnum io.skyway.Peer.Peer.getDebugLevel ( )

Get the current debug level.

Returns
debugging level

◆ getSdkVersion()

static String io.skyway.Peer.Peer.getSdkVersion ( )
static

Getting current SDK version.

Returns
Version number

◆ identity()

String io.skyway.Peer.Peer.identity ( )

Get the current Peer ID.

Returns
Peer ID

◆ isDestroyed()

boolean io.skyway.Peer.Peer.isDestroyed ( )

Get the disconnection state.

Returns

◆ isDisconnected()

boolean io.skyway.Peer.Peer.isDisconnected ( )

Get the disconnection state.

Returns

◆ joinRoom()

Room io.skyway.Peer.Peer.joinRoom ( String  roomName,
RoomOption  option 
)

Join room.

Full mesh room example:

Peer peer;
MediaStream localStream;
String roomName = "fullmesh_videochat_room";
RoomOption options = new RoomOptions();
options.mode = RoomOption.RoomModeEnum.MESH;
options.stream = localStream;
MeshRoom meshRoom = peer.join(roomName, options);

SFU room example:

Peer peer;
String roomName = "sfu_textchat_room";
RoomOption options = new RoomOptions();
options.mode = RoomOption.RoomModeEnum.SFU;
SFURoom sfuRoom = peer.join(roomName, options);
Parameters
roomNameRoom name
optionRoom option
Returns
Room object

◆ listAllPeers()

void io.skyway.Peer.Peer.listAllPeers ( OnCallback  callback)

Obtain a list of available Peer IDs from the signaling server.

an ArrayList of strings is passed.

Peer peer;
peer.listAllPeers(new OnCallback() {
@Override public void onCallback(Object object) {
ArrayList<String> list = (ArrayList<String>)object;
}
});
Parameters
callbackSet the callback object to be executed when the list acquisition is completed.

◆ on()

void io.skyway.Peer.Peer.on ( PeerEventEnum  event,
OnCallback  callback 
)

Sets the event callback block for the Peer.

Peer peer;
peer.on(Peer.PeerEventEnum.OPEN, new OnCallback() {
@Override
public void onCallback(Object object) {
String ownId = (String)object;
}
});
peer.on(Peer.PeerEventEnum.CONNECTION, new OnCallback() {
@Override
public void onCallback(Object object) {
DataConnection data = (DataConnection)object;
}
});
peer.on(Peer.PeerEventEnum.CALL, new OnCallback() {
@Override
public void onCallback(Object object) {
MediaConnection media = (MediaConnection)object;
}
});
peer.on(Peer.PeerEventEnum.CLOSE, new OnCallback() {
@Override
public void onCallback(Object object) {
// 処理を記述
}
});
peer.on(Peer.PeerEventEnum.DISCONNECTED, new OnCallback() {
@Override
public void onCallback(Object object) {
// 処理を記述
}
});
peer.on(Peer.PeerEventEnum.ERROR, new OnCallback() {
@Override
public void onCallback(Object object) {
PeerError error = (PeerError)object;
}
});
Parameters
eventSet the event type to be set.
callbackSet the callback object to be executed when the event occurs.

◆ reconnect()

void io.skyway.Peer.Peer.reconnect ( )

(deprecated) Reconnect to the signaling server.

Use the assigned Peer ID when reconnecting.

Deprecated:
Recreate peer instance instead.

◆ updateCredential()

void io.skyway.Peer.Peer.updateCredential ( PeerCredential  newCredential)

update credential

Peer peer;
PeerCredential credential = new PeerCredential();
credential.timestamp = System.currentTimeMillis();
credential.ttl = 86400;
credential.authToken = "calculated auth token";
peer.updateCredential(credential);
Parameters
newCredentialnew credential

Member Data Documentation

◆ connections

final Map<String, ArrayList<BaseConnection> > io.skyway.Peer.Peer.connections = new HashMap<>()

Connection connection management object.

A hash with the ID of a remote Peer as the key and the connection sequence to be associated with the Peer.

io.skyway.Peer.Peer.Peer
Peer(Context context, PeerOption options)
Create a Peer object.
Definition: Peer.java:317