Samples

Description samples for testing.

PTTPluginSample

CryptoPlugin Sampleversion 4.3.0
Server 8.0.0~
Down
AdminWebPlugin2 Sampleversion 4.2.0
Server 6.3.1~
Down
AdminWebPlugin Sampleversion 4.1.0
Server 6.3.0~
Down
PublicGWPlugin Sampleversion 4.0.0
Server 6.1.1~
Down
PTTPlugin4 Sampleversion 4.0.0
Server 6.0.2~
Down
PTTPlugin3 Sampleversion 3.0.0
Server 5.1.0~
Down
PTTPlugin2.1 Sampleversion 2.1.0
Server 5.0.2~
Down
PTTPlugin2 Sampleversion 2.0.0
Server 3.3.0~
Down
PTTPlugin Sampleversion 1.0.0Down

PTTPlugin4Sample.java for V4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import com.imptt.proptt.pttserver.plugins.V4.*;
import java.sql.*;
 
public class PTTPlugin4Sample implements IPTTPlugin4
{
    ICallback3 cbObject = null;
    public int getInterfaceVersion()
    {
        System.out.println("PTTPlugin4Sample::getInterfaceVersion");
        return INTERFACE_VERSION;
    }
     
    public int getType()
    {
        System.out.println("PTTPlugin4Sample::getType");
        return TYPE_GENERAL_PLUGIN;
    }
     
    public void setCallback(ICallback4 cbObject)
    {
        System.out.println("PTTPlugin4Sample::setCallback cbObject="+cbObject);
        this.cbObject = cbObject;
    }
     
    public boolean initialize(String arg)
    {
        System.out.println("PTTPlugin4Sample::initialize arg="+arg);
        Connection conn = cbObject.getDBConnection();
        if(conn != null)
        {
            int dbSchemaVersion = 0;
            Statement stmt = null;
            try
            {
                stmt = conn.createStatement();
                String sqlStr = "SELECT TextValue FROM TB_Setup WHERE TextKey='db.schema.version'";
                ResultSet rs = stmt.executeQuery(sqlStr);
                if(rs.next())
                {
                    dbSchemaVersion = rs.getInt(1);
                }
            }
            catch (Exception e)
            {
                System.out.println(e.getMessage());
            }
            if ( stmt != null ) try { stmt.close(); }catch (Exception e){}
            System.out.println("PTTPlugin4Sample::initialize dbSchemaVersion="+dbSchemaVersion);
        }
        if(cbObject!=null) cbObject.OnInitialized();
        return true;
    }
     
 
    //events
    public void OnConnected(String userId, String jsonParams)
    {
        System.out.println("PTTPlugin4Sample::OnConnected userId="+userId+", jsonParams="+jsonParams);
    }
     
    public void OnJoined(String userId, int channelId)
    {
        System.out.println("PTTPlugin4Sample::OnJoined userId="+userId+", channelId="+channelId);
    }
     
    public void OnLocked(String userId, int channelId, int lockIndex, int mediaProfileId, String userLocation, String audioCodec, String videoCodec, String encKey, String jsonParams)
    {
        System.out.println("PTTPlugin4Sample::OnLocked userId="+userId+", channelId="+channelId+", jsonParams="+jsonParams);
    }
 
    public void OnPTT(int channelId, int lockIndex, byte[] frames)
    {
        System.out.println("PTTPlugin4Sample::OnPTT channelId="+channelId+", frames.length="+frames.length);
    }
 
    public void OnUnLocked(String userId, int channelId, int lockIndex)
    {
        System.out.println("PTTPlugin4Sample::OnUnlocked userId="+userId+", channelId="+channelId);
    }
     
    public void OnVideoShare(String userId, int channelId, int videoChannelId, String jsonParams)
    {
        System.out.println("PTTPlugin4Sample::OnVideoShare userId="+userId+", channelId="+channelId+", videoChannelId="+videoChannelId+", jsonParams="+jsonParams);
    }
 
    public void OnVideoShared(String userId, int channelId, int videoChannelId)
    {
        System.out.println("PTTPlugin4Sample::OnVideoShared userId="+userId+", channelId="+channelId+", videoChannelId="+videoChannelId);
    }
 
    public void OnVideoUnshare(String userId, int channelId, int videoChannelId, String jsonParams)
    {
        System.out.println("PTTPlugin4Sample::OnVideoUnshare userId="+userId+", channelId="+channelId+", videoChannelId="+videoChannelId+", jsonParams="+jsonParams);
    }
 
    public void OnVideoUnshared(String userId, int channelId, int videoChannelId)
    {
        System.out.println("PTTPlugin4Sample::OnVideoUnshared userId="+userId+", channelId="+channelId+", videoChannelId="+videoChannelId);
    }
     
    public void OnFileShare(String userId, int channelId, int fileChannelId, String jsonParams)
    {
        System.out.println("PTTPlugin4Sample::OnFileShare userId="+userId+", channelId="+channelId+", fileChannelId="+fileChannelId+", jsonParams="+jsonParams);
    }
 
    public void OnFileShared(String userId, int channelId, int fileChannelId)
    {
        System.out.println("PTTPlugin4Sample::OnFileShared userId="+userId+", channelId="+channelId+", fileChannelId="+fileChannelId);
    }
 
    public void OnFileUnshare(String userId, int channelId, int fileChannelId, String jsonParams)
    {
        System.out.println("PTTPlugin4Sample::OnFileUnshare userId="+userId+", channelId="+channelId+", fileChannelId="+fileChannelId+", jsonParams="+jsonParams);
    }
 
    public void OnFileUnshared(String userId, int channelId, int fileChannelId)
    {
        System.out.println("PTTPlugin4Sample::OnFileUnshared userId="+userId+", channelId="+channelId+", fileChannelId="+fileChannelId);
    }
 
    public void OnText(String userId, int channelId, int messageId, String base64Message)
    {
        System.out.println("PTTPlugin4Sample::OnText userId="+userId+", channelId="+channelId+", messageId="+messageId+", base64Message="+base64Message);
    }
     
    public void OnCustomMessage(String userId, int channelId, int messageId, String base64Message)
    {
        System.out.println("PTTPlugin4Sample::OnCustomMessage userId="+userId+", channelId="+channelId+", messageId="+messageId+", base64Message="+base64Message);
    }
     
    public void OnFunction(String userId, int channelId, String latitude, String longitude, String functionName, String jsonParams)
    {
        System.out.println("PTTPlugin4Sample::OnFunction userId="+userId+", channelId="+channelId+", functionName="+functionName+", jsonParams="+jsonParams);
    }
     
    public void OnLocation(String userId, String latitude, String longitude)
    {
        System.out.println("PTTPlugin4Sample::OnLocation userId="+userId+", latitude="+latitude+", longitude="+longitude);
    }
     
    public void OnLeaved(String userId, int channelId)
    {
        System.out.println("PTTPlugin4Sample::OnLeaved userId="+userId+", channelId="+channelId);
    }
     
    public void OnDisconnected(String userId)
    {
        System.out.println("PTTPlugin4Sample::OnDisconnected userId="+userId);
    }
 
    public void OnClientDirectMessage(String userId, String message)
    {
        System.out.println("PTTPlugin4Sample::OnClientDirectMessage userId="+userId+"  message="+message);
        cbObject.sendToUser(userId, message);
    }
 
    public void OnError(int errCode, String jsonParams)
    {
        System.out.println("PTTPlugin4Sample::OnError errCode="+errCode+", jsonParams="+jsonParams);
    }
     
    public void OnExtenedEvent(String cmdName, String jsonParams)
    {
        System.out.println("PTTPlugin4Sample::OnExtenedEvent cmdName="+cmdName+", jsonParams="+jsonParams);
    }
     
}
 
                

2FA(Two-Factor Authentication) by email/SMS

Basic flow

AdminWebPluginSample.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import com.imptt.proptt.adminweb.plugins.V2.*;
import java.sql.*;
 
public class AdminWebPluginSample implements IAdminWebPlugin2
{
    ICallback2 cbObject = null;
    public int getInterfaceVersion()
    {
        System.out.println("AdminWebPluginSample::getInterfaceVersion");
        return INTERFACE_VERSION;
    }
     
    public int getType()
    {
        System.out.println("AdminWebPluginSample::getType");
        return TYPE_GENERAL_PLUGIN;
    }
     
    public void setCallback(ICallback2 cbObject)
    {
        System.out.println("AdminWebPluginSample::setCallback cbObject="+cbObject);
        this.cbObject = cbObject;
    }
     
    public boolean initialize(String arg)
    {
        System.out.println("AdminWebPluginSample::initialize arg="+arg);
        Connection conn = cbObject.getDBConnection();
        if(conn != null)
        {
            int dbSchemaVersion = 0;
            Statement stmt = null;
            try
            {
                stmt = conn.createStatement();
                String sqlStr = "SELECT TextValue FROM TB_Setup WHERE TextKey='db.schema.version'";
                ResultSet rs = stmt.executeQuery(sqlStr);
                if(rs.next())
                {
                    dbSchemaVersion = rs.getInt(1);
                }
            }
            catch (Exception e)
            {
                System.out.println(e.getMessage());
            }
            if ( stmt != null ) try { stmt.close(); }catch (Exception e){}
            System.out.println("AdminWebPluginSample::initialize dbSchemaVersion="+dbSchemaVersion);
        }
        if(cbObject!=null) cbObject.OnInitialized();
        return true;
    }
     
 
    //events
     
    public String autheticate(PTTUser2 user, String hashedPassword, boolean passwordVerified, String device, String os, String app, String peerIp, String token)
    {
        System.out.println("AdminWebPluginSample::autheticate userId="+user.strID+", passwordVerified="+passwordVerified);
        if(passwordVerified==false) return "failure";
        if(app.startsWith("ProGate/")) return "success"; //ProGate don't support 2FA(Two-Factor Authentication)
        if(token.isEmpty()) return "required";
        if(token.equals("1234")) {
            //you can save the one time session key("5678") to TB_User's AuthToken field
            return "5678"; //one time session key
        }
        if(token.equals("5678")) return "success";
        if(token.equals("retry")) {
            //have to send new token to user
        }
        if(user.strPlainPassword != null && user.strPlainPassword.isEmpty()==false) { //case of only secure login
            //Check SSO
        }
        return "required";
    }
 
    public boolean allocVideoServer(PTTUser2 user, String hashedPassword, boolean passwordVerified, String peerIp, String token)
    {
        if(user.strPlainPassword != null && user.strPlainPassword.isEmpty()==false) { //case of only secure login
            //Check SSO
        }
        return true;
    }   
 
    public void OnError(int errCode, String jsonParams)
    {
        System.out.println("AdminWebPluginSample::OnError errCode="+errCode+", jsonParams="+jsonParams);
    }
     
    public void OnExtenedEvent(String cmdName, String jsonParams)
    {
        System.out.println("AdminWebPluginSample::OnExtenedEvent cmdName="+cmdName+", jsonParams="+jsonParams);
    }
     
}