TestWith Guide




테스트위드의 다양한 기능을 실제로 사용하는 이미지


    HTML
    copy!
    <script src = "https://www.testwith.io/static/js/testwith_api.js"></script>
    JavaScript
    copy!
    const serviceId = "string";         
    const tw = new Testwith(serviceId);
    JavaScript
    copy!
    tw.loadTestwith().then(() => {
      
    }).catch(err => {
      console.error('자원 로드 중 오류 발생:', err);
    });
Important

serviceId string

Python
copy!
def get_token():
  headers = {
    "Content-Type": 'application/json; charset=utf-8' ,
  }

  body = {
    "apiKey": {apiKey},        # api key (from TestWith)
    "apiSecret": {apiSecret},  # api secret (from TestWith)
    "serviceId": {serviceId}   # service id (from TestWith)
  }

  URL = f'https://www.testwith.io/services/token'
  response = requests.post(URL, headers=headers, json=body)
  if response.status_code == 200:
    return response.json()
  else:
    return response.json()
Info

API URL

HTTP
copy!
https://www.testwith.io/services/token

API Header

Mandatory Description
Content-Type Mandatory

JSON
copy!
{
    "apiKey": "string",
    "apiSecret": "string",
    "serviceId": "string"
}
apiKey string
apiSceret string
serviceId string

JSON
copy!
{
    "access": "string",
    "exp": "int",
    "now": "int",
    "resultCode": "int",
    "resultMsg": "string"
}
access string
exp int timestamp
now int timestamp
resultCode int
resultMsg string

JavaScript
copy!
tw.getTestCenterList(parameter)
Info

Object
copy!
{
    "token": "string"
}
token string Y

JSON
copy!
{
    "resultCode": "int",
    "resultMsg": "string",
    "resultData":
   [{
       "id": "string",
       "testId": "string",
       "title": "string"
    }, ...]
}
resultCode int
resultMsg string
resultData Array
id string
testId string
title string

JavaScript
copy!
tw.getTestCenter(parameter)
Info

Object
copy!
{
    "token": "string",
    "testId": "string"
}
token string Y
testId string Y

JSON
copy!
{
    "resultCode": "int",
    "resultMsg": "string",
    "resultData":
   [{
       "id": "string",
       "testId":"string",
       "title":"string",
    }, ...]
}
resultCode int
resultMsg string
resultData Array
id string
testId string
title string

JavaScript
copy!
tw.createTestCenter(parameter)
Info

Object
copy!
{
    "token": "string",
    "title": "string"
}
token string Y
title string Y

JSON
copy!
{
    "resultCode": "int",
    "resultMsg": "string",
    "resultData":
   {
       "testId": "string"
    }
}
resultCode int
resultMsg string
resultData Array
testId string

JavaScript
copy!
tw.updateTestCenter(parameter)
Info

Object
copy!
{
    "token": "string",
    "testId": "string",
    "title": "string"
}
token string Y
testId string Y
title string Y

JSON
copy!
{
    "resultCode": "int",
    "resultMsg": "string"
}
resultCode int
resultMsg string

JavaScript
copy!
tw.getStudentList(parameter)
Info

요청 파라미터

Object
copy!
{
    "token":"string",
    "testId":"string"
}
token string Y
testId string Y

JSON
copy!
{
    "resultCode":"int",
    "resultMsg":"string",
    "resultData":
   [{
       "userId": "int",
       "testId": "string",
       "userNum": "string",
       "name": "string",
       "email": "string",
       "face": "string",
       "assist": "int",
       "confirmed": "string",
       "audioId": "string",
       "deviceId": "string",
       "stream": "string",
       "screen": "string",
       "mstream": "string"
    }, ...]
}
resultCode int
resultMsg string
resultData Array
userId int
testId string
userNum string
name string
email string
face string
assist int
confirmed string
audioId string
deviceId string
stream string
screen string
mstream string

JavaScript
copy!
tw.getStudent(parameter)
Info

Object
copy!
{
    "token":"string",
    "testId":"string",
    "userId":"int"
}
token string Y
testId string Y
userId int Y

JSON
copy!
{
    "resultCode":"int",
    "resultMsg":"string",
    "resultData":
   [{
       "userId": "int",
       "testId": "string",
       "userNum": "string",
       "name": "string",
       "email": "string",
       "face": "string",
       "assist": "int",
       "audioId": "string",
       "deviceId": "string",
       "stream": "string",
       "screen": "string",
       "mstream": "string"
    }, ...]
}
resultCode int
resultMsg string
resultData array
userId int
testId string
userNum string
name string
email string
face string
assist int
audioId string
deviceId string
stream string
screen string
mstream string

JavaScript
copy!
tw.registerStudent(parameter)
Info

Object
copy!
{
    "token": "string",
    "testId": "string",
    "userNums": [],
    "names": []
}
token string Y
testId string Y
userNums array Y
names array Y

JSON
copy!
{
    "resultCode": "int",
    "resultMsg": "string",
    "resultData": []
}
resultCode int
resultMsg string
resultData array

JavaScript
copy!
tw.updateStudent(parameter)
Info

Object
copy!
{
    "token": "string",
    "testId": "string",
    "userId": "int",
    "userNum": "string",
    "name": "string"
}
token string Y
testId string Y
userId int Y
userNum string Y
name string Y

JSON
copy!
{
    "resultCode": "int",
    "resultMsg": "string"
}
resultCode int
resultMsg string

JavaScript
copy!
tw.createWebcam(parameter)
Info

Object
copy!
{
    "langKey": "",
    "elementId": "",
    "userId": "0000"
}
langKey string N
elementId string N
userId string Y
Important

copy!
tw.onSuccessStream() => {
    console
.log();
    
}
copy!
tw.onFailStream() => {
    console.log();
    
}
Info

JavaScript
copy!
tw.createScreen(parameter)

Object
copy!
{
    "langKey": "",
    "elementId": "",
    "userId": "0000"
}
langKey string N
elementId string N
userId string Y
Important

copy!
tw.onSuccessScreen() => {
    console
.log();
    
}
copy!
tw.onFailScreen() => {
    console.log();
    
}
Info

JavaScript
copy!
tw.createQR_code(parameter)
Info

Object
copy!
{
    "langKey": "",
    "elementId": "",
    "userId": "0000",
    "width": "",
    "height": ""
}
langKey string N
elementId string N
userId string Y
width int N
height int N

JavaScript
copy!
tw.stream_start(parameter)
Info

Object
copy!
{
    "userId": "0000",
    "videoSource": "",
    "audioSource": "",
    "type": "",
    "elementId": ""
}
userId string Y
videoSource string N
audioSource string N
type string N
elementId string N

JavaScript
copy!
tw.connectAI(parameter)
Info

Object
copy!
{
    "deviceId": "0000000"
}
deviceId string Y

JavaScript
copy!
tw.createRegister(parameter)
Info

Object
copy!
{
    "langKey": "",
    "elementId": ""
}
langKey string N
elementId string N
Important

JavaScript
copy!
tw.registFace(parameter).then(data => {
    console.log(data);
});
Info

Object
copy!
{
    "testId": "1234",
    "userId": "0000",
    "videoId": "",
    "valid": ""
}
testId string Y
userId string Y
videoId string N
valid string N

JSON
copy!
{
    "message": "string",
    "result": "int"
}
message string
result int

JavaScript
copy!
tw.setScreenAI(parameter)
Info

Object
copy!
{
    "testId": "1234",
    "userId": "0000",
    "detectOption" = {
      "screenLeave": true,
      "rightClick": true,
      "specialKey": true,
     },
    "recordOption": true
}
testId string Y
userId string Y
detectOption object Y
screenLeave boolean N
rightClick boolean N
specialKey boolean N
recordOption boolean N

{
    "message": "string",
    "result": "int"
}
message string
result int

JavaScript
copy!
tw.screenDetectOption = {
    "screenLeave": true,
    "rightClick": true,
    "specialKey": true
}
screenLeave boolean N
rightClick boolean N
specialKey boolean N
Info

JavaScript
copy!
tw.screenRecordOption = true    // 화면 녹화 설정 => false: 비활성(기본값), true: 활성
Info

JavaScript
copy!
tw.setFaceAI(parameter)
Info

Object
copy!
{
    "testId": "1234",
    "userId": "0000",
    "detectOption" = {
      "existFace": true,
      "multiFace": true,
      "validFace": true,
      "gaze": true,
     },
    "recordOption": true
}
testId string Y
userId string Y
detectOption object Y
existFace boolean N
multiFace boolean N
validFace boolean N
gaze boolean N
recordOption boolean N

{
    "message": "string",
    "result": "int"
}
message string
result int

JavaScript
copy!
tw.faceDetectOption = {
    "existFace": true,
    "multiFace": true,
    "validFace": true
    "gaze": true
}
existFace boolean N
multiFace boolean N
validFace boolean N
gaze boolean N
Info

JavaScript
copy!
tw.faceRecordOption = true;     
Info

JavaScript
copy!
tw.createGazeOptimize(parameter)

Object
copy!
{
    "langKey": "",
    "testId": "1234",
    "userId": "0000",
    "optimizeTime": ""
}
langKey string N
testId string Y
userId string Y
optimizeTime string N

JavaScript
copy!
tw.gazeOptimize(parameter)
Info

Object
copy!
{
    "langKey": "",
    "testId": "1234",
    "userId": "0000",
    "optimizeTime": ""
}
langKey string N
testId string Y
userId string Y
optimizeTime string N

JavaScript
copy!
tw.connectSignal(parameter).then(data => {
    console.log(data);
});
Info

Object
copy!
{
    "langKey": "",
    "testId": "1234",
    "userId": "0000",
    "chatOpen": ""
}
langKey string N
testId string Y
userId string Y
chatOpen string N

{
    "message": "string",
    "result": "int"
}
message string
result int

JavaScript
copy!
tw.callbackSignal_getout() => {
    console
.log('signal getout');
    
}
Info

JavaScript
copy!
tw.callbackSignal_cheater() => {
    console
.log('signal cheater');
    
}
Info

JavaScript
copy!
tw.callbackSignal_caution(count) => {
    console
.log('signal caution', count);
    
}
Info

JavaScript
copy!
tw.callbackSignal_webcam() => {
    console
.log('signal webcam reconnect');
    
}
Info

JavaScript
copy!
tw.callbackSignal_mobile() => {
    console
.log('signal mobile reconnect');
    
}
Info

JavaScript
copy!
tw.callbackSignal_screen() => {
    console
.log('signal screen reconnect');
    
}
Info

Error Code Message Desc
1001 TooManyRequests
1002 InvalidParams
1003 TestwithScriptRequired
1004 ParamsBindingError
1005 UserNumsNamesLengthDoNotMatch
1006 NoScreenStreaming
1007 CameraDisconnected
2001 TimestampExpired
2002 TestCenterNotFound
2003 TestCenterCreationFail
2004 TestCenterUpdateFail
2005 UserRegistrationFail
2006 UserNumTaken
2007 UserUpdateFail
2008 UserNotFound
3001 InvalidImageFormat
3002 FileUploadFail
3003 FileNotFound
3004 FaceDetection
3005 MultipleFaceDetection
3006 NoStoredPhoto
3007 NoFaceInStoredFile
3008 VerificationMismatch
3009 InvalidFileName
3010 TokenExpired
3011 InvalidToken
3012 Unauthorized
3013 ServiceIdNotFound
3014 InvalidTagName
3015 InvalidVideoRatio
3016 VideoElementNotFound

Important
HTML
copy!
<script src = "https://www.testwith.io/static/js/testwith_api.js"></script>
JavaScript
copy!
const serviceId = "YOUR_SERVICE_ID_HERE";
const tw = new Testwith(serviceId);
const token = 'YOUR_TOKEN_HERE';

async function registerAndVerifyFace() {
  try {
    await tw.loadTestwith();

    const testCenterResult = await tw.getTestCenterList({ "token": token });
    const testCenterList = testCenterResult.resultData;  

    if (testCenterList.length === 0) {
      console.log('testCenterList is empty');
      return;
    }

    const testId = testCenterList[0].testId;  

    const studentResult = await tw.getStudentList({ "token": token, "testId": testId });
    const studentList = studentResult.resultData;  

    if (studentList.length === 0) {
      console.log('studentList is empty');
      return;
    }

    const numberToFind = '';  
    const foundStudentData = studentList.find((data)=> data.userNum === numberToFind);

    if (foundStudentData) {
      const userId = foundStudentData.userId;

      
      tw.createRegister();

      
      const registerButton = document.createElement('button');
      registerButton.textContent = 'Register Face';
      document.body.appendChild(registerButton);
      registerButton.style = 'position: absolute; left: 50%; transform: translate(-50%, 0%);';

      
      registerButton.addEventListener('click', () => {
        tw.registFace({ "testId": testId, "userId": userId }).then((registerFaceResult) => {
          console.log(registerFaceResult);
          if (registerFaceResult.resultCode == '200') {
            registerButton.remove();

            
            const verifyButton = document.createElement('button');
            verifyButton.textContent = 'Verify Face';
            document.body.appendChild(verifyButton);
            verifyButton.style = 'position: absolute; left: 50%; transform: translate(-50%, 0%);';

            
            verifyButton.addEventListener('click', () => {
              tw.registFace({ "testId": testId, "userId": userId, "valid": true }).then((verifyFaceResult) => {
                console.log(verifyFaceResult);
              }).catch((error) => {
                console.error(error);
              });
            });
          }
        }).catch ((error) => {
          console.error(error);
        });
      });
    } else {
      console.log(`No student found with the examinee's number "${numberToFind}"`);
    }
  } catch (error) {
    console.error(error);
  }
}

registerAndVerifyFace();
Info

Important
JavaScript
copy!
const serviceId = "YOUR_SERVICE_ID_HERE";
const tw = new Testwith(serviceId);
const token = 'YOUR_TOKEN_HERE';

async function gazeOptimize() {
  try {
    await tw.loadTestwith();

    const testCenterResult = await tw.getTestCenterList({ "token": token });
    const testCenterList = testCenterResult.resultData;  

    if (testCenterList.length === 0) {
      console.log('testCenterList is empty');
      return;
    }

    const testId = testCenterList[0].testId;  

    const studentResult = await tw.getStudentList({ "token": token, "testId": testId });
    const studentList = studentResult.resultData;  

    if (studentList.length === 0) {
      console.log('studentList is empty');
      return;
    }

    const numberToFind = '';  
    const foundStudentData = studentList.find((data)=> data.userNum === numberToFind);

    if (foundStudentData) {
      const userId = foundStudentData.userId;

      try {
        
        await tw.createRegister();

        
        await tw.connectAI();

        
        tw.createGazeOptimize({ "testId": testId, "userId": userId });
      } catch (error) {
        console.error(error);
      }
    } else {
      console.log(`No student found with the examinee's number "${numberToFind}"`);
    }
  } catch (error) {
    console.error(error);
  }
}

gazeOptimize();
Info

JavaScript
copy!
const serviceId = "YOUR_SERVICE_ID_HERE";
const tw = new Testwith(serviceId);
const token = 'YOUR_TOKEN_HERE';

async function faceAI() {
  try {
    await tw.loadTestwith();

    const testCenterResult = await tw.getTestCenterList({ "token": token });
    const testCenterList = testCenterResult.resultData;  

    if (testCenterList.length === 0) {
      console.log('testCenterList is empty');
      return;
    }

    const testId = testCenterList[0].testId;  

    const studentResult = await tw.getStudentList({ "token": token, "testId": testId });
    const studentList = studentResult.resultData;  

    if (studentList.length === 0) {
      console.log('studentList is empty');
      return;
    }

    const numberToFind = '';  
    const foundStudentData = studentList.find((data)=> data.userNum === numberToFind);

    if (foundStudentData) {
      const userId = foundStudentData.userId;

      
      tw.onSuccessStream = () => {
        tw.setFaceAI({
          "testId": testId,
          "userId": userId,
          "detectOption": {
            "existFace": true,  
            "multiFace": true,  
            "validFace": true,  
            "gaze": true,       
          },
          "recordOption": true  
        });
      }
      
      tw.createWebcam({ "userId": userId });
    } else {
      console.log(`No student found with the examinee's number "${numberToFind}"`);
    }
  } catch (error) {
    console.error(error);
  }
}

faceAI();
Info

JavaScript
copy!
const serviceId = "YOUR_SERVICE_ID_HERE";
const tw = new Testwith(serviceId);
const token = 'YOUR_TOKEN_HERE';

async function screenAI() {
  try {
    await tw.loadTestwith();

    const testCenterResult = await tw.getTestCenterList({ "token": token });
    const testCenterList = testCenterResult.resultData;  

    if (testCenterList.length === 0) {
      console.log('testCenterList is empty');
      return;
    }

    const testId = testCenterList[0].testId;  

    const studentResult = await tw.getStudentList({ "token": token, "testId": testId });
    const studentList = studentResult.resultData;  

    if (studentList.length === 0) {
      console.log('studentList is empty');
      return;
    }

    const numberToFind = '';  
    const foundStudentData = studentList.find((data)=> data.userNum === numberToFind);

    if (foundStudentData) {
      const userId = foundStudentData.userId;

      
      tw.onSuccessScreen = () => {
        tw.setScreenAI({
          "testId": testId,
          "userId": userId,
          "detectOption": {
            "screenLeave": true, 
            "rightClick": true,  
            "specialKey": true,  
          },
          "recordOption": true   
        });
      }
      
      tw.createScreen({ "userId": userId });
    } else {
      console.log(`No student found with the examinee's number "${numberToFind}"`);
    }
  } catch (error) {
    console.error(error);
  }
}

screenAI();
Info

JavaScript
copy!
const serviceId = "YOUR_SERVICE_ID_HERE";
const tw = new Testwith(serviceId);
const token = 'YOUR_TOKEN_HERE';

async function createQR() {
  try {
    await tw.loadTestwith();

    const testCenterResult = await tw.getTestCenterList({ "token": token });
    const testCenterList = testCenterResult.resultData;  

    if (testCenterList.length === 0) {
      console.log('testCenterList is empty');
      return;
    }

    const testId = testCenterList[0].testId;  

    const studentResult = await tw.getStudentList({ "token": token, "testId": testId });
    const studentList = studentResult.resultData;  

    if (studentList.length === 0) {
      console.log('studentList is empty');
      return;
    }

    const numberToFind = '';  
    const foundStudentData = studentList.find((data)=> data.userNum === numberToFind);

    if (foundStudentData) {
      const userId = foundStudentData.userId;

      
      tw.createQR_code({ "userId" : userId });

    } else {
      console.log(`No student found with the examinee's number "${numberToFind}"`);
    }
  } catch (error) {
    console.error(error);
  }
}

createQR();
Info

×