new Xpush(host, appId, eventHandler, autoInitFlag)
Constructor of Xpush
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
host |
string | address of session server to connect |
|
appId |
string | application id |
|
eventHandler |
string |
<optional> |
a function for processing the session event |
autoInitFlag |
boolean |
<optional> |
flag for whether to automatically initialize |
Examples
// Create new Xpush Object var xpush = new Xpush( 'http://demo.stalk.io:8000', 'sample' );
// Create new Xpush Object with event Handler
var xpush = new Xpush( 'http://demo.stalk.io:8000', 'sample', function (type, data){
console.log( " type : ", type );
console.log( " data : ", data );
});
Methods
-
<static> addUserToGroup(groupId, userIds, cb)
-
Add a group id to one or multiple users.
Parameters:
Name Type Argument Description groupIdstring <optional>
userId
userIdsarray users array to add
cbcallback callback function to be performed after add
Example
xpush.addUserToGroup( 'james', ['notdol','john'], function( err, result ){ console.log( result ); )}; -
<static> createChannel(users, channel, datas, cb)
-
Generates a new channel.
Parameters:
Name Type Argument Description usersstring userId array to invite channel
channelstring <optional>
Channel Id
datasObject <optional>
JSON for additional channel information
cbcallback callback function to be performed after generate
Examples
// create random channel without data xpush.createChannel(['james', 'notdol'], function(err, data){ console.log( 'create channel success : ', data); });// create a channel without data xpush.createChannel(['james'], 'channel02', function(err,data){ console.log( 'create channel success : ', data); });// create a channel with data xpush.createChannel(['james'], 'channel03', {'NM':'james'}, function(err,data){ console.log( 'create channel success : ', data); }); -
<static> createSimpleChannel(channel, userObj, cb)
-
Generate a new
CHANNEL_ONLYchannel.Parameters:
Name Type Argument Description channelstring Channel Id
userObjObject <optional>
UserObject( U : userID, D : deviceId )
cbcallback callback function to be performed after generate
Examples
// create simple channel without userObject xpush.createSimpleChannel('channel01', function(){ console.log( 'create simple channel success' ); });// create simple channel with userObject xpush.createSimpleChannel('channel02', {'U':'james','D':'WEB'}, function(){ console.log( 'create simple channel success' ); }); -
<static> disableDebug()
-
disable debugging
Example
// disable debug xpush.disableDebug();
-
<static> enableDebug()
-
enable debugging
Example
// enable debug xpush.enableDebug();
-
<static> exitChannel(channel, cb)
-
Exit from the channel
Parameters:
Name Type Description channelstring Channel Id
cbcallback callback function to be performed after exit
Example
xpush.exitChannel( 'channel03', function(err, result){ console.log( 'result : ', result); }); -
<static> getChannel(channel) → {Object}
-
Get the current channel information in xpush object.
Parameters:
Name Type Description channelstring Channel Id
Returns:
return Channel Object
- Type
- Object
Example
var channel01 = xpush.getChannel('channel01'); -
<static> getChannelData(channel, cb)
-
Query the channel information of the server.
Parameters:
Name Type Description channelstring Channel Id
cbcallback callback function to be performed after query
Example
xpush.getChannelData( channel, function(err,data){ console.log( 'retrieve channel success : ', data); }); -
<static> getChannels(cb)
-
Query the channel list from the server.
Parameters:
Name Type Description cbcallback callback function to be performed after query
Example
// Get channels xpush.getChannels(function(err,datas){ console.log( 'channels : ' + datas ); }); -
<static> getChannelsActive(data, cb)
-
The channel list where the user is connected to the current channel will be viewed in redis.
Parameters:
Name Type Description dataObject ( 'key': '' )
cbcallback callback function to be performed after retrieve
Example
// Retrieve channels that start with channel xpush.getChannelsActive( {'key':'channel*'}, function(results){ console.log( 'results : ', results ); }); -
<static> getFileUrl(channel, fileName) → {string}
-
Get the file url which is uploaded completely
Parameters:
Name Type Description channelstring Channel Id
fileNamestring received return name after file uploading
Returns:
url where you can download the file
- Type
- string
Example
var url = xpush.getFileUrl( 'channel03', data.result.name )
-
<static> getGroupUsers(groupId, cb)
-
Query the user list on the server that contains the group.
Parameters:
Name Type Description groupIdstring Find groupId
cbcallback callback function to be performed after query
Example
xpush.getGroupUsers( 'james', function( err, users ){ console.log( users ); )}; -
<static> getUnreadMessage(cb)
-
Query the unread server message. After inquiry, call the
message-receivedAPI to delete the viewed message.Parameters:
Name Type Description cbcallback callback function to be performed after query
Example
xpush.getUnreadMessage( function(err, result){ console.log( result ); }); -
<static> getUserList(params, cb)
-
Query the user list from the server.
Parameters:
Name Type Argument Description paramsObject <optional>
param for search user.
cbfunction callback function to be performed after query
Example
xpush.getUserList( {'page':{'num':1,'size':10} },function(err, users){ console.log( users ); }); -
<static> isExistChannel(channel) → {boolean}
-
confirm whether channel is exist or not
Parameters:
Name Type Description channelstring Channel Id
Returns:
- Type
- boolean
Example
var isExist = xpush.isExistChannel('channel03'); -
<static> joinChannel(channel, param, cb)
-
Join to the channel.
Parameters:
Name Type Description channelstring Channel Id
paramObject JSON Data ( U, DT )
cbcallback callback function to be performed after join
Example
xpush.joinChannel( 'channel03', {'U':['notdol']}, function(result){ console.log( 'result : ', result); }); -
<static> login(userId, password, deviceId, mode, cb)
-
Login user using the userId and password.
Parameters:
Name Type Argument Default Description userIdstring User Id
passwordstring Password
deviceIdstring <optional>
WEB Device Id
modestring <optional>
mode
cbcallback callback function to be performed after login
Examples
xpush.login( 'james', '1234', function(err,data){ console.log('register success : ', data); });// login with deviceId xpush.login( 'james', '1234', 'android', function(err,data){ console.log('login success : ', data); }); -
<static> logout()
-
Disconnect the session socket and channel socket.
Example
// logout xpush.logout();
-
<static> off(event, function)
-
Removes the event and function in the event stack
Parameters:
Name Type Description eventstring key
functionfunction Example
xpush.off( 'message', function(channel, name, data){ console.log( channel, name, data ); }); -
<static> off(event, function)
-
Remove all event on the event stack.
Parameters:
Name Type Description eventstring key
functionfunction Example
xpush.clearEvent();
-
<static> on(event, function)
-
Register the event and function to the event stack. The specified function is event is called the event.
Parameters:
Name Type Description eventstring key
functionfunction Example
xpush.on( 'message', function(channel, name, data){ console.log( channel, name, data ); }); -
<static> queryUser(_params, cb)
-
Query the user list from the server. Paging is possible.
Parameters:
Name Type Description _paramsObject ( query, column )
cbcallback callback function to be performed after query
Example
var param = {query : {'DT.NM':'james'}, column: { U: 1, DT: 1, _id: 0 } }; xpush.queryUser( param, function( err, userArray, count ){ console.log( userArray ); }); -
<static> removeUserFromGroup(groupId, userId, cb)
-
Delete the user from the group.
Parameters:
Name Type Argument Description groupIdstring <optional>
userId
userIdstring user's ID to delete
cbcallback callback function to be performed after delete
Example
xpush.removeUserFromGroup( 'james', 'notdol', function( err, result ){ console.log( result ); )}; -
<static> send(channel, name, data)
-
Transmits the data.
Parameters:
Name Type Description channelstring Channel Id
namestring EventName
dataObject String or JSON object to Send
Example
xpush.send( 'ch01', 'message', {'MG':'Hello world'} ); -
<static> setSessionInfo(userId, deviceId, cb)
-
Set the userId and deviceId to current xpush object. only if the session socket is already connected
Parameters:
Name Type Argument Description userIdstring User Id
deviceIdstring <optional>
Device Id
cbcallback callback function to be performed after set
Examples
// Set session info xpush.setSessionInfo( 'james', function(){} );// Set session info with deviceId xpush.setSessionInfo( 'james', 'WEB', function(){} ); -
<static> signup(userId, password, deviceId, cb)
-
Register user using the userId and password.
Parameters:
Name Type Argument Default Description userIdstring User Id
passwordstring Password
deviceIdstring <optional>
WEB Device Id
cbcallback callback function to be performed after register
Example
// Add new user xpush.signup( 'james', '1234', function(err,data){ console.log('register success : ' + data); }); -
<static> updateChannel(channel, query, cb)
-
Modify the channel information of the server.
Parameters:
Name Type Description channelstring Channel Id
queryObject mongo DB query form as a JSON
cbcallback callback function to be performed after modify // update channel
Example
xpush.updateChannel( 'channel02', { $set:{'DT':{'NM':'notdol1'}}}, function(err, result){ console.log( 'result : ', result ); }); -
<static> uploadFile(channel, fileUri, inputObj, fnPrg, fnCallback)
-
Upload files using the REST API because the mobile is not supported file dom object
Parameters:
Name Type Description channelstring Channel Id
fileUristring fileUri to upload
inputObjObject JSON Objec( 'type' : '', 'name' : Original File name )
fnPrgfunction function to show the upload progress
fnCallbackcallback callback function to be performed after upload
Example
xpush.uploadFile('channelId', 'content://media/external/images/media/636', {type : 'image', name:'image.png' }, function ( data ){ console.log( data ); }, function (data){ console.log( data.response ); }); -
<static> uploadStream(channel, inputObj, fnPrg, fnCallback)
-
Upload the file DOM object using the socket stream to
Parameters:
Name Type Description channelstring Channel Id
inputObjObject JSON Objec( 'file' : file DOM Oject for upload, 'type' : '' )
fnPrgfunction function to show the upload progress
fnCallbackcallback callback function to be performed after upload
Example
var fileObj = document.getElementById('file'); xpush.uploadStream( 'channel03', { file: fileObj }, function(data, idx){ console.log( 'progress : ' + data ); }, function(data,idx){ console.log( 'upload result : ' + data ); }); -
<private, static> XPush#emit(event)
-
Call a function that is registered in the event stack. When unread message exists, message will be stacked without causing the function of that event soon because it is being initialized status.
Parameters:
Name Type Description eventstring key
-
<static> XPush#getChannelAsync(channel, cb)
-
Bring the channel information asynchronously. If the channel information is not present in the object, it queries the channel information from the server.
Parameters:
Name Type Description channelstring Channel Id
cbcallback callback function to be performed after get
Example
xpush.getChannelAsync( 'channel03', function(err, result){ console.log( 'result : ', result); });